Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix the parsing error of evalscope with the inference returned by the sglang engine. #261

Closed
wants to merge 1 commit into from
Closed
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
56 changes: 32 additions & 24 deletions evalscope/perf/plugin/api/openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,43 @@ def parse_responses(self, responses, request: Any = None, **kwargs) -> Dict:
delta_contents = {}
input_tokens = None
output_tokens = None

for response in responses:
js = json.loads(response)
if js['object'] == 'chat.completion':
for choice in js['choices']:
delta_contents[choice['index']] = [choice['message']['content']]
input_tokens = js['usage']['prompt_tokens']
output_tokens = js['usage']['completion_tokens']
elif js['object'] == 'text_completion':
for choice in js['choices']:
delta_contents[choice['index']] = [choice['text']]
input_tokens = js['usage']['prompt_tokens']
output_tokens = js['usage']['completion_tokens']
elif js['object'] == 'chat.completion.chunk':
if 'choices' in js:
if 'object' in js:
if js['object'] == 'chat.completion':
for choice in js['choices']:
if 'delta' in choice and 'index' in choice:
delta = choice['delta']
idx = choice['index']
if 'content' in delta:
delta_content = delta['content']
if idx in delta_contents:
delta_contents[idx].append(delta_content)
else:
delta_contents[idx] = [delta_content]
# usage in chunk: {"id":"","object":"chat.completion.chunk","created":1718269986,"model":"llama3",
# "choices":[],"usage":{"prompt_tokens":32,"total_tokens":384,"completion_tokens":352}}
if 'usage' in js and js['usage']:
delta_contents[choice['index']] = [choice['message']['content']]
input_tokens = js['usage']['prompt_tokens']
output_tokens = js['usage']['completion_tokens']
elif js['object'] == 'text_completion':
for choice in js['choices']:
delta_contents[choice['index']] = [choice['text']]
input_tokens = js['usage']['prompt_tokens']
output_tokens = js['usage']['completion_tokens']
elif js['object'] == 'chat.completion.chunk':
if 'choices' in js:
for choice in js['choices']:
if 'delta' in choice and 'index' in choice:
delta = choice['delta']
idx = choice['index']
if 'content' in delta:
delta_content = delta['content']
if idx in delta_contents:
delta_contents[idx].append(delta_content)
else:
delta_contents[idx] = [delta_content]
# usage in chunk
if 'usage' in js and js['usage']:
input_tokens = js['usage']['prompt_tokens']
output_tokens = js['usage']['completion_tokens']
else:
if 'usage' in js and js['usage']:
input_tokens = js['usage'].get('prompt_tokens', 0)
output_tokens = js['usage'].get('completion_tokens', 0)
else:
logger.warning('No `object` or `usage` information found in response.')

if (input_tokens is None and output_tokens is None and self.tokenizer is not None):
input_tokens = 0
output_tokens = 0
Expand Down
Loading