- parseModelError 按模型配置的 ErrorMessageMapping(schema 树)解析错误响应 - 成功判定: code 提取为空 / code 节点配置 defaultValue 且提取值等于它 → 成功 - 未配置 mapping 不识别错误(纯配置驱动), 删硬编码 ModelErrorResp/ModelError1Resp - DTO 加 errorMessageMapping 字段, update.sql 建 error_message_mapping JSONB 列 - 单测: parse_error_test.go 覆盖扁平/嵌套/数组/纯字符串路径/未配置/坏 JSON
145 lines
6.9 KiB
Go
145 lines
6.9 KiB
Go
package dto
|
|
|
|
import (
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
// ModelCallReq 模型调用请求
|
|
type ModelCallReq struct {
|
|
g.Meta `path:"/modelCall" method:"post" tags:"模型管理" summary:"模型调用" dc:"模型调用"`
|
|
ModelId int64 `json:"modelId" v:"required#modelId不能为空" dc:"模型ID"`
|
|
BizName string `json:"bizName" dc:"业务名称(调用方模块/系统,用于统计)"`
|
|
SessionId string `json:"sessionId" v:"required#sessionId不能为空" dc:"会话ID"`
|
|
RequestParams map[string]any `json:"requestParams" dc:"请求参数(模板字段)"`
|
|
BusinessParams map[string]any `json:"businessParams" dc:"业务参数(按业务字段名传,按 RequestBusinessFieldMapping 写入请求体)"`
|
|
MsgTopic string `json:"msgTopic" dc:"消息主题(异步必要参数)"`
|
|
}
|
|
|
|
type ModelCallRes struct {
|
|
TaskId int64 `json:"id" dc:"任务ID"`
|
|
TotalTokens int64 `json:"totalTokens" dc:"总token"`
|
|
PromptTokens int64 `json:"promptTokens" dc:"输入token"`
|
|
CompletionTokens int64 `json:"completionTokens" dc:"输出token"`
|
|
Tools []ModelTool `json:"tools" dc:"工具"`
|
|
ReasoningContent string `json:"reasoningContent" dc:"思考内容"`
|
|
Content map[string]any `json:"content" dc:"内容"`
|
|
Cost float64 `json:"cost" dc:"费用(元)"`
|
|
ErrorMsg string `json:"errorMsg" dc:"错误消息"`
|
|
}
|
|
|
|
type ModelTool struct {
|
|
Id string `json:"id" dc:"工具ID"`
|
|
Type string `json:"type" dc:"工具类型"`
|
|
Function struct {
|
|
Name string `json:"name"`
|
|
Arguments string `json:"arguments"`
|
|
} `json:"function"`
|
|
}
|
|
|
|
// ModelCallStreamEvent 流式增量事件(SSE data 行)。文本增量事件省略 Type,
|
|
// 流末 done 事件带 Type="done" 与 Tools。字段名由本结构体 json tag 统一管理。
|
|
type ModelCallStreamEvent struct {
|
|
Type string `json:"type,omitempty"`
|
|
Content map[string]any `json:"content,omitempty"`
|
|
ReasoningContent string `json:"reasoningContent,omitempty"`
|
|
TotalTokens int64 `json:"totalTokens,omitempty"`
|
|
PromptTokens int64 `json:"promptTokens,omitempty"`
|
|
CompletionTokens int64 `json:"completionTokens,omitempty"`
|
|
Tools []ModelTool `json:"tools,omitempty"`
|
|
Cost float64 `json:"cost,omitempty" dc:"费用(元),done事件携带最终费用,增量事件不带"`
|
|
}
|
|
|
|
// ModelCallStreamReq 模型调用流式请求
|
|
type ModelCallStreamReq struct {
|
|
g.Meta `path:"/modelCallStream" method:"post" tags:"模型管理" summary:"模型调用流式" dc:"模型调用流式"`
|
|
ModelId int64 `json:"modelId" v:"required#modelId不能为空" dc:"模型ID"`
|
|
BizName string `json:"bizName" dc:"业务名称(调用方模块/系统,用于统计)"`
|
|
SessionId string `json:"sessionId" v:"required#sessionId不能为空" dc:"会话ID"`
|
|
RequestParams map[string]any `json:"requestParams" dc:"请求参数(模板字段)"`
|
|
BusinessParams map[string]any `json:"businessParams" dc:"业务参数(按业务字段名传,按 RequestBusinessFieldMapping 写入请求体)"`
|
|
}
|
|
|
|
type ModelMsg struct {
|
|
TaskID int64 `json:"id" dc:"任务ID"`
|
|
TotalTokens int64 `json:"totalTokens" dc:"总token"`
|
|
PromptTokens int64 `json:"promptTokens" dc:"输入token"`
|
|
CompletionTokens int64 `json:"completionTokens" dc:"输出token"`
|
|
Content map[string]any `json:"content" dc:"内容"`
|
|
Cost float64 `json:"cost" dc:"费用(元)"`
|
|
ErrorMsg string `json:"errorMsg" dc:"错误消息"`
|
|
}
|
|
|
|
//========================
|
|
// Upload 文件上传定义
|
|
//========================
|
|
|
|
// UploadFileBytesReq 上传文件请求(字节流)
|
|
type UploadFileBytesReq struct {
|
|
FileName string `json:"fileName" dc:"文件名"`
|
|
FileBytes []byte `json:"fileBytes" dc:"文件字节流"`
|
|
FileStoreURL string `json:"fileStoreURL" dc:"文件存储URL"`
|
|
}
|
|
|
|
type UploadFileBytesRes struct {
|
|
FileURL string `json:"fileURL" dc:"上传地址"`
|
|
FileSize int `json:"fileSize" dc:"文件大小"`
|
|
FileName string `json:"fileName" dc:"文件名称"`
|
|
FileFormat string `json:"fileFormat" dc:"文件格式"`
|
|
FileAddressPrefix string `json:"fileAddressPrefix"`
|
|
}
|
|
|
|
// ===========================
|
|
// Template 元数据模板定义
|
|
// ===========================
|
|
|
|
// UploadRule 上传文件规则
|
|
type UploadRule struct {
|
|
Format string `json:"format" dc:"格式"`
|
|
MaxSize int `json:"maxSize" dc:"最大大小"`
|
|
MaxCount int `json:"maxCount" dc:"最大数量"`
|
|
}
|
|
|
|
// Constraint 字段约束
|
|
type Constraint struct {
|
|
// 数字类型:int、float、double
|
|
NumberType string `json:"numberType" dc:"数字类型"`
|
|
Min any `json:"min" dc:"最小值"`
|
|
Max any `json:"max" dc:"最大值"`
|
|
|
|
// 字符串类型:string、text
|
|
MinLength int `json:"minLength" dc:"最小长度"`
|
|
MaxLength int `json:"maxLength" dc:"最大长度"`
|
|
Pattern string `json:"pattern" dc:"正则"`
|
|
|
|
// 上传文件类型
|
|
UploadTotalMaxCount int `json:"uploadTotalMaxCount" dc:"上传文件最大数量"`
|
|
UploadTotalMaxSize int `json:"uploadTotalMaxSize" dc:"上传文件最大大小"`
|
|
UploadRules []UploadRule `json:"uploadRules" dc:"上传文件规则"`
|
|
}
|
|
|
|
// SelectOptionT 选择框选项
|
|
type SelectOptionT struct {
|
|
Label string `json:"label" dc:"展示标签"`
|
|
Value any `json:"value" dc:"选项值"`
|
|
}
|
|
|
|
// Template 元数据模板结构体
|
|
// 用于描述单个字段的元数据,包括类型、值、默认值、校验规则等
|
|
type Template struct {
|
|
Type string `json:"type" dc:"类型:string/boolean/number/object/array/null"`
|
|
Value any `json:"value" dc:"值"`
|
|
DefaultValue any `json:"defaultValue" dc:"默认值"`
|
|
Required bool `json:"required" dc:"是否必填"`
|
|
FieldType string `json:"fieldType" dc:"字段类型(输入框/选择框/多行文本/数字输入等)"`
|
|
Attrs any `json:"attrs" dc:"子字段(object/array时使用)"`
|
|
IsContainer bool `json:"isContainer" dc:"是否为容器"`
|
|
LinkRules []map[string]string `json:"linkRules" dc:"链接规则"`
|
|
Label string `json:"label" dc:"展示标签"`
|
|
Loop bool `json:"loop" dc:"是否为循环"`
|
|
IsForm bool `json:"isForm" dc:"是否为表单"`
|
|
Constraint Constraint `json:"constraint" dc:"字段约束"`
|
|
Options []SelectOptionT `json:"options" dc:"选项列表(字段类型为选择框时使用)"`
|
|
FieldConstraint string `json:"fieldConstraint" dc:"字段额外约束"`
|
|
EnumValues []any `json:"enumValues" dc:"枚举值列表"`
|
|
}
|