2026-04-29 15:54:14 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
|
|
"model-asynch/model/dto"
|
2026-05-12 13:45:08 +08:00
|
|
|
|
"model-asynch/model/entity"
|
2026-04-29 15:54:14 +08:00
|
|
|
|
"model-asynch/service"
|
|
|
|
|
|
|
|
|
|
|
|
"gitea.com/red-future/common/beans"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type model struct{}
|
|
|
|
|
|
|
|
|
|
|
|
// Model 模型配置控制器
|
|
|
|
|
|
var Model = new(model)
|
|
|
|
|
|
|
|
|
|
|
|
// CreateModel 添加配置
|
|
|
|
|
|
func (c *model) CreateModel(ctx context.Context, req *dto.CreateModelReq) (res *dto.CreateModelRes, err error) {
|
|
|
|
|
|
return service.Model.Create(ctx, req)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateModel 更改配置
|
|
|
|
|
|
func (c *model) UpdateModel(ctx context.Context, req *dto.UpdateModelReq) (res *beans.ResponseEmpty, err error) {
|
|
|
|
|
|
err = service.Model.Update(ctx, req)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DeleteModel 删除配置
|
|
|
|
|
|
func (c *model) DeleteModel(ctx context.Context, req *dto.DeleteModelReq) (res *beans.ResponseEmpty, err error) {
|
|
|
|
|
|
err = service.Model.Delete(ctx, req.ID)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetModel 获取配置详情(按 modelName)
|
|
|
|
|
|
func (c *model) GetModel(ctx context.Context, req *dto.GetModelReq) (res *dto.GetModelRes, err error) {
|
2026-05-12 13:45:08 +08:00
|
|
|
|
model, err := service.Model.Get(ctx, req.ID)
|
2026-04-29 15:54:14 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2026-05-12 13:45:08 +08:00
|
|
|
|
return &dto.GetModelRes{Model: model}, nil
|
2026-04-29 15:54:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ListModel 配置列表
|
|
|
|
|
|
func (c *model) ListModel(ctx context.Context, req *dto.ListModelReq) (res *dto.ListModelRes, err error) {
|
|
|
|
|
|
pageNum, pageSize := 1, 10 //默认分页参数
|
2026-05-12 13:45:08 +08:00
|
|
|
|
if req != nil {
|
|
|
|
|
|
if req.PageNum > 0 {
|
|
|
|
|
|
pageNum = req.PageNum
|
2026-04-29 15:54:14 +08:00
|
|
|
|
}
|
2026-05-12 13:45:08 +08:00
|
|
|
|
if req.PageSize > 0 {
|
|
|
|
|
|
pageSize = req.PageSize
|
2026-04-29 15:54:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-12 14:08:29 +08:00
|
|
|
|
list, total, err := service.Model.List(ctx, pageNum, pageSize, req)
|
2026-04-29 15:54:14 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return &dto.ListModelRes{
|
|
|
|
|
|
List: list,
|
|
|
|
|
|
Total: total,
|
|
|
|
|
|
}, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// AutoTune 动态调参(由上层定时任务每小时触发一次)
|
|
|
|
|
|
func (c *model) AutoTune(ctx context.Context, req *dto.AutoTuneReq) (res *dto.AutoTuneRes, err error) {
|
|
|
|
|
|
windowSeconds := 3600
|
|
|
|
|
|
if req != nil && req.WindowSeconds > 0 {
|
|
|
|
|
|
windowSeconds = req.WindowSeconds
|
|
|
|
|
|
}
|
|
|
|
|
|
list, err := service.AutoTune(ctx, windowSeconds)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return &dto.AutoTuneRes{List: list}, nil
|
|
|
|
|
|
}
|
2026-05-12 13:45:08 +08:00
|
|
|
|
|
|
|
|
|
|
func (c *model) ListType(ctx context.Context, req *dto.ListTypeReq) (res dto.TypeItem, err error) {
|
|
|
|
|
|
modelType := service.GetModelTypesFromConfig(ctx)
|
|
|
|
|
|
res.Type = modelType
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateChatModel 更新是否为聊天模型
|
|
|
|
|
|
func (c *model) UpdateChatModel(ctx context.Context, req *dto.UpdateChatModelReq) (res *beans.ResponseEmpty, err error) {
|
|
|
|
|
|
err = service.Model.UpdateChatModel(ctx, req)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetIsChatModel 获取是否为聊天模型
|
|
|
|
|
|
func (c *model) GetIsChatModel(ctx context.Context, req *dto.GetIsChatModelReq) (res *entity.AsynchModel, err error) {
|
|
|
|
|
|
return service.Model.GetIsChatModel(ctx)
|
|
|
|
|
|
}
|