-
Notifications
You must be signed in to change notification settings - Fork 226
fix: add provider checker #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |||||
| "github.com/chaitin/MonkeyCode/backend/internal/middleware" | ||||||
| "github.com/chaitin/MonkeyCode/backend/pkg/logger" | ||||||
| "github.com/chaitin/MonkeyCode/backend/pkg/tee" | ||||||
| "github.com/chaitin/MonkeyCode/backend/pkg/tools" | ||||||
| ) | ||||||
|
|
||||||
| type CtxKey struct{} | ||||||
|
|
@@ -114,7 +115,7 @@ func (l *LLMProxy) rewrite(r *httputil.ProxyRequest) { | |||||
| } | ||||||
|
|
||||||
| metadata := make(map[string]string) | ||||||
| if m.Provider == consts.ModelProviderZhiPu { | ||||||
| if tools.CheckProvider(r.In.Context(), m.Provider, m.ModelName) == consts.ModelProviderZhiPu { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在代理转发逻辑中使用了新的CheckProvider函数,这是合理的。但需要注意的是,这里的实现可能会导致重复的上下文传递(ctx),因为tools.CheckProvider的第一个参数是ctx,但函数内部并未使用它。可以考虑简化函数签名。
Suggested change
|
||||||
| body, err := io.ReadAll(r.In.Body) | ||||||
| if err != nil { | ||||||
| l.logger.ErrorContext(r.In.Context(), "read request body failed", slog.String("path", r.In.URL.Path), slog.Any("err", err)) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||
| package tools | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "strings" | ||||||
|
|
||||||
| "github.com/chaitin/MonkeyCode/backend/consts" | ||||||
| ) | ||||||
|
|
||||||
| // CheckProvider 根据 model 的前缀来判断 provider | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 新增的CheckProvider函数实现了基本的提供商识别逻辑,但目前只支持根据"glm"前缀识别智谱提供商。考虑到系统的可扩展性,建议采用更灵活的配置方式,比如通过配置文件或数据库来管理模型名称与提供商的映射关系,而不是硬编码在函数中。
Suggested change
|
||||||
| func CheckProvider(ctx context.Context, provider consts.ModelProvider, modelName string) consts.ModelProvider { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CheckProvider函数的第一个参数ctx在当前实现中并未被使用,可以考虑移除以简化函数签名,除非未来有计划使用它。
Suggested change
|
||||||
| if strings.HasPrefix(modelName, "glm") { | ||||||
| provider = consts.ModelProviderZhiPu | ||||||
| } | ||||||
| return provider | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
backend/internal/proxy/proxy.go中同样使用了tools.CheckProvider函数,但该项目中未找到此函数的实现。这可能导致编译错误或运行时错误。