Skip to content

Commit e5709da

Browse files
committed
Update mock_server.py
1 parent baca1f1 commit e5709da

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

tests/mock_server.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async def generate(
205205
force_stream: bool = False,
206206
skip_model_exist_check: bool = False,
207207
):
208-
# 1. 模型存在性检查
208+
# Model existence check
209209
if not skip_model_exist_check and req_data.model not in MODEL_MAPPING:
210210
return JSONResponse(
211211
status_code=400,
@@ -215,7 +215,7 @@ async def generate(
215215
},
216216
)
217217

218-
# 2. Input 内容检查
218+
# Input content validation
219219
has_input = req_data.input is not None
220220
has_content = False
221221
if has_input:
@@ -251,7 +251,7 @@ async def generate(
251251

252252
params = req_data.parameters
253253

254-
# 3. Logprobs 检查
254+
# Logprobs check
255255
if params.logprobs:
256256
return JSONResponse(
257257
status_code=400,
@@ -261,7 +261,7 @@ async def generate(
261261
},
262262
)
263263

264-
# 4. Max Tokens 检查
264+
# Max Tokens check
265265
if params.max_tokens is not None and params.max_tokens < 1:
266266
return JSONResponse(
267267
status_code=400,
@@ -271,7 +271,7 @@ async def generate(
271271
},
272272
)
273273

274-
# 5. N (Completions) 检查
274+
# N (Completions) check
275275
if params.n is not None:
276276
if not (1 <= params.n <= 4):
277277
return JSONResponse(
@@ -282,7 +282,7 @@ async def generate(
282282
},
283283
)
284284

285-
# 6. Thinking Budget 检查
285+
# Thinking Budget check
286286
if params.thinking_budget is not None:
287287
if params.thinking_budget <= 0:
288288
return JSONResponse(
@@ -293,7 +293,7 @@ async def generate(
293293
},
294294
)
295295

296-
# 7. Seed 检查
296+
# Seed check
297297
if params.seed is not None:
298298
if not (0 <= params.seed <= 9223372036854775807):
299299
return JSONResponse(
@@ -304,7 +304,7 @@ async def generate(
304304
},
305305
)
306306

307-
# 8. Response Format 检查
307+
# Response Format check
308308
if params.response_format:
309309
rf_type = params.response_format.get("type")
310310
if rf_type and rf_type not in ["json_object", "text"]:
@@ -325,7 +325,7 @@ async def generate(
325325
},
326326
)
327327

328-
# 9. Tool Calls 链条逻辑检查
328+
# Tool Calls chain logic validation
329329
if req_data.input.messages:
330330
msgs = req_data.input.messages
331331
for idx, msg in enumerate(msgs):
@@ -386,7 +386,7 @@ async def generate(
386386
},
387387
)
388388

389-
# 10. Stop 参数提取 (Proxy侧处理,不再透传给上游)
389+
# Stop parameter extraction
390390
proxy_stop_list: List[str] = []
391391
if params.stop:
392392
if isinstance(params.stop, str):
@@ -401,7 +401,7 @@ async def generate(
401401
if sw.get("mode", "exclude") == "exclude" and "stop_str" in sw:
402402
proxy_stop_list.append(sw["stop_str"])
403403

404-
# 去重
404+
# Deduplicate
405405
proxy_stop_list = list(set(proxy_stop_list))
406406

407407
# --- Request Parameters Assembly ---
@@ -418,7 +418,7 @@ async def generate(
418418
"temperature": params.temperature,
419419
"top_p": params.top_p,
420420
"stream": should_stream,
421-
# 注意: "stop" 在这里被有意省略,完全由Proxy侧接管
421+
# Note: "stop" is intentionally omitted here, handled by proxy
422422
}
423423

424424
if params.response_format:
@@ -613,7 +613,7 @@ async def _stream_generator(
613613

614614
delta = chunk.choices[0].delta if chunk.choices else None
615615

616-
# 1. Reasoning Content (Pass-through directly, no stop logic)
616+
# Reasoning Content
617617
delta_reasoning = (
618618
(getattr(delta, "reasoning_content", "") or "") if delta else ""
619619
)
@@ -630,7 +630,7 @@ async def _stream_generator(
630630
request_id=request_id,
631631
)
632632

633-
# 2. Content (Buffered and checked for stop)
633+
# Content
634634
delta_content = delta.content if delta and delta.content else ""
635635

636636
content_to_yield = ""
@@ -650,7 +650,7 @@ async def _stream_generator(
650650
)
651651

652652
if earliest_idx != -1:
653-
# Stop found!
653+
# Stop found
654654
stop_triggered = True
655655
finish_reason = "stop"
656656

@@ -663,7 +663,6 @@ async def _stream_generator(
663663
else:
664664
# No stop found yet.
665665
# We can safely yield the part of the buffer that is "safe"
666-
# i.e., characters that cannot possibly be the start of a stop sequence being formed.
667666
# Simplest heuristic: Keep the last N characters where N is max_stop_len
668667
if len(content_buffer) > max_stop_len:
669668
safe_chars = len(content_buffer) - max_stop_len
@@ -672,7 +671,7 @@ async def _stream_generator(
672671
full_text += chunk_safe
673672
content_buffer = content_buffer[safe_chars:]
674673

675-
# Tool calls logic (accumulation)
674+
# Tool calls logic
676675
current_tool_calls_payload = None
677676
if delta and delta.tool_calls:
678677
if is_incremental:
@@ -937,10 +936,10 @@ def create_app() -> FastAPI:
937936
)
938937

939938
@app.exception_handler(RequestValidationError)
940-
@app.exception_handler(ValidationError) # <--- 新增这行,捕获手动解析时的错误
939+
@app.exception_handler(ValidationError) # Catch errors during manual parsing
941940
async def validation_exception_handler(request, exc):
942941
try:
943-
# 兼容两种异常获取 errors 的方式
942+
# Compatible with two ways of retrieving errors
944943
errors = exc.errors() if hasattr(exc, "errors") else []
945944
except Exception:
946945
errors = [{"msg": str(exc), "loc": [], "type": "unknown"}]
@@ -962,7 +961,7 @@ async def validation_exception_handler(request, exc):
962961
err_type = err.get("type")
963962
input_value = err.get("input")
964963

965-
# --- 以下保持原有的逻辑不变 ---
964+
# Keep original logic below
966965

967966
if err_type == "int_parsing":
968967
if isinstance(input_value, str):
@@ -1059,7 +1058,7 @@ async def validation_exception_handler(request, exc):
10591058
},
10601059
)
10611060

1062-
# 兜底日志
1061+
# Fallback logging
10631062
logger.error(f"Validation Error: {errors}")
10641063

10651064
return JSONResponse(

0 commit comments

Comments
 (0)