fix empty models

This commit is contained in:
Sakurasan
2025-04-22 02:52:56 +08:00
parent 8d34f8d6fe
commit 9c604460b1
5 changed files with 7 additions and 6 deletions

View File

@@ -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: [],
}
}

View File

@@ -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"})

View File

@@ -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())

View File

@@ -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
}

View File

@@ -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
}