feat: 阿里云Qwen3深度思考开关

This commit is contained in:
chan 2025-07-03 11:29:12 +08:00
parent 04b132816c
commit e47a42a913
4 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,4 @@
-- OpenAI llm 配置增加 enable_thinking 开关
UPDATE `ai_model_provider` SET `fields` =
'[{\"key\": \"base_url\", \"type\": \"string\", \"label\": \"基础URL\", \"selected\": false}, {\"key\": \"model_name\", \"type\": \"string\", \"label\": \"模型名称\", \"selected\": false}, {\"key\": \"api_key\", \"type\": \"string\", \"label\": \"API密钥\", \"selected\": false}, {\"key\": \"temperature\", \"type\": \"number\", \"label\": \"温度\", \"selected\": false}, {\"key\": \"max_tokens\", \"type\": \"number\", \"label\": \"最大令牌数\", \"selected\": false}, {\"key\": \"top_p\", \"type\": \"number\", \"label\": \"top_p值\", \"selected\": false}, {\"key\": \"top_k\", \"type\": \"number\", \"label\": \"top_k值\", \"selected\": false}, {\"key\": \"frequency_penalty\", \"type\": \"number\", \"label\": \"频率惩罚\", \"selected\": false}, {\"key\": \"enable_thinking\", \"type\": \"boolean\", \"label\": \"阿里云Qwen3深度思考开关\", \"default\": \"false\", \"editing\": false, \"selected\": false}]'
WHERE `id` = 'SYSTEM_LLM_openai';

View file

@ -239,4 +239,11 @@ databaseChangeLog:
changes:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202506261637.sql
path: classpath:db/changelog/202506261637.sql
- changeSet:
id: 202507031111
author: chan
changes:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202507031111.sql

View file

@ -343,6 +343,7 @@ LLM:
top_p: 1
top_k: 50
frequency_penalty: 0 # 频率惩罚
enable_thinking: false # 阿里云Qwen3全系列支持思考模式和非思考模式切换 true/false
AliAppLLM:
# 定义LLM API类型
type: AliBL

View file

@ -26,6 +26,7 @@ class LLMProvider(LLMProviderBase):
"temperature": (0.7, lambda x: round(float(x), 1)),
"top_p": (1.0, lambda x: round(float(x), 1)),
"frequency_penalty": (0, lambda x: round(float(x), 1)),
"enable_thinking": (False, bool),
}
for param, (default, converter) in param_defaults.items():
@ -91,7 +92,10 @@ class LLMProvider(LLMProviderBase):
def response_with_functions(self, session_id, dialogue, functions=None):
try:
stream = self.client.chat.completions.create(
model=self.model_name, messages=dialogue, stream=True, tools=functions
model=self.model_name, messages=dialogue, stream=True, tools=functions,
extra_body={
"enable_thinking": self.enable_thinking
}
)
for chunk in stream: