Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ais_bench/benchmark/models/api_models/vllm_custom_api_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ async def parse_stream_response(self, json_content, output):
for item in json_content.get("choices", []):
if item["delta"].get("content"):
output.content += item["delta"]["content"]
if item["delta"].get("reasoning_content"):
output.reasoning_content += item["delta"]["reasoning_content"]
if item["delta"].get("reasoning_content") or item["delta"].get("reasoning"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

【review】所用的框架是什么,标准openai接口返回的应该都是reasoning_content,是否是框架差异导致

output.reasoning_content += item["delta"].get("reasoning_content") or item["delta"].get("reasoning")
Comment on lines +144 to +145
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这部分代码存在重复。item["delta"].get("reasoning_content") or item["delta"].get("reasoning") 这个表达式在 if 条件和 if 代码块中被计算了两次。这不仅效率低下,也降低了代码的可读性。

建议使用海象运算符(:=)来避免重复计算,就像您在 parse_text_response 函数中所做的那样。这样可以使代码更简洁、高效,并与另一处修改保持风格一致。

Suggested change
if item["delta"].get("reasoning_content") or item["delta"].get("reasoning"):
output.reasoning_content += item["delta"].get("reasoning_content") or item["delta"].get("reasoning")
if reasoning := item["delta"].get("reasoning_content") or item["delta"].get("reasoning"):
output.reasoning_content += reasoning

await self._parse_usage(json_content, output)

async def parse_text_response(self, json_content, output):
for item in json_content.get("choices", []):
if content:=item["message"].get("content"):
output.content += content
if reasoning_content:=item["message"].get("reasoning_content"):
if reasoning_content:=item["message"].get("reasoning_content") or item["message"].get("reasoning"):
output.reasoning_content += reasoning_content
await self._parse_usage(json_content, output)
output.update_extra_details_data_from_text_response(json_content)
Expand Down