From eb0f34a4d17167f1f5954543e834517c84ffa1c1 Mon Sep 17 00:00:00 2001 From: jiangzj Date: Mon, 19 Jan 2026 17:11:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/ai/openai_client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/ai/openai_client.go b/pkg/ai/openai_client.go index bd2c543..d9f82e1 100644 --- a/pkg/ai/openai_client.go +++ b/pkg/ai/openai_client.go @@ -168,6 +168,7 @@ func (c *OpenAIClient) sendChatRequest(req *ChatCompletionRequest) (*ChatComplet if len(chatResp.Choices) > 0 { finishReason := chatResp.Choices[0].FinishReason content := chatResp.Choices[0].Message.Content + usage := chatResp.Usage fmt.Printf("OpenAI: finish_reason=%s, content_length=%d\n", finishReason, len(content)) @@ -175,7 +176,7 @@ func (c *OpenAIClient) sendChatRequest(req *ChatCompletionRequest) (*ChatComplet return nil, fmt.Errorf("AI内容被安全过滤器拦截,可能因为:\n1. 请求内容触发了安全策略\n2. 生成的内容包含敏感信息\n3. 建议:调整输入内容或联系API提供商调整过滤策略") } - if content == "" && finishReason != "stop" { + if usage.TotalTokens == 0 && finishReason != "stop" { return nil, fmt.Errorf("AI返回内容为空 (finish_reason: %s),可能的原因:\n1. 内容被过滤\n2. Token限制\n3. API异常", finishReason) } }