From aae0629b2dc924ed6f9ca7962a2bbb3ea2da798a Mon Sep 17 00:00:00 2001 From: hhs <386998068@qq.com> Date: Sun, 14 Jun 2026 11:55:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20LLM=20=E6=9C=8D=E5=8A=A1=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E9=87=8D=E5=A4=8D=E9=BB=98=E8=AE=A4=E5=80=BC=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20httpClientTimeout=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 去除 model/endpoint 的 fallback 默认值 - HTTP Client 超时从 config 传入 --- backend/internal/ai/llm/openai.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/internal/ai/llm/openai.go b/backend/internal/ai/llm/openai.go index bbc9444..754176c 100644 --- a/backend/internal/ai/llm/openai.go +++ b/backend/internal/ai/llm/openai.go @@ -26,24 +26,23 @@ type OpenAIService struct { } // NewOpenAIService 创建 OpenAI LLM 服务。 -func NewOpenAIService(apiKey, model, endpoint string, timeoutSec int, logger *zap.SugaredLogger) *OpenAIService { - if model == "" { - model = "gpt-4o" - } - if endpoint == "" { - endpoint = "https://api.openai.com/v1" - } +// model、endpoint 由 config 层保证非空。 +func NewOpenAIService(apiKey, model, endpoint string, timeoutSec, httpClientTimeoutSec int, logger *zap.SugaredLogger) *OpenAIService { timeout := time.Duration(timeoutSec) * time.Second if timeout <= 0 { timeout = 10 * time.Second } + httpClientTimeout := time.Duration(httpClientTimeoutSec) * time.Second + if httpClientTimeout <= 0 { + httpClientTimeout = 60 * time.Second + } return &OpenAIService{ apiKey: apiKey, model: model, endpoint: endpoint, timeout: timeout, logger: logger, - client: &http.Client{Timeout: 60 * time.Second}, // HTTP client timeout > LLM timeout + client: &http.Client{Timeout: httpClientTimeout}, } }