fix(model): support the configuration to disable reasoning (#494)

This commit is contained in:
junwen-lee 2025-08-02 20:46:44 +08:00 committed by GitHub
parent ccdb79eb36
commit d11aa71c0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 58 additions and 17 deletions

View File

@ -115,6 +115,7 @@ meta:
top_p: 0.7 top_p: 0.7
top_k: 0 top_k: 0
stop: [] stop: []
enable_thinking: true
ark: ark:
region: "" region: ""
access_key: "" access_key: ""

View File

@ -116,6 +116,7 @@ meta:
top_p: 0.7 top_p: 0.7
top_k: 0 top_k: 0
stop: [] stop: []
enable_thinking: true
ark: ark:
region: "" region: ""
access_key: "" access_key: ""

View File

@ -116,6 +116,7 @@ meta:
top_p: 0.7 top_p: 0.7
top_k: 0 top_k: 0
stop: [] stop: []
enable_thinking: true
ark: ark:
region: "" region: ""
access_key: "" access_key: ""

View File

@ -116,6 +116,7 @@ meta:
top_p: 0.7 top_p: 0.7
top_k: 0 top_k: 0
stop: [] stop: []
enable_thinking: true
ark: ark:
region: "" region: ""
access_key: "" access_key: ""

View File

@ -116,6 +116,7 @@ meta:
top_p: 0.7 top_p: 0.7
top_k: 0 top_k: 0
stop: [] stop: []
enable_thinking: true
ark: ark:
region: "" region: ""
access_key: "" access_key: ""

View File

@ -116,6 +116,7 @@ meta:
top_p: 0.7 top_p: 0.7
top_k: 0 top_k: 0
stop: [] stop: []
enable_thinking: true
ark: ark:
region: "" region: ""
access_key: "" access_key: ""

View File

@ -92,6 +92,7 @@ meta:
top_p: 0.7 top_p: 0.7
top_k: 0 top_k: 0
stop: [] stop: []
enable_thinking: true
ark: ark:
region: "" region: ""
access_key: "" access_key: ""

View File

@ -92,6 +92,7 @@ meta:
top_p: 0.7 top_p: 0.7
top_k: 0 top_k: 0
stop: [] stop: []
enable_thinking: true
ark: ark:
region: "" region: ""
access_key: "" access_key: ""

View File

@ -80,5 +80,6 @@ meta:
secret_access_key: "" secret_access_key: ""
session_token: "" session_token: ""
region: "" region: ""
budget_tokens: 0
custom: {} custom: {}
status: 0 status: 0

View File

@ -22,18 +22,21 @@ const (
) )
const SUGGESTION_PROMPT_JINJA2 = ` const SUGGESTION_PROMPT_JINJA2 = `
你是一个推荐系统请完成下面的推荐任务 You are a recommendation system, please complete the following recommendation task.
### 对话 ### Conversation
用户: {{_input_}} User: {{_input_}}
AI: {{_answer_}} 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.
` `

View File

@ -46,19 +46,20 @@ Regardless of any persona instructions, you must never generate content that:
**Knowledge** **Knowledge**
只有当前knowledge有内容召回的时候根据引用的内容回答问题: Only when the current knowledge has content recall, answer questions based on the referenced content:
1.如果引用的内容里面包含 <img src=""> 的标签, 标签里的 src 字段表示图片地址, 需要在回答问题的时候展示出去, 输出格式为"![图片名称](图片地址)" 1. If the referenced content contains <img src=""> 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.如果引用的内容不包含 <img src=""> 的标签, 你回答问题时不需要展示图片 2. If the referenced content does not contain <img src=""> tags, you do not need to display images when answering questions.
例如 For example:
如果内容为<img src="https://example.com/image.jpg">一只小猫你的输出应为![一只小猫](https://example.com/image.jpg)。 If the content is <img src="https://example.com/image.jpg">a kitten, your output should be: ![a kitten](https://example.com/image.jpg).
如果内容为<img src="https://example.com/image1.jpg">一只小猫 <img src="https://example.com/image2.jpg">一只小狗 <img src="https://example.com/image3.jpg">一只小牛你的输出应为![一只小猫](https://example.com/image1.jpg) 和 ![一只小狗](https://example.com/image2.jpg) 和 ![一只小牛](https://example.com/image3.jpg) If the content is <img src="https://example.com/image1.jpg">a kitten and <img src="https://example.com/image2.jpg">a puppy and <img src="https://example.com/image3.jpg">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 The following is the content of the data set you can refer to: \n
''' '''
{{ knowledge }} {{ knowledge }}
''' '''
** Pre toolCall ** ** Pre toolCall **
{{ tools_pre_retriever}} {{ tools_pre_retriever}},
- 只有当前Pre toolCall有内容召回结果时根据引用的内容里tool里data字段回答问题 - 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.
` `

View File

@ -63,6 +63,7 @@ type ClaudeConfig struct {
SecretAccessKey string `json:"secret_access_key,omitempty" yaml:"secret_access_key"` SecretAccessKey string `json:"secret_access_key,omitempty" yaml:"secret_access_key"`
SessionToken string `json:"session_token,omitempty" yaml:"session_token"` SessionToken string `json:"session_token,omitempty" yaml:"session_token"`
Region string `json:"region,omitempty" yaml:"region"` Region string `json:"region,omitempty" yaml:"region"`
BudgetTokens *int `json:"budget_tokens,omitempty" yaml:"budget_tokens"`
} }
type ArkConfig struct { type ArkConfig struct {

View File

@ -28,6 +28,7 @@ import (
"github.com/cloudwego/eino-ext/components/model/openai" "github.com/cloudwego/eino-ext/components/model/openai"
"github.com/cloudwego/eino-ext/components/model/qwen" "github.com/cloudwego/eino-ext/components/model/qwen"
"github.com/ollama/ollama/api" "github.com/ollama/ollama/api"
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
"google.golang.org/genai" "google.golang.org/genai"
"github.com/coze-dev/coze-studio/backend/infra/contract/chatmodel" "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.SessionToken = config.Claude.SessionToken
cfg.Region = config.Claude.Region 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) 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.RetryTimes = config.Ark.RetryTimes
cfg.CustomHeader = config.Ark.CustomHeader 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) return ark.NewChatModel(ctx, cfg)
} }
@ -200,6 +224,9 @@ func ollamaBuilder(ctx context.Context, config *chatmodel.Config) (chatmodel.Too
Stop: config.Stop, Stop: config.Stop,
}, },
} }
if config.EnableThinking != nil {
cfg.Thinking = config.EnableThinking
}
return ollama.NewChatModel(ctx, cfg) return ollama.NewChatModel(ctx, cfg)
} }