Skip to content

Commit b304522

Browse files
author
qingjing.cai
committed
fix: add provider checker
1 parent 88ecd0e commit b304522

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

backend/internal/model/repo/model.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/chaitin/MonkeyCode/backend/ent/types"
1919
"github.com/chaitin/MonkeyCode/backend/pkg/cvt"
2020
"github.com/chaitin/MonkeyCode/backend/pkg/entx"
21+
"github.com/chaitin/MonkeyCode/backend/pkg/tools"
2122
)
2223

2324
type ModelRepo struct {
@@ -69,6 +70,9 @@ func (r *ModelRepo) Create(ctx context.Context, m *domain.CreateModelReq) (*db.M
6970
status = consts.ModelStatusDefault
7071
}
7172

73+
// 尝试修正用户不清楚 provider 时的情况
74+
m.Provider = tools.CheckProvider(ctx, m.Provider, m.ModelName)
75+
7276
r.cache.Delete(string(m.ModelType))
7377
create := r.db.Model.Create().
7478
SetUserID(m.AdminID).
@@ -184,7 +188,6 @@ func (r *ModelRepo) GetTokenUsage(ctx context.Context, modelType consts.ModelTyp
184188
OrderBy("date")
185189
}).
186190
Scan(ctx, &dailyUsages)
187-
188191
if err != nil {
189192
return nil, err
190193
}

backend/internal/proxy/proxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/chaitin/MonkeyCode/backend/internal/middleware"
2020
"github.com/chaitin/MonkeyCode/backend/pkg/logger"
2121
"github.com/chaitin/MonkeyCode/backend/pkg/tee"
22+
"github.com/chaitin/MonkeyCode/backend/pkg/tools"
2223
)
2324

2425
type CtxKey struct{}
@@ -114,7 +115,7 @@ func (l *LLMProxy) rewrite(r *httputil.ProxyRequest) {
114115
}
115116

116117
metadata := make(map[string]string)
117-
if m.Provider == consts.ModelProviderZhiPu {
118+
if tools.CheckProvider(r.In.Context(), m.Provider, m.ModelName) == consts.ModelProviderZhiPu {
118119
body, err := io.ReadAll(r.In.Body)
119120
if err != nil {
120121
l.logger.ErrorContext(r.In.Context(), "read request body failed", slog.String("path", r.In.URL.Path), slog.Any("err", err))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tools
2+
3+
import (
4+
"context"
5+
"strings"
6+
7+
"github.com/chaitin/MonkeyCode/backend/consts"
8+
)
9+
10+
// CheckProvider 根据 model 的前缀来判断 provider
11+
func CheckProvider(ctx context.Context, provider consts.ModelProvider, modelName string) consts.ModelProvider {
12+
if strings.HasPrefix(modelName, "glm") {
13+
provider = consts.ModelProviderZhiPu
14+
}
15+
return provider
16+
}

0 commit comments

Comments
 (0)