- parseModelError 按模型配置的 ErrorMessageMapping(schema 树)解析错误响应 - 成功判定: code 提取为空 / code 节点配置 defaultValue 且提取值等于它 → 成功 - 未配置 mapping 不识别错误(纯配置驱动), 删硬编码 ModelErrorResp/ModelError1Resp - DTO 加 errorMessageMapping 字段, update.sql 建 error_message_mapping JSONB 列 - 单测: parse_error_test.go 覆盖扁平/嵌套/数组/纯字符串路径/未配置/坏 JSON
160 lines
9.8 KiB
Go
160 lines
9.8 KiB
Go
package dto
|
||
|
||
import (
|
||
"model-gateway/consts/model"
|
||
"model-gateway/consts/public"
|
||
"model-gateway/model/entity"
|
||
|
||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
)
|
||
|
||
// CreateModelManageReq 添加模型配置
|
||
type CreateModelManageReq struct {
|
||
g.Meta `path:"/createModelManage" method:"post" tags:"模型管理" summary:"创建模型配置" dc:"添加新的模型配置"`
|
||
ModelSupplier model.SupplierType `json:"modelSupplier" v:"required#模型供应商不能为空" dc:"模型供应商"`
|
||
ModelName string `json:"modelName" v:"required#模型名称不能为空" dc:"模型名称"`
|
||
ModelType model.ModelType `json:"modelType" v:"required#模型类型不能为空" dc:"模型类型"`
|
||
BaseURL string `json:"baseUrl" v:"required#模型服务地址不能为空" dc:"模型服务地址"`
|
||
SystemModel *bool `json:"systemModel" dc:"系统模型"`
|
||
RefSystemModelId int64 `json:"refSystemModelId" dc:"引用的系统模型ID(引用创建时填,普通创建留空)"`
|
||
HttpMethod string `json:"httpMethod" dc:"请求方式:GET/POST" d:"POST"`
|
||
ChatModel *bool `json:"chatModel" dc:"对话模型"`
|
||
ResponseType model.ResponseType `json:"responseType" v:"required#调用模式不能为空" dc:"调用模式:0-同步 1-异步 2-流式"`
|
||
ApiKey string `json:"apiKey" dc:"调用凭证/密钥"`
|
||
Enabled *bool `json:"enabled" dc:"启用"`
|
||
RequestHeadMapping map[string]string `json:"requestHeadMapping" dc:"请求头映射"`
|
||
RequestBodyMapping map[string]any `json:"requestBodyMapping" dc:"请求体映射"`
|
||
RequestBusinessFieldMapping map[string]string `json:"requestBusinessFieldMapping" dc:"业务字段映射"`
|
||
ResponseMapping map[string]any `json:"responseMapping" dc:"返回映射"`
|
||
ResponseBodyMapping map[string]string `json:"responseBodyMapping" dc:"返回体映射"`
|
||
ResponseBusinessFieldMapping map[string]string `json:"responseBusinessFieldMapping" dc:"业务字段映射"`
|
||
MaxConcurrency int `json:"maxConcurrency" dc:"最大并发数(默认10)"`
|
||
TokenMapping *entity.TokenMapping `json:"tokenMapping" dc:"token映射"`
|
||
AsyncTaskMapping *entity.AsyncTaskMapping `json:"asyncTaskMapping" dc:"异步任务映射"`
|
||
TokenPredictPrice float64 `json:"tokenPredictPrice" dc:"模型Token预估价格"`
|
||
TokenPredictPriceUnit string `json:"tokenPredictPriceUnit" dc:"模型Token预估价格单位"`
|
||
MaxTokens int `json:"maxTokens" dc:"最大token数"`
|
||
MinDuration int `json:"minDuration" dc:"最小时长"`
|
||
MaxDuration int `json:"maxDuration" dc:"最大时长"`
|
||
LastFrame string `json:"lastFrame" dc:"视频的尾帧图像"`
|
||
ErrorMessageMapping map[string]any `json:"errorMessageMapping" dc:"错误消息映射(schema 树,解析模型错误用)"`
|
||
}
|
||
|
||
type CreateModelManageRes struct {
|
||
Id int64 `json:"id,string" dc:"配置ID"`
|
||
}
|
||
|
||
type UpdateModelManageReq struct {
|
||
g.Meta `path:"/updateModelManage" method:"put" tags:"模型管理" summary:"更新模型配置" dc:"更新指定ID的模型配置"`
|
||
Id int64 `json:"id" v:"required#id不能为空" dc:"配置ID"`
|
||
ModelSupplier model.SupplierType `json:"modelSupplier" dc:"模型供应商"`
|
||
ModelName string `json:"modelName" dc:"模型名称"`
|
||
ModelType model.ModelType `json:"modelType" dc:"模型类型"`
|
||
BaseURL string `json:"baseUrl" dc:"模型服务地址"`
|
||
SystemModel *bool `json:"systemModel" dc:"系统模型"`
|
||
RefSystemModelId int64 `json:"refSystemModelId" dc:"引用的系统模型ID(引用行只改个人字段,本字段无效)"`
|
||
HttpMethod string `json:"httpMethod" dc:"请求方式:GET/POST"`
|
||
ChatModel *bool `json:"chatModel" dc:"对话模型"`
|
||
ResponseType model.ResponseType `json:"responseType" dc:"调用模式:0-同步 1-异步 2-流式"`
|
||
ApiKey string `json:"apiKey" dc:"调用凭证/密钥"`
|
||
Enabled *bool `json:"enabled" dc:"启用"`
|
||
RequestHeadMapping map[string]string `json:"requestHeadMapping" dc:"请求头映射"`
|
||
RequestBodyMapping map[string]any `json:"requestBodyMapping" dc:"请求体映射"`
|
||
RequestBusinessFieldMapping map[string]string `json:"requestBusinessFieldMapping" dc:"业务字段映射"`
|
||
ResponseMapping map[string]any `json:"responseMapping" dc:"返回映射"`
|
||
ResponseBodyMapping map[string]string `json:"responseBodyMapping" dc:"返回主体映射"`
|
||
ResponseBusinessFieldMapping map[string]string `json:"responseBusinessFieldMapping" dc:"业务字段映射"`
|
||
MaxConcurrency int `json:"maxConcurrency" dc:"最大并发数(默认10)"`
|
||
TokenMapping *entity.TokenMapping `json:"tokenMapping" dc:"token映射"`
|
||
AsyncTaskMapping *entity.AsyncTaskMapping `json:"asyncTaskMapping" dc:"异步任务映射"`
|
||
TokenPredictPrice float64 `json:"tokenPredictPrice" dc:"模型Token预估价格"`
|
||
TokenPredictPriceUnit string `json:"tokenPredictPriceUnit" dc:"模型Token预估价格单位"`
|
||
MaxTokens int `json:"maxTokens" dc:"最大token数"`
|
||
MinDuration int `json:"minDuration" dc:"最小时长"`
|
||
MaxDuration int `json:"maxDuration" dc:"最大时长"`
|
||
LastFrame string `json:"lastFrame" dc:"视频的尾帧图像"`
|
||
ErrorMessageMapping map[string]any `json:"errorMessageMapping" dc:"错误消息映射(schema 树,解析模型错误用)"`
|
||
}
|
||
|
||
type DeleteModelManageReq struct {
|
||
g.Meta `path:"/deleteModelManage" method:"delete" tags:"模型管理" summary:"删除模型配置" dc:"删除指定ID的模型配置"`
|
||
Id int64 `p:"id" json:"id,string" v:"required#id不能为空" dc:"配置ID"`
|
||
}
|
||
|
||
type GetModelManage struct {
|
||
ChatModel *bool `json:"chatModel" dc:"对话模型"`
|
||
Creator string `json:"creator" dc:"创建人"`
|
||
ModelName string `json:"modelName" dc:"模型名称"`
|
||
}
|
||
|
||
type GetModelManageReq struct {
|
||
g.Meta `path:"/getModelManage" method:"get" tags:"模型管理" summary:"获取模型配置" dc:"获取指定ID的模型配置"`
|
||
Id int64 `p:"id" json:"id,string" v:"required#id不能为空" dc:"配置ID"`
|
||
}
|
||
|
||
type GetModelManageRes struct {
|
||
ModelManage *entity.ModelManage `json:"modelManage"`
|
||
}
|
||
|
||
type GetChatModelReq struct {
|
||
g.Meta `path:"/getChatModel" method:"get" tags:"模型管理" summary:"获取聊天模型" dc:"获取聊天模型"`
|
||
}
|
||
|
||
type GetChatModelRes struct {
|
||
ModelManage *entity.ModelManage `json:"modelManage"`
|
||
}
|
||
|
||
// ListModelManageReq 配置列表
|
||
type ListModelManageReq struct {
|
||
g.Meta `path:"/listModelManage" method:"get" tags:"模型管理" summary:"模型配置列表" dc:"分页获取模型配置列表"`
|
||
*beans.Page `json:"page"`
|
||
Id int64 `p:"id" json:"id,string" dc:"配置ID"`
|
||
ModelName string `p:"modelName" json:"modelName" dc:"模型名称(模糊查询,可选)"`
|
||
ModelType model.ModelType `p:"modelType" json:"modelType" dc:"模型类型"`
|
||
IsSameType bool `p:"isSameType" json:"isSameType" dc:"是否相同类型"`
|
||
Creator string `json:"creator" dc:"创建人"`
|
||
}
|
||
|
||
type ListModelManageRes struct {
|
||
List []*entity.ModelManage `json:"list" dc:"列表数据"`
|
||
Total int `json:"total" dc:"总数"`
|
||
}
|
||
|
||
type CheckChatModelReq struct {
|
||
g.Meta `path:"/checkChatModel" method:"get" tags:"模型管理" summary:"检查是否为聊天模型" dc:"检查是否为聊天模型"`
|
||
}
|
||
|
||
type CheckChatModelRes struct {
|
||
IsChatModel bool `json:"isChatModel" dc:"是否为聊天模型"`
|
||
}
|
||
|
||
// ModelTypeReq 模型类型列表(分页)
|
||
type ModelTypeReq struct {
|
||
g.Meta `path:"/modelType" method:"get" tags:"模型管理" summary:"模型类型列表" dc:"分页获取模型类型列表"`
|
||
}
|
||
|
||
type ModelTypeRes struct {
|
||
List []*model.TypeTree `json:"list" dc:"模型类型ID到名称的映射"`
|
||
}
|
||
|
||
type ModelSupplierReq struct {
|
||
g.Meta `path:"/modelSupplier" method:"get" tags:"模型管理" summary:"获取运营商列表" dc:"获取运营商列表"`
|
||
}
|
||
|
||
type ModelSupplierRes struct {
|
||
List []*public.Option `json:"list" dc:"运营商名称到ID的映射"`
|
||
}
|
||
|
||
// BuildSchemaMappingReq 构建 Schema 映射请求
|
||
type BuildSchemaMappingReq struct {
|
||
g.Meta `path:"/buildSchemaMapping" method:"post" tags:"模型管理" summary:"自动构建 Schema 映射" dc:"根据模型类型和 Schema JSON,自动生成业务字段映射"`
|
||
ModelType int `json:"modelType" v:"required#模型类型不能为空" dc:"模型类型编码"`
|
||
Schema map[string]any `json:"schema" v:"required#Schema不能为空" dc:"模型的完整 Schema JSON"`
|
||
}
|
||
|
||
type BuildSchemaMappingRes struct {
|
||
SchemaMapping map[string]any `json:"schemaMapping" dc:"生成的 Schema 映射 JSON"`
|
||
}
|
||
|