refactor(service): 重构服务代码结构并更新配置
This commit is contained in:
@@ -29,14 +29,14 @@ database:
|
|||||||
|
|
||||||
redis:
|
redis:
|
||||||
default:
|
default:
|
||||||
address: 116.204.74.41:6379
|
address: 192.168.3.30:6379
|
||||||
db: 0
|
db: 0
|
||||||
|
|
||||||
consul:
|
consul:
|
||||||
address: 116.204.74.41:8500
|
address: 192.168.3.30:8500
|
||||||
|
|
||||||
jaeger:
|
jaeger:
|
||||||
addr: 116.204.74.41:4318
|
addr: 192.168.3.30:4318
|
||||||
|
|
||||||
# 本地调试用:可选自动执行 worker/cleaner(默认关闭)
|
# 本地调试用:可选自动执行 worker/cleaner(默认关闭)
|
||||||
asynch:
|
asynch:
|
||||||
|
|||||||
@@ -114,6 +114,25 @@ func (d *modelDao) List(ctx context.Context, pageNum, pageSize int, modelNameLik
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *modelDao) GetByIsChatModel(ctx context.Context) (m *entity.AsynchModel, err error) {
|
||||||
|
userInfo, err := utils.GetUserInfo(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
||||||
|
Where(entity.AsynchModelCol.IsChatModel, 1).
|
||||||
|
Where(entity.AsynchModelCol.Creator, userInfo.UserName).
|
||||||
|
One()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if r.IsEmpty() {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
err = r.Struct(&m)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// ListByCreatorAndPlatform 普通用户:平台公共(tenant_id=0) + 自己创建的(creator=xxx)
|
// ListByCreatorAndPlatform 普通用户:平台公共(tenant_id=0) + 自己创建的(creator=xxx)
|
||||||
func (d *modelDao) ListByCreatorAndPlatform(ctx context.Context, creator string, pageNum, pageSize int, modelNameLike string) (list []*entity.AsynchModel, total int64, err error) {
|
func (d *modelDao) ListByCreatorAndPlatform(ctx context.Context, creator string, pageNum, pageSize int, modelNameLike string) (list []*entity.AsynchModel, total int64, err error) {
|
||||||
// 构建 Where 条件
|
// 构建 Where 条件
|
||||||
@@ -200,25 +219,6 @@ WHERE deleted_at IS NULL
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *modelDao) GetByIsChatModel(ctx context.Context) (m *entity.AsynchModel, err error) {
|
|
||||||
userInfo, err := utils.GetUserInfo(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
|
||||||
Where(entity.AsynchModelCol.IsChatModel, 1).
|
|
||||||
Where(entity.AsynchModelCol.Creator, userInfo.UserName).
|
|
||||||
One()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if r.IsEmpty() {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
err = r.Struct(&m)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListAll 用于分组展示:查询全部模型(不按类型过滤,类型拆分在 service 层处理)
|
// ListAll 用于分组展示:查询全部模型(不按类型过滤,类型拆分在 service 层处理)
|
||||||
func (d *modelDao) ListAll(ctx context.Context) (list []*entity.AsynchModel, err error) {
|
func (d *modelDao) ListAll(ctx context.Context) (list []*entity.AsynchModel, err error) {
|
||||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
||||||
|
|||||||
1
go.sum
1
go.sum
@@ -426,6 +426,7 @@ gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E
|
|||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||||
|
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -33,14 +33,14 @@ func main() {
|
|||||||
// 本地调试:可选自动触发 worker/cleaner(由配置文件控制)
|
// 本地调试:可选自动触发 worker/cleaner(由配置文件控制)
|
||||||
startAutoRunner(ctx)
|
startAutoRunner(ctx)
|
||||||
|
|
||||||
// 监听退出信号,确保 Ctrl+C 能完整退出(停止 worker/cleaner 并关闭 http server)
|
// 监听退出信号,确保 Ctrl+C 能完整退出(停止 worker/cleaner 并关闭 gateway server)
|
||||||
quit := make(chan os.Signal, 1)
|
quit := make(chan os.Signal, 1)
|
||||||
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
|
||||||
<-quit
|
<-quit
|
||||||
|
|
||||||
g.Log().Infof(ctx, "[main] 收到退出信号,开始优雅退出...")
|
g.Log().Infof(ctx, "[main] 收到退出信号,开始优雅退出...")
|
||||||
cancel()
|
cancel()
|
||||||
// 关闭 http server(RouteRegister 内部是 go Httpserver.Run() 启动的)
|
// 关闭 gateway server(RouteRegister 内部是 go Httpserver.Run() 启动的)
|
||||||
_ = http.Httpserver.Shutdown()
|
_ = http.Httpserver.Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type CreateModelReq struct {
|
|||||||
g.Meta `path:"/createModel" method:"post" tags:"模型管理" summary:"创建模型配置" dc:"添加新的模型配置"`
|
g.Meta `path:"/createModel" method:"post" tags:"模型管理" summary:"创建模型配置" dc:"添加新的模型配置"`
|
||||||
ModelName string `p:"modelName" json:"modelName" v:"required#modelName不能为空" dc:"模型名称(唯一标识)"`
|
ModelName string `p:"modelName" json:"modelName" v:"required#modelName不能为空" dc:"模型名称(唯一标识)"`
|
||||||
ModelType int `p:"modelType" json:"modelType" v:"required#modelType不能为空" dc:"模型类型:1-文本生成 2-图像生成 3-语音 4-视频 5-多模态"`
|
ModelType int `p:"modelType" json:"modelType" v:"required#modelType不能为空" dc:"模型类型:1-文本生成 2-图像生成 3-语音 4-视频 5-多模态"`
|
||||||
BaseURL string `p:"baseUrl" json:"baseUrl" v:"required#baseUrl不能为空" dc:"模型服务基础地址(如 http(s)://host:port)"`
|
BaseURL string `p:"baseUrl" json:"baseUrl" v:"required#baseUrl不能为空" dc:"模型服务基础地址(如 gateway(s)://host:port)"`
|
||||||
HttpMethod string `p:"httpMethod" json:"httpMethod" dc:"请求方式:GET/POST(默认POST)"`
|
HttpMethod string `p:"httpMethod" json:"httpMethod" dc:"请求方式:GET/POST(默认POST)"`
|
||||||
HeadMsg string `p:"headMsg" json:"headMsg" dc:"请求头绑定(支持多个,逗号分隔),示例:Authorization:Bearer xxx,Content-Type:application/json"`
|
HeadMsg string `p:"headMsg" json:"headMsg" dc:"请求头绑定(支持多个,逗号分隔),示例:Authorization:Bearer xxx,Content-Type:application/json"`
|
||||||
IsPrivate *int `p:"isPrivate" json:"isPrivate" v:"in:0,1#私有化参数只能为0或1" dc:"是否私有化:0-私有(默认) 1-公共"`
|
IsPrivate *int `p:"isPrivate" json:"isPrivate" v:"in:0,1#私有化参数只能为0或1" dc:"是否私有化:0-私有(默认) 1-公共"`
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ func DetectFileType(data []byte) (contentType string, ext string) {
|
|||||||
return "application/octet-stream", ""
|
return "application/octet-stream", ""
|
||||||
}
|
}
|
||||||
ct := http.DetectContentType(data)
|
ct := http.DetectContentType(data)
|
||||||
// http.DetectContentType 可能带 charset 等参数:text/plain; charset=utf-8
|
// gateway.DetectContentType 可能带 charset 等参数:text/plain; charset=utf-8
|
||||||
if idx := strings.Index(ct, ";"); idx > 0 {
|
if idx := strings.Index(ct, ";"); idx > 0 {
|
||||||
ct = strings.TrimSpace(ct[:idx])
|
ct = strings.TrimSpace(ct[:idx])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user