-
Notifications
You must be signed in to change notification settings - Fork 210
feat: 支持供应商gpustack与xinference #353
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
base: main
Are you sure you want to change the base?
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,8 +14,9 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type ModelHandler struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usecase domain.ModelUsecase | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger *slog.Logger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usecase domain.ModelUsecase | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger *slog.Logger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modelkit *modelkit.ModelKit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func NewModelHandler( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -26,7 +27,8 @@ func NewModelHandler( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readonly *middleware.ReadOnlyMiddleware, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger *slog.Logger, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) *ModelHandler { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m := &ModelHandler{usecase: usecase, logger: logger.With("handler", "model")} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modelkit := modelkit.NewModelKit(logger) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. 在 NewModelHandler 函数中初始化 modelkit 实例时,建议考虑是否需要将其作为依赖注入的一部分,以提高组件的可测试性和灵活性。
Suggested change
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. 在初始化ModelKit实例时,应该添加错误处理逻辑以确保其正确初始化。
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m := &ModelHandler{usecase: usecase, logger: logger.With("handler", "model"), modelkit: modelkit} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| g := w.Group("/api/v1/model") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| g.Use(auth.Auth(), active.Active("admin"), readonly.Guard()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -55,7 +57,7 @@ func NewModelHandler( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // @Success 200 {object} web.Resp{data=domain.CheckModelResp} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // @Router /api/v1/model/check [post] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (h *ModelHandler) Check(c *web.Context, req domain.CheckModelReq) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modelkitRes, err := modelkit.CheckModel(c.Request().Context(), &modelkitDomain.CheckModelReq{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modelkitRes, err := h.modelkit.CheckModel(c.Request().Context(), &modelkitDomain.CheckModelReq{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. 应该检查modelkit.CheckModel方法返回的错误,并进行适当的处理。
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Provider: string(req.Provider), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Model: req.ModelName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BaseURL: req.APIBase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -199,7 +201,7 @@ func (h *ModelHandler) GetTokenUsage(c *web.Context, req domain.GetTokenUsageReq | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // @Success 200 {object} web.Resp{data=domain.GetProviderModelListResp} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // @Router /api/v1/model/provider/supported [get] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (h *ModelHandler) GetProviderModelList(c *web.Context, req domain.GetProviderModelListReq) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modelkitRes, err := modelkit.ModelList(c.Request().Context(), &modelkitDomain.ModelListReq{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modelkitRes, err := h.modelkit.ModelList(c.Request().Context(), &modelkitDomain.ModelListReq{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. 应该检查modelkit.ModelList方法返回的错误,并进行适当的处理。
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Provider: string(req.Provider), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Type: string(req.Type), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BaseURL: req.BaseURL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
在 ModelHandler 中添加 modelkit 字段后,建议添加相应的注释说明其用途和生命周期,以提高代码的可读性和可维护性。