Skip to content

feat: add response_id from API response to prediction results#401

Closed
xuchi-0808 wants to merge 1 commit into
AISBench:masterfrom
xuchi-0808:feat/response-id
Closed

feat: add response_id from API response to prediction results#401
xuchi-0808 wants to merge 1 commit into
AISBench:masterfrom
xuchi-0808:feat/response-id

Conversation

@xuchi-0808

Copy link
Copy Markdown

Summary

Add the id field from OpenAI-compatible API responses (e.g., chatcmpl-xxx from /v1/chat/completions) to the prediction result JSONL files.

Currently, AISBench discards the id field from API responses. This PR captures it and stores it as response_id in the prediction output, making it possible to trace inference results back to specific API calls.

Changes

  1. ais_bench/benchmark/models/output.py — Added response_id field to Output class
  2. ais_bench/benchmark/models/api_models/vllm_custom_api_chat.py — Parse id from /v1/chat/completions responses (both text and stream modes)
  3. ais_bench/benchmark/models/api_models/vllm_custom_api.py — Parse id from /v1/completions responses (both text and stream modes)
  4. ais_bench/benchmark/openicl/icl_inferencer/output_handler/gen_inferencer_output_handler.py — Include response_id in the prediction result dict written to predictions/{dataset}.jsonl

Example output

Each line in predictions/{model_abbr}/{dataset_abbr}.jsonl will now include:

{
  "success": true,
  "uuid": "abc12345",
  "response_id": "chatcmpl-9a8b7c6d5e",
  "origin_prompt": "...",
  "prediction": "...",
  "gold": "..."
}

Design notes

  • For streaming responses, the id is captured from the first SSE chunk and preserved
  • The response_id field defaults to empty string when not available (backward compatible)
  • Both chat API (/v1/chat/completions) and legacy completion API (/v1/completions) are covered

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a response_id field to track API response identifiers across text and stream responses. It updates the Output class, the VLLM custom API models, and the output handler to capture and propagate this ID. The feedback suggests using getattr to retrieve response_id in the output handler, which provides a more robust and Pythonic approach by avoiding explicit type checks and potential attribute errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +64 to +66
"response_id": (
output.response_id if isinstance(output, Output) and output.response_id else ""
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using getattr(output, "response_id", "") is a more robust and Pythonic way to retrieve the response_id attribute. It avoids potential AttributeError if output is a mock object or a custom subclass that does not have the response_id attribute initialized, and it eliminates the need for explicit type checking since getattr safely handles any object type (including str).

            "response_id": getattr(output, "response_id", ""),

@xuchi-0808 xuchi-0808 force-pushed the feat/response-id branch 3 times, most recently from bb8a0b8 to 59dd8ac Compare July 15, 2026 11:52
Parse the 'id' field (e.g. chatcmpl-xxx) from OpenAI-compatible API
responses in VLLMCustomAPIChat and VLLMCustomAPI, store it in the
Output object, and include it in the generated prediction JSONL files
under the predictions/ directory.

The response_id helps trace inference results back to specific API
calls for debugging and audit purposes.

Signed-off-by: xuchi-0808 <xuchi0808@gmail.com>
Signed-off-by: xuchi <xuchicolson@163.com>
@xuchi-0808 xuchi-0808 closed this Jul 15, 2026
@xuchi-0808 xuchi-0808 deleted the feat/response-id branch July 15, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant