nemo_gym.openai_utils

View as Markdown

Module Contents

Classes

NameDescription
NeMoGymAsyncOpenAIThis is just a stub class that wraps around aiohttp
NeMoGymChatCompletion-
NeMoGymChatCompletionAssistantMessageForTrainingParam-
NeMoGymChatCompletionAssistantMessageParam-
NeMoGymChatCompletionContentPartFileParam-
NeMoGymChatCompletionContentPartImageParam-
NeMoGymChatCompletionContentPartInputAudioParam-
NeMoGymChatCompletionContentPartTextParam-
NeMoGymChatCompletionCreateParamsNonStreaming-
NeMoGymChatCompletionCustomToolParam-
NeMoGymChatCompletionDeveloperMessageParam-
NeMoGymChatCompletionMessage-
NeMoGymChatCompletionMessageCustomToolCall-
NeMoGymChatCompletionMessageCustomToolCallParam-
NeMoGymChatCompletionMessageForTraining-
NeMoGymChatCompletionMessageToolCall-
NeMoGymChatCompletionMessageToolCallFunctionParam-
NeMoGymChatCompletionMessageToolCallParam-
NeMoGymChatCompletionSystemMessageParam-
NeMoGymChatCompletionToolMessageParam-
NeMoGymChatCompletionToolParam-
NeMoGymChatCompletionUserMessageParam-
NeMoGymChoice-
NeMoGymComputerCallOutputThe client’s result of a computer-use action (computer_call_output item).
NeMoGymEasyInputMessage-
NeMoGymEasyInputMessageForTraining-
NeMoGymFunction-
NeMoGymFunctionCallOutputWe copy openai.types.responses.response_input_param.FunctionCallOutput, originally a TypedDict, as a BaseModel here
NeMoGymFunctionDefinition-
NeMoGymFunctionToolParam-
NeMoGymImageGenerationCallA hosted image-generation call (OpenAI Responses image_generation_call output item).
NeMoGymLocalShellCallA local-shell command for the client to execute (local_shell_call output item).
NeMoGymLocalShellCallOutputThe client’s result of a local shell command (local_shell_call_output item).
NeMoGymMcpApprovalResponseThe client’s answer to a hosted-MCP approval request (mcp_approval_response item).
NeMoGymMessage-
NeMoGymMessageForTraining-
NeMoGymResponse-
NeMoGymResponseCodeInterpreterToolCallA hosted code-interpreter call (OpenAI Responses code_interpreter_call output item).
NeMoGymResponseComputerToolCallA computer-use action for the client to execute (computer_call output item).
NeMoGymResponseCreateParamsNonStreamingThis class is a copy of openai.types.responses.response_create_params.ResponseCreateParamsNonStreaming
NeMoGymResponseCustomToolCallA client-executed custom tool call (OpenAI Responses custom_tool_call output item).
NeMoGymResponseCustomToolCallOutputThe client’s result of a custom tool call (custom_tool_call_output item).
NeMoGymResponseFileSearchToolCallA hosted file-search call (OpenAI Responses file_search_call output item).
NeMoGymResponseFunctionToolCall-
NeMoGymResponseFunctionToolCallForTraining-
NeMoGymResponseFunctionWebSearchA hosted web-search call (OpenAI Responses web_search_call output item).
NeMoGymResponseInputText-
NeMoGymResponseInputTokensDetails-
NeMoGymResponseMcpApprovalRequestA hosted-MCP approval request (OpenAI Responses mcp_approval_request item).
NeMoGymResponseMcpCallA hosted-MCP tool call (OpenAI Responses mcp_call output item).
NeMoGymResponseMcpListToolsA hosted-MCP tool listing (OpenAI Responses mcp_list_tools output item).
NeMoGymResponseOutputMessage-
NeMoGymResponseOutputMessageForTraining-
NeMoGymResponseOutputRefusal-
NeMoGymResponseOutputText-
NeMoGymResponseOutputTokensDetails-
NeMoGymResponseReasoningItem-
NeMoGymResponseReasoningItemForTraining-
NeMoGymResponseUsage-
NeMoGymSummary-
TokenIDLogProbMixin-
TokenIDLogProbTypedDictMixin-

Functions

NameDescription
_require_response_output_item_typePrevent an untagged output item from being coerced into the wrong union member.
_validate_atomic_token_metadataRequire complete token metadata when any token field is present.
accumulate_response_usageAccumulate top-level and detailed response token counts.
training_variant_ofReturn the ForTraining subclass that carries token IDs for item_cls.

Data

NeMoGymChatCompletionContentPartParam

NeMoGymChatCompletionMessageParam

NeMoGymChatCompletionMessageToolCallUnion

NeMoGymChatCompletionMessageToolCallUnionParam

NeMoGymChatCompletionOutputMessage

NeMoGymChatCompletionToolUnionParam

NeMoGymContent

NeMoGymResponseInput

NeMoGymResponseInputItem

NeMoGymResponseOutputItem

RATE_LIMIT_ERROR_CODES

RESPONSES_TO_TRAIN

RETRY_ERROR_CODES

RoutedExperts

_REQUIRED_TOKEN_METADATA_FIELDS

_TOKEN_METADATA_FIELDS

API

class nemo_gym.openai_utils.NeMoGymAsyncOpenAI()

Bases: BaseModel

This is just a stub class that wraps around aiohttp

api_key
str
base_url
str
default_headers
Dict[str, str]
internal
bool
nemo_gym.openai_utils.NeMoGymAsyncOpenAI._raise_for_status(
response: nemo_gym.server_utils.ClientResponse,
request_kwargs: typing.Dict[str, typing.Any]
) -> None
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI._request(
request_kwargs: typing.Dict = {}
) -> nemo_gym.server_utils.ClientResponse
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI._request_with_retry(
request_kwargs: typing.Dict = {}
) -> nemo_gym.server_utils.ClientResponse
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_chat_completion(
kwargs = {}
)
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_completion(
kwargs = {}
)
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_models()
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_response(
kwargs = {}
)
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_tokenize(
kwargs = {}
)
async
class nemo_gym.openai_utils.NeMoGymChatCompletion()

Bases: ChatCompletion

choices
List[NeMoGymChoice]
class nemo_gym.openai_utils.NeMoGymChatCompletionAssistantMessageForTrainingParam

Bases: typing.TypedDict

class nemo_gym.openai_utils.NeMoGymChatCompletionAssistantMessageParam()

Bases: ChatCompletionAssistantMessageParam

content
Union[str, List[ContentArrayOfContentPart], None]
tool_calls
Optional[List[NeMoGymChatCompletionMessageToolCallUnionParam]] = None
class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartFileParam()

Bases: ChatCompletionContentPartFileParam

class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartImageParam()

Bases: ChatCompletionContentPartImageParam

class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartInputAudioParam()

Bases: ChatCompletionContentPartInputAudioParam

class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartTextParam()

Bases: ChatCompletionContentPartTextParam

class nemo_gym.openai_utils.NeMoGymChatCompletionCreateParamsNonStreaming()

Bases: BaseModel

audio
Optional[ChatCompletionAudioParam] = None
frequency_penalty
Optional[float] = None
logit_bias
Optional[Dict[str, int]] = None
logprobs
Optional[bool] = None
max_completion_tokens
Optional[int] = None
max_tokens
Optional[int] = None
messages
List[NeMoGymChatCompletionMessageParam]
metadata
Optional[Metadata] = None
modalities
Optional[List[Literal['text', 'audio']]] = None
model
Optional[Union[str, ChatModel]] = None
n
Optional[int] = None
parallel_tool_calls
bool = True
prediction
Optional[ChatCompletionPredictionContentParam] = None
presence_penalty
Optional[float] = None
reasoning_effort
Optional[ReasoningEffort] = None
response_format
Optional[ResponseFormat] = None
seed
Optional[int] = None
service_tier
Optional[Literal['auto', 'default', 'flex', 'scale', 'priority']] = None
stop
Union[Optional[str], List[str], None] = None
store
Optional[bool] = None
stream
Optional[Literal[False]] = None
stream_options
Optional[ChatCompletionStreamOptionsParam] = None
temperature
Optional[float] = None
tool_choice
Optional[ChatCompletionToolChoiceOptionParam] = None
tools
Optional[List[NeMoGymChatCompletionToolUnionParam]] = None
top_logprobs
Optional[int] = None
top_p
Optional[float] = None
user
Optional[str] = None
web_search_options
Optional[WebSearchOptions] = None
class nemo_gym.openai_utils.NeMoGymChatCompletionCustomToolParam()

Bases: ChatCompletionCustomToolParam

class nemo_gym.openai_utils.NeMoGymChatCompletionDeveloperMessageParam()

Bases: ChatCompletionDeveloperMessageParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartTextParam]]]
class nemo_gym.openai_utils.NeMoGymChatCompletionMessage()

Bases: ChatCompletionMessage

tool_calls
Optional[List[NeMoGymChatCompletionMessageToolCallUnion]] = None
class nemo_gym.openai_utils.NeMoGymChatCompletionMessageCustomToolCall()

Bases: ChatCompletionMessageCustomToolCall

class nemo_gym.openai_utils.NeMoGymChatCompletionMessageCustomToolCallParam()

Bases: ChatCompletionMessageCustomToolCallParam

class nemo_gym.openai_utils.NeMoGymChatCompletionMessageForTraining()
class nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCall()

Bases: ChatCompletionMessageToolCall

function
NeMoGymFunction
class nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallFunctionParam

Bases: typing.TypedDict

arguments
Required[str]
name
Required[str]
class nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallParam()

Bases: ChatCompletionMessageToolCallParam

function
NeMoGymChatCompletionMessageToolCallFunctionParam
class nemo_gym.openai_utils.NeMoGymChatCompletionSystemMessageParam()

Bases: ChatCompletionSystemMessageParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartTextParam]]]
class nemo_gym.openai_utils.NeMoGymChatCompletionToolMessageParam()

Bases: ChatCompletionToolMessageParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartTextParam]]]
class nemo_gym.openai_utils.NeMoGymChatCompletionToolParam()

Bases: ChatCompletionToolParam

function
Required[NeMoGymFunctionDefinition]
class nemo_gym.openai_utils.NeMoGymChatCompletionUserMessageParam()

Bases: ChatCompletionUserMessageParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartParam]]]
class nemo_gym.openai_utils.NeMoGymChoice()

Bases: Choice

message
NeMoGymChatCompletionOutputMessage
class nemo_gym.openai_utils.NeMoGymComputerCallOutput()

Bases: ComputerCallOutput

The client’s result of a computer-use action (computer_call_output item).

class nemo_gym.openai_utils.NeMoGymEasyInputMessage()

Bases: BaseModel

content
Union[str, ResponseInputMessageContentListParam]
role
Literal['user', 'assistant', 'system', 'developer']
type
Literal['message'] = 'message'
class nemo_gym.openai_utils.NeMoGymEasyInputMessageForTraining()
class nemo_gym.openai_utils.NeMoGymFunction()

Bases: BaseModel

arguments
str
name
str
class nemo_gym.openai_utils.NeMoGymFunctionCallOutput()

Bases: BaseModel

We copy openai.types.responses.response_input_param.FunctionCallOutput, originally a TypedDict, as a BaseModel here so that we can use it in the NeMoGymResponseOutputItem below and be consistent with the other ResponseOutputItem types.

call_id
str
id
Optional[str] = None
output
Union[str, ResponseFunctionCallOutputItemListParam]
status
Optional[Literal['in_progress', 'completed', 'incomplete']] = None
type
Literal['function_call_output'] = 'function_call_output'
class nemo_gym.openai_utils.NeMoGymFunctionDefinition()

Bases: FunctionDefinition

class nemo_gym.openai_utils.NeMoGymFunctionToolParam()

Bases: FunctionToolParam

class nemo_gym.openai_utils.NeMoGymImageGenerationCall()

Bases: ImageGenerationCall

A hosted image-generation call (OpenAI Responses image_generation_call output item).

class nemo_gym.openai_utils.NeMoGymLocalShellCall()

Bases: LocalShellCall

A local-shell command for the client to execute (local_shell_call output item).

class nemo_gym.openai_utils.NeMoGymLocalShellCallOutput()

Bases: LocalShellCallOutput

The client’s result of a local shell command (local_shell_call_output item).

class nemo_gym.openai_utils.NeMoGymMcpApprovalResponse()

Bases: McpApprovalResponse

The client’s answer to a hosted-MCP approval request (mcp_approval_response item).

class nemo_gym.openai_utils.NeMoGymMessage()

Bases: BaseModel

content
ResponseInputMessageContentListParam
role
Literal['user', 'system', 'developer']
status
Literal['in_progress', 'completed', 'incomplete'] = 'completed'
type
Literal['message'] = 'message'
class nemo_gym.openai_utils.NeMoGymMessageForTraining()
class nemo_gym.openai_utils.NeMoGymResponse()

Bases: Response

output
List[NeMoGymResponseOutputItem]
usage
Optional[NeMoGymResponseUsage] = None
class nemo_gym.openai_utils.NeMoGymResponseCodeInterpreterToolCall()

Bases: ResponseCodeInterpreterToolCall

A hosted code-interpreter call (OpenAI Responses code_interpreter_call output item).

class nemo_gym.openai_utils.NeMoGymResponseComputerToolCall()

Bases: ResponseComputerToolCall

A computer-use action for the client to execute (computer_call output item).

class nemo_gym.openai_utils.NeMoGymResponseCreateParamsNonStreaming()

Bases: BaseModel

This class is a copy of openai.types.responses.response_create_params.ResponseCreateParamsNonStreaming We make a copy of it here since ResponseCreateParamsNonStreaming is a TypedDict with no strict validation. We need to do server side validation here.

background
Optional[bool] = None
include
Optional[List[ResponseIncludable]] = None
input
Union[str, NeMoGymResponseInput]
instructions
Optional[str] = None
max_output_tokens
Optional[int] = None
max_tool_calls
Optional[int] = None
metadata
Optional[Metadata] = None
model
Optional[ResponsesModel] = None
model_config
= ConfigDict(extra='forbid')
parallel_tool_calls
bool = True
previous_response_id
Optional[str] = None
prompt
Optional[ResponsePromptParam] = None
reasoning
Optional[Reasoning] = None
service_tier
Optional[Literal['auto', 'default', 'flex', 'scale', 'priority']] = None
store
Optional[bool] = None
stream
Optional[Literal[False]] = None
temperature
Optional[float] = None
text
Optional[ResponseTextConfigParam] = None
tool_choice
ToolChoice = 'auto'
tools
List[ToolParam] = Field(default_factory=list)
top_logprobs
Optional[int] = None
top_p
Optional[float] = None
truncation
Optional[Literal['auto', 'disabled']] = None
user
Optional[str] = None
class nemo_gym.openai_utils.NeMoGymResponseCustomToolCall()

Bases: ResponseCustomToolCall

A client-executed custom tool call (OpenAI Responses custom_tool_call output item).

class nemo_gym.openai_utils.NeMoGymResponseCustomToolCallOutput()

Bases: ResponseCustomToolCallOutput

The client’s result of a custom tool call (custom_tool_call_output item).

class nemo_gym.openai_utils.NeMoGymResponseFileSearchToolCall()

Bases: ResponseFileSearchToolCall

A hosted file-search call (OpenAI Responses file_search_call output item).

The provider executes the search and returns the call in response.output. Inherits the upstream typing unchanged.

class nemo_gym.openai_utils.NeMoGymResponseFunctionToolCall()

Bases: BaseModel

arguments
str
call_id
str
id
Optional[str] = None
name
str
status
Optional[Literal['in_progress', 'completed', 'incomplete']] = None
type
Literal['function_call'] = 'function_call'
class nemo_gym.openai_utils.NeMoGymResponseFunctionToolCallForTraining()
class nemo_gym.openai_utils.NeMoGymResponseFunctionWebSearch()

Bases: ResponseFunctionWebSearch

A hosted web-search call (OpenAI Responses web_search_call output item).

class nemo_gym.openai_utils.NeMoGymResponseInputText()

Bases: ResponseInputTextParam

class nemo_gym.openai_utils.NeMoGymResponseInputTokensDetails()

Bases: ResponseInputTokensDetails

class nemo_gym.openai_utils.NeMoGymResponseMcpApprovalRequest()

Bases: McpApprovalRequest

A hosted-MCP approval request (OpenAI Responses mcp_approval_request item).

Inherits the upstream McpApprovalRequest typing; id/server_label are relaxed to optional to tolerate endpoints that omit them.

id
Optional[str] = None
server_label
Optional[str] = None
type
Literal['mcp_approval_request'] = 'mcp_approval_request'
class nemo_gym.openai_utils.NeMoGymResponseMcpCall()

Bases: McpCall

A hosted-MCP tool call (OpenAI Responses mcp_call output item).

Emitted when the upstream endpoint executes a tool server-side (e.g. NVIDIA-hosted gpt-oss surfacing its built-in python tool as MCP) instead of returning a client-executed function_call. The output/error fields are already populated by the server, so the agent parses and passes it through; there is no client-side execution and hence no training variant.

Inherits the upstream McpCall typing and only relaxes the fields NVIDIA-hosted endpoints may omit or widen: id/server_label are made optional and status accepts any string (upstream pins it to a Literal).

id
Optional[str] = None
server_label
Optional[str] = None
status
Optional[str] = None
type
Literal['mcp_call'] = 'mcp_call'
class nemo_gym.openai_utils.NeMoGymResponseMcpListTools()

Bases: McpListTools

A hosted-MCP tool listing (OpenAI Responses mcp_list_tools output item).

Inherits the upstream McpListTools typing; only id/server_label are relaxed to optional (NVIDIA-hosted endpoints may omit them) and tools is widened to List[Any] so raw tool entries pass through without being coerced into the upstream McpListToolsTool schema.

id
Optional[str] = None
server_label
Optional[str] = None
tools
List[Any] = Field(default_factory=list)
type
Literal['mcp_list_tools'] = 'mcp_list_tools'
class nemo_gym.openai_utils.NeMoGymResponseOutputMessage()

Bases: BaseModel

content
List[NeMoGymContent]
id
str
role
Literal['assistant'] = 'assistant'
status
Literal['in_progress', 'completed', 'incomplete'] = 'completed'
type
Literal['message'] = 'message'
class nemo_gym.openai_utils.NeMoGymResponseOutputMessageForTraining()
class nemo_gym.openai_utils.NeMoGymResponseOutputRefusal()

Bases: BaseModel

refusal
str
type
Literal['refusal'] = 'refusal'
class nemo_gym.openai_utils.NeMoGymResponseOutputText()

Bases: BaseModel

annotations
List[Annotation]
logprobs
Optional[List[Logprob]] = None
text
str
type
Literal['output_text'] = 'output_text'
class nemo_gym.openai_utils.NeMoGymResponseOutputTokensDetails()

Bases: ResponseOutputTokensDetails

class nemo_gym.openai_utils.NeMoGymResponseReasoningItem()

Bases: BaseModel

content
Optional[List[ReasoningContent]] = None
encrypted_content
Optional[str] = None
id
str
summary
List[NeMoGymSummary]
type
Literal['reasoning'] = 'reasoning'
class nemo_gym.openai_utils.NeMoGymResponseReasoningItemForTraining()
class nemo_gym.openai_utils.NeMoGymResponseUsage()

Bases: ResponseUsage

input_tokens_details
NeMoGymResponseInputTokensDetails
output_tokens_details
NeMoGymResponseOutputTokensDetails
classmethod
class nemo_gym.openai_utils.NeMoGymSummary()

Bases: Summary

class nemo_gym.openai_utils.TokenIDLogProbMixin()

Bases: BaseModel

generation_log_probs
List[float]
generation_token_ids
List[int]
prompt_token_ids
List[int]
routed_experts
Optional[RoutedExperts] = None
class nemo_gym.openai_utils.TokenIDLogProbTypedDictMixin

Bases: typing.TypedDict

generation_log_probs
List[float]
generation_token_ids
List[int]
prompt_token_ids
List[int]
routed_experts
NotRequired[RoutedExperts]
nemo_gym.openai_utils._require_response_output_item_type(
value: typing.Any
) -> typing.Any

Prevent an untagged output item from being coerced into the wrong union member.

nemo_gym.openai_utils._validate_atomic_token_metadata(
value: typing.Any
) -> typing.Any

Require complete token metadata when any token field is present.

nemo_gym.openai_utils.accumulate_response_usage(
total: typing.Optional[nemo_gym.openai_utils.NeMoGymResponseUsage],
additional: typing.Optional[nemo_gym.openai_utils.NeMoGymResponseUsage]
) -> typing.Optional[nemo_gym.openai_utils.NeMoGymResponseUsage]

Accumulate top-level and detailed response token counts.

nemo_gym.openai_utils.training_variant_of(
item_cls: type
) -> type

Return the ForTraining subclass that carries token IDs for item_cls.

Raises NotImplementedError rather than KeyError, so the message can name the class and the fix. Either register the pair in RESPONSES_TO_TRAIN, or stop attaching token IDs to that item.

nemo_gym.openai_utils.NeMoGymChatCompletionContentPartParam = Union[NeMoGymChatCompletionContentPartTextParam, NeMoGymChatCompletionContentPar...
nemo_gym.openai_utils.NeMoGymChatCompletionMessageParam: TypeAlias = Annotated[Union[NeMoGymChatCompletionDeveloperMessageParam, NeMoGymChatCompletio...
nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallUnion = Annotated[Union[NeMoGymChatCompletionMessageToolCall, NeMoGymChatCompletionMessa...
nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallUnionParam = Annotated[Union[NeMoGymChatCompletionMessageToolCallParam, NeMoGymChatCompletion...
nemo_gym.openai_utils.NeMoGymChatCompletionOutputMessage: TypeAlias = Annotated[Union[NeMoGymChatCompletionMessage, NeMoGymChatCompletionMessageForTra...
nemo_gym.openai_utils.NeMoGymChatCompletionToolUnionParam = Annotated[Union[NeMoGymChatCompletionToolParam, NeMoGymChatCompletionCustomToolP...
nemo_gym.openai_utils.NeMoGymContent: TypeAlias = Union[NeMoGymResponseOutputText, NeMoGymResponseOutputRefusal]
nemo_gym.openai_utils.NeMoGymResponseInput: TypeAlias = List[NeMoGymResponseInputItem]
nemo_gym.openai_utils.NeMoGymResponseInputItem = Annotated[Union[NeMoGymEasyInputMessage, NeMoGymMessage, NeMoGymResponseOutputMe...
nemo_gym.openai_utils.NeMoGymResponseOutputItem = Annotated[NeMoGymResponseInputItem, BeforeValidator(_require_response_output_ite...
nemo_gym.openai_utils.RATE_LIMIT_ERROR_CODES = [429, 502, 503, 504, 520]
nemo_gym.openai_utils.RESPONSES_TO_TRAIN = {NeMoGymEasyInputMessage: NeMoGymEasyInputMessageForTraining, NeMoGymMessage: Ne...
nemo_gym.openai_utils.RETRY_ERROR_CODES = RATE_LIMIT_ERROR_CODES + [500]
nemo_gym.openai_utils.RoutedExperts: TypeAlias = Union[str, List[List[List[int]]]]
nemo_gym.openai_utils._REQUIRED_TOKEN_METADATA_FIELDS = frozenset({'prompt_token_ids', 'generation_token_ids', 'generation_log_probs'})
nemo_gym.openai_utils._TOKEN_METADATA_FIELDS = _REQUIRED_TOKEN_METADATA_FIELDS | {'routed_experts'}