Skip to content

Commit 2a6f521

Browse files
committed
Update mock_server.py
1 parent 4f99309 commit 2a6f521

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/mock_server.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ async def generate(self, req_data: GenerationRequest, initial_request_id: str):
189189
}
190190
)
191191

192+
# === [thinking_budget 校验] ===
193+
if params.thinking_budget is not None:
194+
# 必须大于 0 (具体限制取决于上游,但负数肯定是无效的)
195+
if params.thinking_budget <= 0:
196+
return JSONResponse(
197+
status_code=400,
198+
content={
199+
"code": "InvalidParameter",
200+
# 保持与代码库中其他错误一致的格式
201+
"message": "<400> InternalError.Algo.InvalidParameter: thinking_budget should be greater than 0"
202+
}
203+
)
204+
# ===================================
205+
192206
# === [新增 response_format 校验逻辑] ===
193207
if params.response_format:
194208
rf_type = params.response_format.get("type")
@@ -339,6 +353,14 @@ async def generate(self, req_data: GenerationRequest, initial_request_id: str):
339353
extra_body["top_k"] = 100 # Clamp to max supported by upstream
340354
else:
341355
extra_body["top_k"] = params.top_k
356+
357+
# === [将 thinking_budget 加入 extra_body] ===
358+
if params.enable_thinking and params.thinking_budget is not None:
359+
# 确保只有在开启思考时才透传 budget,且前面已经校验过 >0
360+
# 如果上游明确支持 thinking_budget 字段:
361+
extra_body["thinking_budget"] = params.thinking_budget
362+
# ===============================================
363+
342364
if extra_body:
343365
openai_params["extra_body"] = extra_body
344366

0 commit comments

Comments
 (0)