From 0f31bfc78f08d97d7690005d600053cd16e832b8 Mon Sep 17 00:00:00 2001 From: Liam Mazy Date: Wed, 11 Jun 2025 14:05:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0timeout=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=EF=BC=8C=E5=8D=95=E4=BD=8D=E4=B8=BA=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/providers/llm/openai/openai.py | 5 ++++- 1 file changed, 4 insertions(+), 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 bc0e7f211..5605c9729 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -1,3 +1,4 @@ +import httpx import openai from openai.types import CompletionUsage from config.logger import setup_logging @@ -16,6 +17,8 @@ def __init__(self, config): self.base_url = config.get("base_url") else: self.base_url = config.get("url") + # 增加timeout的配置项,单位为秒 + self.timeout = config.get("timeout", 300.0) param_defaults = { "max_tokens": (500, int), @@ -35,7 +38,7 @@ def __init__(self, config): f"意图识别参数初始化: {self.temperature}, {self.max_tokens}, {self.top_p}, {self.frequency_penalty}") check_model_key("LLM", self.api_key) - self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url) + self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url, timeout=httpx.Timeout(self.timeout)) def response(self, session_id, dialogue, **kwargs): try: From 26553b8875e1c4afe45d80e9507bf8b24fda9f24 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Mon, 30 Jun 2025 10:41:15 +0800 Subject: [PATCH 2/2] Update openai.py --- main/xiaozhi-server/core/providers/llm/openai/openai.py | 3 ++- 1 file changed, 2 insertions(+), 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 5605c9729..ca5dd25fb 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -18,7 +18,8 @@ def __init__(self, config): else: self.base_url = config.get("url") # 增加timeout的配置项,单位为秒 - self.timeout = config.get("timeout", 300.0) + timeout = config.get("timeout", 300) + self.timeout = int(timeout) if timeout else 300 param_defaults = { "max_tokens": (500, int),