Skip to content
Merged
Changes from 3 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
50 changes: 40 additions & 10 deletions python/sglang/srt/openai_api/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,11 @@ def v1_chat_generate_request(
top_logprobs_num=top_logprobs_nums,
stream=all_requests[0].stream,
return_text_in_logprobs=True,
rid=request_ids,
rid=(
request_ids
if request_ids is None or len(request_ids) > 1
else request_ids[0]
),
modalities=modalities_list,
lora_path=lora_paths,
bootstrap_host=all_requests[0].bootstrap_host,
Expand Down Expand Up @@ -1375,27 +1379,53 @@ def v1_chat_generate_response(
if to_file:
responses = []

for i, choice in enumerate(choices):
if len(choices) == 1:
response = {
"status_code": 200,
"request_id": ret[i]["meta_info"]["id"],
"request_id": ret[0]["meta_info"]["id"],
"body": {
# remain the same but if needed we can change that
"id": ret[i]["meta_info"]["id"],
"id": ret[0]["meta_info"]["id"],
"object": "chat.completion",
"created": created,
"model": request[i].model,
"choices": choice,
"model": request.model,
"choices": choices[0],
"usage": {
"prompt_tokens": ret[i]["meta_info"]["prompt_tokens"],
"completion_tokens": ret[i]["meta_info"]["completion_tokens"],
"total_tokens": ret[i]["meta_info"]["prompt_tokens"]
+ ret[i]["meta_info"]["completion_tokens"],
"prompt_tokens": ret[0]["meta_info"]["prompt_tokens"],
"completion_tokens": ret[0]["meta_info"]["completion_tokens"],
"total_tokens": ret[0]["meta_info"]["prompt_tokens"]
+ ret[0]["meta_info"]["completion_tokens"],
},
"system_fingerprint": None,
},
}

responses.append(response)
else:
for i, choice in enumerate(choices):
response = {
"status_code": 200,
"request_id": ret[i]["meta_info"]["id"],
"body": {
# remain the same but if needed we can change that
"id": ret[i]["meta_info"]["id"],
"object": "chat.completion",
"created": created,
"model": request[i].model,
"choices": choice,
"usage": {
"prompt_tokens": ret[i]["meta_info"]["prompt_tokens"],
"completion_tokens": ret[i]["meta_info"][
"completion_tokens"
],
"total_tokens": ret[i]["meta_info"]["prompt_tokens"]
+ ret[i]["meta_info"]["completion_tokens"],
},
"system_fingerprint": None,
},
}
responses.append(response)

return responses
else:
prompt_tokens = sum(
Expand Down