refactor(model): 优化模型网关的数据解析和任务处理逻辑

This commit is contained in:
2026-06-17 14:34:49 +08:00
parent 0d52b631b9
commit eb28c2d1e0
4 changed files with 58 additions and 24 deletions

View File

@@ -148,10 +148,11 @@ func GetSkillUser(ctx context.Context, name string) (*SkillUserVO, error) {
// SendCallbackReq 发送回调的请求体
type SendCallbackReq struct {
TaskId string `json:"taskId"`
Status string `json:"status"`
EpicycleId int64 `json:"epicycleId"`
ErrorMsg string `json:"errorMsg,omitempty"`
TaskId string `json:"taskId"`
Status string `json:"status"`
EpicycleId int64 `json:"epicycleId"`
Messages map[string]any `json:"messages,omitempty"`
ErrorMsg string `json:"errorMsg,omitempty"`
}
// SendCallback 向业务方发送回调
@@ -165,6 +166,7 @@ func SendCallback(ctx context.Context, composeTask *entity.ComposeTask, epicycle
TaskId: composeTask.TaskId,
Status: composeTask.Status,
ErrorMsg: composeTask.ErrorMessage,
Messages: composeTask.ResultJson,
EpicycleId: epicycleId,
}
// 3. 发送 POST 请求

View File

@@ -81,11 +81,9 @@ func promptBuildWithRounds(ctx context.Context, chatModel *gateway.AsynchModel,
if err != nil || providerProtocol == nil {
return ""
}
outputJSON := gjson.New(util.ReverseMap(aiModel.RequestMapping, map[string]any{})).MustToJsonIndentString()
outputJSON := gjson.New(util.ReverseMap(aiModel.RequestMapping, map[string]any{})).MustToJsonString()
return fmt.Sprintf(providerProtocol.SystemPromptTemplate,
outputJSON, //【输出结构】 %s
)
return fmt.Sprintf(providerProtocol.SystemPromptTemplate, outputJSON)
}
// checkOverallContent 检查整体内容是否超出窗口
@@ -110,9 +108,6 @@ func buildUserPrompt(ctx context.Context, req *dto.ComposeMessagesReq, prompt st
if userFormText := buildUserFormText(req.UserForm); userFormText != "" {
b.WriteString(fmt.Sprintf("用户需求:\n%s\n", userFormText))
}
if len(req.Consult) > 0 {
b.WriteString(fmt.Sprintf("参考附件:%s\n", gjson.New(req.Consult).String()))
}
if fileTexts := ExtractFileTexts(ctx, req.Consult); fileTexts != "" {
b.WriteString(fmt.Sprintf("附件内容:\n%s\n", fileTexts))
}

View File

@@ -41,7 +41,9 @@ func GetModelMessage(ctx context.Context, req *dto.ComposeMessagesReq) (*gateway
return nil, nil, fmt.Errorf("获取用户信息失败: %w", err)
}
chatModel, err := gateway.GetModelConfig(ctx, &gateway.AsynchModel{
SQLBaseDO: beans.SQLBaseDO{Creator: userInfo.UserName},
SQLBaseDO: beans.SQLBaseDO{
Creator: userInfo.UserName,
},
IsChatModel: 1,
})
if err != nil || chatModel == nil {
@@ -148,7 +150,7 @@ func Callback(ctx context.Context, req *dto.CallbackReq) error {
// 3) 解析 OSS 内容为消息
var messages map[string]any
if len(ossContent) > 0 {
messages, _ = gjson.New(ossContent).Map(), nil
messages = gjson.New(ossContent).Map()
}
// 4) 处理失败