nemo_rl.environments.nemo_gym_request#
Helpers for reading and merging NeMo Gym request metadata.
Module Contents#
Functions#
Return a copied dict from a mapping or JSON object string. |
|
Read |
|
Build processor kwargs from NeMo Gym chat-template metadata. |
|
Recursively merge two dictionaries without modifying either input. |
API#
- nemo_rl.environments.nemo_gym_request._json_mapping(
- value: Any,
- *,
- field_name: str,
Return a copied dict from a mapping or JSON object string.
.. rubric:: Example
_json_mapping('{"enabled": true}', field_name="options")returns{"enabled": True}.- Parameters:
value – Dict or JSON object string.
field_name – Field name used in errors.
- Returns:
A new dictionary.
- Raises:
TypeError – If the value is not a dict or JSON object string.
ValueError – If the string is empty or invalid JSON.
- nemo_rl.environments.nemo_gym_request._metadata_extra_body(
- nemo_gym_example: dict[str, Any],
Read
metadata.extra_bodyas a dict... rubric:: Example
An example with
metadata.extra_body='{"seed": 1}'returns{"seed": 1}.- Parameters:
nemo_gym_example – Example containing Responses API parameters.
- Returns:
Parsed
extra_body, or an empty dict when absent.- Raises:
TypeError – If request parameters or metadata are not dictionaries.
ValueError – If
extra_bodycontains invalid JSON.
- nemo_rl.environments.nemo_gym_request._chat_template_kwargs_for_processor(
- nemo_gym_example: dict[str, Any],
Build processor kwargs from NeMo Gym chat-template metadata.
.. rubric:: Example
{"chat_template_kwargs": {"enable_thinking": False}}becomes the processor kwarg with the same name and value.- Parameters:
nemo_gym_example – Example containing Responses API parameters.
- Returns:
Keyword arguments for the processor’s chat template.
- Raises:
TypeError – If request metadata has an unsupported type.
ValueError – If a JSON metadata value is empty or invalid.
- nemo_rl.environments.nemo_gym_request._deep_merge_dict(
- base: dict[str, Any],
- update: dict[str, Any],
Recursively merge two dictionaries without modifying either input.
.. rubric:: Example
Merging
{"a": {"b": 1}}with{"a": {"c": 2}}returns{"a": {"b": 1, "c": 2}}.- Parameters:
base – Initial mapping.
update – Values to merge into
base.
- Returns:
A recursively merged deep copy.