diff --git a/frontend/src/utils/request.js b/frontend/src/utils/request.js index a2672fc..0539e00 100644 --- a/frontend/src/utils/request.js +++ b/frontend/src/utils/request.js @@ -11,7 +11,7 @@ if (import.meta.env.DEV) { // Vite 的方式判断开发环境 const service = axios.create({ baseURL: baseURL, - timeout: 5000, + timeout: 6000, headers: { 'Content-Type': 'application/json', }, diff --git a/frontend/src/views/dashboard/KeyNew.vue b/frontend/src/views/dashboard/KeyNew.vue index ec8fe0f..62ef014 100644 --- a/frontend/src/views/dashboard/KeyNew.vue +++ b/frontend/src/views/dashboard/KeyNew.vue @@ -12,17 +12,6 @@

- -
@@ -147,7 +136,7 @@ + placeholder="Please input" @change="onchange_supportmodel" />
@@ -165,10 +154,23 @@
+ +
-
@@ -249,7 +251,7 @@ const apiKeyImageMap = { 'gemini': '/assets/gemini.svg', 'azure': '/assets/azure.svg', 'github': '/assets/github.svg' - + }; const apiKeyImageUrl = (keytype) => { @@ -261,7 +263,7 @@ const createApiKey = async () => { setToast('Please fill in all required fields (Name, Type, API Key).', 'error') return } - + try { try { if (!Array.isArray(newApiKey.value.support_models_array)) { diff --git a/internal/controller/apikey.go b/internal/controller/apikey.go index af30019..54a4fac 100644 --- a/internal/controller/apikey.go +++ b/internal/controller/apikey.go @@ -28,7 +28,7 @@ func (a Api) CreateApiKey(c *gin.Context) { } if slice.Contain([]string{"openai", "azure", "claude"}, *newkey.ApiType) { sma, err := utils.FetchKeyModel(a.db, newkey) - if err == nil { + if err == nil && len(sma) > 0 { newkey.SupportModelsArray = sma var buf = new(bytes.Buffer) json.NewEncoder(buf).Encode(sma) //nolint:errcheck diff --git a/internal/dao/apikey.go b/internal/dao/apikey.go index 0173d0b..837dc76 100644 --- a/internal/dao/apikey.go +++ b/internal/dao/apikey.go @@ -91,11 +91,11 @@ func (dao *ApiKeyDAO) FindApiKeysBySupportModel(db *gorm.DB, modelName string) ( case "postgres": return nil, errors.New("not support") } - err := db.Model(&model.ApiKey{}). - Joins("CROSS JOIN JSON_EACH(apikeys.support_models)"). - Where("active = true"). - Where("value = ?", modelName). - Find(&apiKeys).Error + err := db.Raw(` + SELECT a.* + FROM apikeys a + JOIN json_each(a.support_models) AS je ON je.value = ? + WHERE a.active = true`, modelName).Scan(&apiKeys).Error return apiKeys, err } diff --git a/internal/utils/fetchKeyModel.go b/internal/utils/fetchKeyModel.go index f5b3afd..00018f1 100644 --- a/internal/utils/fetchKeyModel.go +++ b/internal/utils/fetchKeyModel.go @@ -8,12 +8,13 @@ import ( "opencatd-open/internal/model" "os" "strings" + "time" "github.com/tidwall/gjson" "gorm.io/gorm" ) -var client = &http.Client{} +var client = &http.Client{Timeout: 2 * time.Second} func init() { if os.Getenv("LOCAL_PROXY") != "" { @@ -29,13 +30,13 @@ func FetchKeyModel(db *gorm.DB, key *model.ApiKey) ([]string, error) { var err error if *key.ApiType == "openai" || *key.ApiType == "azure" { supportModels, err = FetchOpenAISupportModels(db, key) - if err != nil { - fmt.Println(err) - } } if *key.ApiType == "claude" { supportModels, err = FetchClaudeSupportModels(db, key) } + if err != nil { + fmt.Println(err) + } return supportModels, err }