From 9c604460b19326dd0fc4f51af64b4a8e9d3bbabc Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Tue, 22 Apr 2025 02:52:56 +0800 Subject: [PATCH] fix empty models --- frontend/src/views/dashboard/KeyNew.vue | 4 ++-- internal/controller/proxy/proxy.go | 1 - internal/controller/user.go | 3 +-- internal/dao/apikey.go | 4 ++++ llm/openai_compatible/chat.go | 1 - 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/frontend/src/views/dashboard/KeyNew.vue b/frontend/src/views/dashboard/KeyNew.vue index 62ef014..9ad291c 100644 --- a/frontend/src/views/dashboard/KeyNew.vue +++ b/frontend/src/views/dashboard/KeyNew.vue @@ -207,7 +207,7 @@ const newApiKey = ref({ model_prefix: '', model_alias: '', parameters: '{}', - support_models: '', + support_models: '[]', support_models_array: [], }) @@ -224,7 +224,7 @@ const resetNewApiKey = () => { model_prefix: '', model_alias: '', parameters: '{}', - support_models: '', + support_models: '[]', support_models_array: [], } } diff --git a/internal/controller/proxy/proxy.go b/internal/controller/proxy/proxy.go index d44ab59..c9f602a 100644 --- a/internal/controller/proxy/proxy.go +++ b/internal/controller/proxy/proxy.go @@ -234,7 +234,6 @@ func (p *Proxy) Do(llmusage *llm.TokenUsage) error { func (p *Proxy) SelectApiKey(model string) error { akpikeys, err := p.apiKeyDao.FindApiKeysBySupportModel(p.db, model) - fmt.Println(len(akpikeys), err) if err != nil || len(akpikeys) == 0 { if strings.HasPrefix(model, "gpt") || strings.HasPrefix(model, "o1") || strings.HasPrefix(model, "o3") || strings.HasPrefix(model, "o4") { keys, err := p.apiKeyDao.FindKeys(map[string]any{"active = ?": true, "apitype = ?": "openai"}) diff --git a/internal/controller/user.go b/internal/controller/user.go index 85e9814..03fac2a 100644 --- a/internal/controller/user.go +++ b/internal/controller/user.go @@ -1,7 +1,6 @@ package controller import ( - "fmt" "net/http" "opencatd-open/internal/dto" "opencatd-open/internal/model" @@ -142,7 +141,7 @@ func (a Api) CreateUser(c *gin.Context) { dto.Fail(c, 400, err.Error()) return } - fmt.Printf("user:%+v\n", user) + err = a.userService.Create(c, &user) if err != nil { dto.Fail(c, http.StatusInternalServerError, err.Error()) diff --git a/internal/dao/apikey.go b/internal/dao/apikey.go index 7bb3108..187dd2b 100644 --- a/internal/dao/apikey.go +++ b/internal/dao/apikey.go @@ -3,6 +3,7 @@ package dao import ( "errors" "opencatd-open/internal/model" + "opencatd-open/internal/utils" "opencatd-open/pkg/config" "gorm.io/gorm" @@ -38,6 +39,9 @@ func (dao *ApiKeyDAO) Create(apiKey *model.ApiKey) error { if apiKey == nil { return errors.New("apiKey is nil") } + if len(*apiKey.SupportModels) < 2 { + apiKey.SupportModels = utils.ToPtr("[]") + } return dao.db.Create(apiKey).Error } diff --git a/llm/openai_compatible/chat.go b/llm/openai_compatible/chat.go index 8ccea63..901393c 100644 --- a/llm/openai_compatible/chat.go +++ b/llm/openai_compatible/chat.go @@ -222,7 +222,6 @@ func (o *OpenAICompatible) StreamChat(ctx context.Context, chatReq llm.ChatReque // case output <- &streamResp: // } } - fmt.Println("llm usage:", o.tokenUsage.Model, o.tokenUsage.PromptTokens, o.tokenUsage.CompletionTokens, o.tokenUsage.TotalTokens) }() return output, nil }