From 1f0db7dc470462188ee6cdc1389fd97529d6cab6 Mon Sep 17 00:00:00 2001 From: FAN-yeB <1442100690@qq.com> Date: Mon, 20 Apr 2026 17:35:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E9=BB=98=E8=AE=A4=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=B9=B3=E5=8F=B0LLM=E6=80=9D=E8=80=83?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/providers/llm/openai/openai.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/main/xiaozhi-server/core/providers/llm/openai/openai.py b/main/xiaozhi-server/core/providers/llm/openai/openai.py index 3d9882f3..ba0498e5 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -4,10 +4,19 @@ from openai.types import CompletionUsage from config.logger import setup_logging from core.utils.util import check_model_key from core.providers.llm.base import LLMProviderBase +from urllib.parse import urlparse TAG = __name__ logger = setup_logging() +# 需要禁用思考模式的平台域名及其对应参数(默认关闭思考模式) +THINKING_DISABLED_DOMAINS = { + "aliyuncs.com": {"enable_thinking": False}, + "bigmodel.cn": {"thinking": {"type": "disabled"}}, + "moonshot.cn": {"thinking": {"type": "disabled"}}, + "volces.com": {"thinking": {"type": "disabled"}}, +} + class LLMProvider(LLMProviderBase): def __init__(self, config): @@ -69,6 +78,16 @@ class LLMProvider(LLMProviderBase): msg["content"] = "" return dialogue + def _apply_thinking_disabled(self, request_params: dict): + """根据域名自动禁用思考模式""" + parsed_url = urlparse(self.base_url) + domain = parsed_url.netloc + for disabled_domain, params in THINKING_DISABLED_DOMAINS.items(): + if disabled_domain in domain: + request_params.setdefault("extra_body", {}).update(params) + logger.bind(tag=TAG).info(f"为域名 {domain} 禁用思考模式,参数: {params}") + break + def response(self, session_id, dialogue, **kwargs): dialogue = self.normalize_dialogue(dialogue) @@ -90,6 +109,9 @@ class LLMProvider(LLMProviderBase): if value is not None: request_params[key] = value + # 禁用思考模式 + self._apply_thinking_disabled(request_params) + responses = self.client.chat.completions.create(**request_params) is_active = True @@ -130,6 +152,9 @@ class LLMProvider(LLMProviderBase): if value is not None: request_params[key] = value + # 禁用思考模式 + self._apply_thinking_disabled(request_params) + stream = self.client.chat.completions.create(**request_params) for chunk in stream: