refactor(files): 优化文件处理和任务服务逻辑

This commit is contained in:
2026-06-18 13:39:41 +08:00
parent dd79643170
commit 7fa7a2e8ea
4 changed files with 149 additions and 97 deletions

View File

@@ -20,7 +20,7 @@ func buildPromptTypeRequest(ctx context.Context, req *dto.ComposeMessagesReq, ai
//1) 构建系统提示词
systemPrompt := promptBuildWithRounds(ctx, chatModel, aiModel)
ir.AddSystem(systemPrompt)
userPrompt := buildUserPrompt(ctx, req, util.GetModelPrompt(ctx, aiModel.ModelType))
userPrompt := buildUserPrompt(ctx, req)
ir.AddUser(userPrompt)
//2) 检查整体内容是否超出窗口
if !checkOverallContent(ir, aiModel) {
@@ -40,7 +40,7 @@ func buildNodeTypeRequest(ctx context.Context, req *dto.ComposeMessagesReq, chat
func buildStructTypeRequest(ctx context.Context, req *dto.ComposeMessagesReq, chatModel *gateway.AsynchModel, ir *IR) (map[string]any, error) {
customPrompt := gjson.New(req.UserForm).Get("0.prompt").String()
ir.AddSystem(customPrompt)
ir.AddUser(buildUserPrompt(ctx, req, ""))
ir.AddUser(buildUserPrompt(ctx, req))
return compileToProviderRequest(ctx, ir, chatModel, req, customPrompt)
}
@@ -81,9 +81,14 @@ func promptBuildWithRounds(ctx context.Context, chatModel *gateway.AsynchModel,
if err != nil || providerProtocol == nil {
return ""
}
outputJSON := gjson.New(util.ReverseMap(aiModel.RequestMapping, map[string]any{})).MustToJsonString()
return fmt.Sprintf(providerProtocol.SystemPromptTemplate, outputJSON)
outputJSON := gjson.New(util.ReverseMap(aiModel.RequestMapping, map[string]any{
"model": aiModel.ModelName,
})).MustToJsonString()
return fmt.Sprintf(providerProtocol.SystemPromptTemplate,
outputJSON, //%s【输出结构】
)
}
// checkOverallContent 检查整体内容是否超出窗口
@@ -93,15 +98,8 @@ func checkOverallContent(ir *IR, model *gateway.AsynchModel) bool {
}
// buildUserPrompt 构建用户提示词
func buildUserPrompt(ctx context.Context, req *dto.ComposeMessagesReq, prompt string) string {
func buildUserPrompt(ctx context.Context, req *dto.ComposeMessagesReq) string {
var b strings.Builder
b.WriteString(fmt.Sprintf("目标模型:%s\n", req.ModelName))
if prompt != "" {
b.WriteString(fmt.Sprintf("系统提示词:%s\n", prompt))
}
if skills := SkillMdContent(ctx, req.SkillName); skills != "" {
b.WriteString(fmt.Sprintf("技能内容:\n%s\n", skills))
}
if formText := buildUserFormText(req.Form); formText != "" {
b.WriteString(fmt.Sprintf("系统参数:\n%s\n", formText))
}

View File

@@ -232,15 +232,19 @@ func handleCallbackSuccess(ctx context.Context, req *dto.CallbackReq, composeTas
})
}
}
// 4) 合并系统提示词
systemPrompt := util.GetModelPrompt(ctx, model.ModelType)
skillContent := SkillMdContent(ctx, composeTask.SkillName)
messages = util.MergeSystemPrompt(messages, systemPrompt, skillContent, model.RequestMapping)
// 4) 合并附加结构
// 5) 合并附加结构
messages = util.MergeConsult(composeTask.RequestPayload, messages, model.ExtendMapping)
// 5) 注入历史
// 6) 注入历史
if len(history) > 0 {
messages = InjectHistory(messages, history, protocol)
}
// 6) 更新数据库
// 7) 更新数据库
_, err = dao.ComposeTask.Update(ctx, &entity.ComposeTask{
TaskId: req.TaskId,
Status: public.ComposeStatusSuccess,