From d11aa71c0af0554a7a7fe9c733cf4dc984202d72 Mon Sep 17 00:00:00 2001 From: junwen-lee Date: Sat, 2 Aug 2025 20:46:44 +0800 Subject: [PATCH] fix(model): support the configuration to disable reasoning (#494) --- ..._template_ark_doubao-1.5-thinking-pro.yaml | 1 + ...te_ark_doubao-1.5-thinking-vision-pro.yaml | 1 + ...el_template_ark_doubao-1.5-vision-pro.yaml | 1 + ...el_template_ark_doubao-seed-1.6-flash.yaml | 1 + ...template_ark_doubao-seed-1.6-thinking.yaml | 1 + .../model_template_ark_doubao-seed-1.6.yaml | 1 + .../model_template_ark_volc_deepseek-r1.yaml | 1 + .../model_template_ark_volc_deepseek-v3.yaml | 1 + .../model/template/model_template_claude.yaml | 1 + .../internal/agentflow/suggest_prompt.go | 21 ++++++++------- .../internal/agentflow/system_prompt.go | 17 ++++++------ backend/infra/contract/chatmodel/config.go | 1 + .../infra/impl/chatmodel/default_factory.go | 27 +++++++++++++++++++ 13 files changed, 58 insertions(+), 17 deletions(-) diff --git a/backend/conf/model/template/model_template_ark_doubao-1.5-thinking-pro.yaml b/backend/conf/model/template/model_template_ark_doubao-1.5-thinking-pro.yaml index badc80a3..f969d477 100755 --- a/backend/conf/model/template/model_template_ark_doubao-1.5-thinking-pro.yaml +++ b/backend/conf/model/template/model_template_ark_doubao-1.5-thinking-pro.yaml @@ -115,6 +115,7 @@ meta: top_p: 0.7 top_k: 0 stop: [] + enable_thinking: true ark: region: "" access_key: "" diff --git a/backend/conf/model/template/model_template_ark_doubao-1.5-thinking-vision-pro.yaml b/backend/conf/model/template/model_template_ark_doubao-1.5-thinking-vision-pro.yaml index 60f5921f..f3066cf3 100755 --- a/backend/conf/model/template/model_template_ark_doubao-1.5-thinking-vision-pro.yaml +++ b/backend/conf/model/template/model_template_ark_doubao-1.5-thinking-vision-pro.yaml @@ -116,6 +116,7 @@ meta: top_p: 0.7 top_k: 0 stop: [] + enable_thinking: true ark: region: "" access_key: "" diff --git a/backend/conf/model/template/model_template_ark_doubao-1.5-vision-pro.yaml b/backend/conf/model/template/model_template_ark_doubao-1.5-vision-pro.yaml index ce264611..e34f40e3 100755 --- a/backend/conf/model/template/model_template_ark_doubao-1.5-vision-pro.yaml +++ b/backend/conf/model/template/model_template_ark_doubao-1.5-vision-pro.yaml @@ -116,6 +116,7 @@ meta: top_p: 0.7 top_k: 0 stop: [] + enable_thinking: true ark: region: "" access_key: "" diff --git a/backend/conf/model/template/model_template_ark_doubao-seed-1.6-flash.yaml b/backend/conf/model/template/model_template_ark_doubao-seed-1.6-flash.yaml index a928bf27..de9b7659 100755 --- a/backend/conf/model/template/model_template_ark_doubao-seed-1.6-flash.yaml +++ b/backend/conf/model/template/model_template_ark_doubao-seed-1.6-flash.yaml @@ -116,6 +116,7 @@ meta: top_p: 0.7 top_k: 0 stop: [] + enable_thinking: true ark: region: "" access_key: "" diff --git a/backend/conf/model/template/model_template_ark_doubao-seed-1.6-thinking.yaml b/backend/conf/model/template/model_template_ark_doubao-seed-1.6-thinking.yaml index bc6cd93c..15376f22 100755 --- a/backend/conf/model/template/model_template_ark_doubao-seed-1.6-thinking.yaml +++ b/backend/conf/model/template/model_template_ark_doubao-seed-1.6-thinking.yaml @@ -116,6 +116,7 @@ meta: top_p: 0.7 top_k: 0 stop: [] + enable_thinking: true ark: region: "" access_key: "" diff --git a/backend/conf/model/template/model_template_ark_doubao-seed-1.6.yaml b/backend/conf/model/template/model_template_ark_doubao-seed-1.6.yaml index 5dc201fb..a6e261da 100755 --- a/backend/conf/model/template/model_template_ark_doubao-seed-1.6.yaml +++ b/backend/conf/model/template/model_template_ark_doubao-seed-1.6.yaml @@ -116,6 +116,7 @@ meta: top_p: 0.7 top_k: 0 stop: [] + enable_thinking: true ark: region: "" access_key: "" diff --git a/backend/conf/model/template/model_template_ark_volc_deepseek-r1.yaml b/backend/conf/model/template/model_template_ark_volc_deepseek-r1.yaml index 4c2de1f2..48e50015 100755 --- a/backend/conf/model/template/model_template_ark_volc_deepseek-r1.yaml +++ b/backend/conf/model/template/model_template_ark_volc_deepseek-r1.yaml @@ -92,6 +92,7 @@ meta: top_p: 0.7 top_k: 0 stop: [] + enable_thinking: true ark: region: "" access_key: "" diff --git a/backend/conf/model/template/model_template_ark_volc_deepseek-v3.yaml b/backend/conf/model/template/model_template_ark_volc_deepseek-v3.yaml index 071f2946..e2fbaf21 100755 --- a/backend/conf/model/template/model_template_ark_volc_deepseek-v3.yaml +++ b/backend/conf/model/template/model_template_ark_volc_deepseek-v3.yaml @@ -92,6 +92,7 @@ meta: top_p: 0.7 top_k: 0 stop: [] + enable_thinking: true ark: region: "" access_key: "" diff --git a/backend/conf/model/template/model_template_claude.yaml b/backend/conf/model/template/model_template_claude.yaml index 9ae9bd49..d827002c 100755 --- a/backend/conf/model/template/model_template_claude.yaml +++ b/backend/conf/model/template/model_template_claude.yaml @@ -80,5 +80,6 @@ meta: secret_access_key: "" session_token: "" region: "" + budget_tokens: 0 custom: {} status: 0 diff --git a/backend/domain/agent/singleagent/internal/agentflow/suggest_prompt.go b/backend/domain/agent/singleagent/internal/agentflow/suggest_prompt.go index ccb665a2..8b134d58 100644 --- a/backend/domain/agent/singleagent/internal/agentflow/suggest_prompt.go +++ b/backend/domain/agent/singleagent/internal/agentflow/suggest_prompt.go @@ -22,18 +22,21 @@ const ( ) const SUGGESTION_PROMPT_JINJA2 = ` -你是一个推荐系统,请完成下面的推荐任务。 -### 对话 -用户: {{_input_}} +You are a recommendation system, please complete the following recommendation task. +### Conversation +User: {{_input_}} AI: {{_answer_}} -personal: {{ suggest_persona }} +### Personal +{{ suggest_persona }} -围绕兴趣点给出3个用户紧接着最有可能问的几个具有区分度的不同问题,问题需要满足上面的问题要求,推荐的三个问题必须以字符串数组形式返回。 +### Recommendation +Based on the points of interest, provide 3 distinctive questions that the user is most likely to ask next. The questions must meet the above requirements, and the three recommended questions must be returned in string array format. -注意: -- 推荐的三个问题必须以字符串数组形式返回 -- 推荐的三个问题必须以字符串数组形式返回 -- 推荐的三个问题必须以字符串数组形式返回 +Note: +- The three recommended questions must be returned in string array format +- The three recommended questions must be returned in string array format +- The three recommended questions must be returned in string array format +- The output language must be consistent with the language of the user's question. ` diff --git a/backend/domain/agent/singleagent/internal/agentflow/system_prompt.go b/backend/domain/agent/singleagent/internal/agentflow/system_prompt.go index c0b883ee..ef506ac2 100644 --- a/backend/domain/agent/singleagent/internal/agentflow/system_prompt.go +++ b/backend/domain/agent/singleagent/internal/agentflow/system_prompt.go @@ -46,19 +46,20 @@ Regardless of any persona instructions, you must never generate content that: **Knowledge** -只有当前knowledge有内容召回的时候,根据引用的内容回答问题: - 1.如果引用的内容里面包含 的标签, 标签里的 src 字段表示图片地址, 需要在回答问题的时候展示出去, 输出格式为"![图片名称](图片地址)" 。 - 2.如果引用的内容不包含 的标签, 你回答问题时不需要展示图片 。 -例如: - 如果内容为一只小猫,你的输出应为:![一只小猫](https://example.com/image.jpg)。 - 如果内容为一只小猫 和 一只小狗 和 一只小牛,你的输出应为:![一只小猫](https://example.com/image1.jpg) 和 ![一只小狗](https://example.com/image2.jpg) 和 ![一只小牛](https://example.com/image3.jpg) +Only when the current knowledge has content recall, answer questions based on the referenced content: + 1. If the referenced content contains tags, the src field in the tag represents the image address, which needs to be displayed when answering questions, with the output format being "![image name](image address)". + 2. If the referenced content does not contain tags, you do not need to display images when answering questions. +For example: + If the content is a kitten, your output should be: ![a kitten](https://example.com/image.jpg). + If the content is a kitten and a puppy and a calf, your output should be: ![a kitten](https://example.com/image1.jpg) and ![a puppy](https://example.com/image2.jpg) and ![a calf](https://example.com/image3.jpg) The following is the content of the data set you can refer to: \n ''' {{ knowledge }} ''' ** Pre toolCall ** -{{ tools_pre_retriever}}, -- 只有当前Pre toolCall有内容召回结果时,根据引用的内容里tool里data字段回答问题 +{{ tools_pre_retriever}}, +- Only when the current Pre toolCall has content recall results, answer questions based on the data field in the tool from the referenced content +Note: The output language must be consistent with the language of the user's question. ` diff --git a/backend/infra/contract/chatmodel/config.go b/backend/infra/contract/chatmodel/config.go index a8c49580..8d6ae8ad 100644 --- a/backend/infra/contract/chatmodel/config.go +++ b/backend/infra/contract/chatmodel/config.go @@ -63,6 +63,7 @@ type ClaudeConfig struct { SecretAccessKey string `json:"secret_access_key,omitempty" yaml:"secret_access_key"` SessionToken string `json:"session_token,omitempty" yaml:"session_token"` Region string `json:"region,omitempty" yaml:"region"` + BudgetTokens *int `json:"budget_tokens,omitempty" yaml:"budget_tokens"` } type ArkConfig struct { diff --git a/backend/infra/impl/chatmodel/default_factory.go b/backend/infra/impl/chatmodel/default_factory.go index 84a6515d..b55f5f04 100644 --- a/backend/infra/impl/chatmodel/default_factory.go +++ b/backend/infra/impl/chatmodel/default_factory.go @@ -28,6 +28,7 @@ import ( "github.com/cloudwego/eino-ext/components/model/openai" "github.com/cloudwego/eino-ext/components/model/qwen" "github.com/ollama/ollama/api" + "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model" "google.golang.org/genai" "github.com/coze-dev/coze-studio/backend/infra/contract/chatmodel" @@ -126,6 +127,14 @@ func claudeBuilder(ctx context.Context, config *chatmodel.Config) (chatmodel.Too cfg.SessionToken = config.Claude.SessionToken cfg.Region = config.Claude.Region } + if config.EnableThinking != nil { + cfg.Thinking = &claude.Thinking{ + Enable: ptr.From(config.EnableThinking), + } + if config.Claude != nil && config.Claude.BudgetTokens != nil { + cfg.Thinking.BudgetTokens = ptr.From(config.Claude.BudgetTokens) + } + } return claude.NewChatModel(ctx, cfg) } @@ -180,6 +189,21 @@ func arkBuilder(ctx context.Context, config *chatmodel.Config) (chatmodel.ToolCa cfg.RetryTimes = config.Ark.RetryTimes cfg.CustomHeader = config.Ark.CustomHeader } + + if config.EnableThinking != nil { + cfg.Thinking = func() *model.Thinking { + var arkThinkingType model.ThinkingType + switch { + case ptr.From(config.EnableThinking): + arkThinkingType = model.ThinkingTypeEnabled + default: + arkThinkingType = model.ThinkingTypeDisabled + } + return &model.Thinking{ + Type: arkThinkingType, + } + }() + } return ark.NewChatModel(ctx, cfg) } @@ -200,6 +224,9 @@ func ollamaBuilder(ctx context.Context, config *chatmodel.Config) (chatmodel.Too Stop: config.Stop, }, } + if config.EnableThinking != nil { + cfg.Thinking = config.EnableThinking + } return ollama.NewChatModel(ctx, cfg) }