nemo_gym.responses_converter
nemo_gym.responses_converter
Shared Responses API ↔ Chat Completions converter.
This module contains the translation logic between OpenAI’s Responses API format and the Chat Completions API format. It is used by model servers that need to convert between the two formats (e.g. vllm_model, inference_provider).
Module Contents
Classes
Functions
Data
VLLMConverterResponsesToChatCompletionsState
_REPORTING_ONLY_REASONING_FIELDS
_RESPONSE_OUTPUT_BOUNDARY_TYPES
API
Bases: BaseModel
Converts between OpenAI Responses API and Chat Completions API formats.
Collects text from ‘reasoning’ messages in responses api and appends it to a buffer.
This is done to group together one (or multiple) reasoning message(s) into a single, cohesive block, later prepending it to a subsequent assistant message. See: https://docs.nvidia.com/nemo/gym/main/infrastructure/engineering-notes/responses-api-evolution for background on reasoning in the Responses API.
Convert Responses create params into Chat Completions create params.
A Responses field with no Chat Completions representation raises NotImplementedError,
so the caller can route the request to a server that serves Responses natively. With
drop_unrepresentable_request_fields the reporting-only fields are removed from the
request instead and the conversion proceeds: a non-empty include (every value; an
empty one is already treated as absent), reasoning.summary and
reasoning.generate_summary, and a message phase. An image part in a tool’s output
becomes the text placeholder _IMAGE_OUTPUT_PLACEHOLDER, which does replace that part
of the prompt. Every other unrepresentable field, reasoning.context included, is still
refused.
Bases: BaseModel
Keep the token entries that survive removing the removed character spans.
Reasoning extraction shortens the output text; its logprobs must shrink with it or
they describe different text. The kept positions come from the removal itself, never
from searching for the answer text, which may also occur inside the reasoning. If the
tokens do not reconstruct original the alignment is unknowable and the logprobs
are dropped rather than misattributed.
Chat choice logprobs in the shape ResponseOutputText.logprobs expects.
Same field names on both sides; the Responses models require bytes to be
iterable where chat allows null.
Plain text of a chat message content (a string, or a list of text parts).
Return a provider-reported token count without coercing missing/invalid values to zero.
Return validated token metadata when the mapping contains it.
Read one canonical nested token detail, then named provider aliases.