From d7155e98c39f051a7865e49553845ca4bbb2021c Mon Sep 17 00:00:00 2001 From: aszerW Date: Sun, 19 Apr 2026 01:00:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20Swagger=20UI=20?= =?UTF-8?q?=E4=B8=AD=20max=5Ftokens=20=E9=BB=98=E8=AE=A4=E5=80=BC=E4=BB=8E?= =?UTF-8?q?=201=20=E6=94=B9=E4=B8=BA=202048?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: max_tokens 设置了 ge=1 约束,导致 Swagger UI 自动生成默认值 1, 响应内容被严重截断 修复: - 移除 ge=1 约束,允许 null 值 - example 改为 2048,符合常规使用场景 - 描述更新为'留空时使用模型默认值' 效果: Swagger UI 测试时 max_tokens 默认显示 2048,可返回完整响应 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index ebbae13..9364a6a 100644 --- a/main.py +++ b/main.py @@ -77,7 +77,7 @@ class ChatCompletionRequest(BaseModel): example=[{"role": "user", "content": "你好,介绍一下你自己"}] ) temperature: Optional[float] = Field(0.7, ge=0, le=2, description="随机性 (0-2)") - max_tokens: Optional[int] = Field(None, ge=1, description="最大生成 token 数") + max_tokens: Optional[int] = Field(None, description="最大生成 token 数(留空时使用模型默认值)", example=2048) stream: Optional[bool] = Field(False, description="是否使用流式输出") top_p: Optional[float] = Field(1.0, ge=0, le=1, description="核采样参数") n: Optional[int] = Field(1, ge=1, le=10, description="生成回复数量")