diff --git a/python/sglang/srt/openai_api/adapter.py b/python/sglang/srt/openai_api/adapter.py index b49601933d..f5e84cbe94 100644 --- a/python/sglang/srt/openai_api/adapter.py +++ b/python/sglang/srt/openai_api/adapter.py @@ -989,11 +989,15 @@ def v1_chat_generate_response(request, ret, to_file=False, cache_report=False): output_top_logprobs=ret_item["meta_info"]["output_top_logprobs"], ) token_logprobs = [] - for token, logprob in zip(logprobs.tokens, logprobs.token_logprobs): + for token_idx, (token, logprob) in enumerate( + zip(logprobs.tokens, logprobs.token_logprobs) + ): token_bytes = list(token.encode("utf-8")) top_logprobs = [] if logprobs.top_logprobs: - for top_token, top_logprob in logprobs.top_logprobs[0].items(): + for top_token, top_logprob in logprobs.top_logprobs[ + token_idx + ].items(): top_token_bytes = list(top_token.encode("utf-8")) top_logprobs.append( TopLogprob(