feat: support dall-e3 api mirrors, add name field for ApiKey

This commit is contained in:
RockYang
2024-01-04 16:29:57 +08:00
parent a06a81a415
commit bcc622a24d
13 changed files with 51 additions and 75 deletions

View File

@@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"github.com/imroc/req/v3"
"gorm.io/gorm"
"io"
"net/http"
"net/url"
@@ -86,7 +87,13 @@ type apiErrRes struct {
} `json:"error"`
}
func OpenAIRequest(prompt string, apiKey model.ApiKey, proxy string) (string, error) {
func OpenAIRequest(db *gorm.DB, prompt string, proxy string) (string, error) {
var apiKey model.ApiKey
res := db.Where("platform = ?", types.OpenAI).Where("type = ?", "chat").Where("enabled = ?", true).First(&apiKey)
if res.Error != nil {
return "", fmt.Errorf("error with fetch OpenAI API KEY%v", res.Error)
}
messages := make([]interface{}, 1)
messages[0] = types.Message{
Role: "user",