From e47a42a91347cfe89e57f09d88fa4b38d33cc7a8 Mon Sep 17 00:00:00 2001 From: chan Date: Thu, 3 Jul 2025 11:29:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E9=98=BF=E9=87=8C=E4=BA=91Qwen3?= =?UTF-8?q?=E6=B7=B1=E5=BA=A6=E6=80=9D=E8=80=83=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/db/changelog/202507031111.sql | 4 ++++ .../main/resources/db/changelog/db.changelog-master.yaml | 9 ++++++++- main/xiaozhi-server/config.yaml | 1 + main/xiaozhi-server/core/providers/llm/openai/openai.py | 6 +++++- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 main/manager-api/src/main/resources/db/changelog/202507031111.sql diff --git a/main/manager-api/src/main/resources/db/changelog/202507031111.sql b/main/manager-api/src/main/resources/db/changelog/202507031111.sql new file mode 100644 index 000000000..28f31c26b --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202507031111.sql @@ -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'; diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index 32ba9f307..ef0d689e3 100755 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -239,4 +239,11 @@ databaseChangeLog: changes: - sqlFile: encoding: utf8 - path: classpath:db/changelog/202506261637.sql \ No newline at end of file + path: classpath:db/changelog/202506261637.sql + - changeSet: + id: 202507031111 + author: chan + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202507031111.sql \ No newline at end of file diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index 5a43c995b..3879f2dc3 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -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 diff --git a/main/xiaozhi-server/core/providers/llm/openai/openai.py b/main/xiaozhi-server/core/providers/llm/openai/openai.py index 5c85c6478..a980f02c3 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -26,6 +26,7 @@ def __init__(self, config): "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 @@ def response(self, session_id, dialogue, **kwargs): 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: From 21ca10cecbf4fc09446249187a69445cdee34246 Mon Sep 17 00:00:00 2001 From: Pursue Wind <40025981+pursue-wind@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:23:49 +0800 Subject: [PATCH 2/2] fix: converter err --- main/xiaozhi-server/core/providers/llm/openai/openai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/xiaozhi-server/core/providers/llm/openai/openai.py b/main/xiaozhi-server/core/providers/llm/openai/openai.py index a980f02c3..8ae8f84ee 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -26,7 +26,7 @@ def __init__(self, config): "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), + "enable_thinking": (False, lambda x: x.lower() == 'true'), } for param, (default, converter) in param_defaults.items():