ReqLLM.Providers.OpenAI.AdapterHelpers (ReqLLM v1.12.0)

View Source

Shared helper functions for OpenAI-compatible model adapters (Azure, etc.).

These functions handle OpenAI-specific request formatting that is shared across providers hosting OpenAI models.

Summary

Functions

Adds parallel_tool_calls option to the request body.

Adds response_format to the request body with schema normalization.

Adds strict mode settings to tools that have strict: true on their function.

Adds appropriate token limit parameters based on model type.

Checks if model is a Codex model (codex-mini, gpt-5-codex, etc.).

Checks if model is a DeepSeek model.

Ensures all properties in a function's parameters schema are required.

Checks if model is a GPT-4o family model.

Checks if model is a GPT-5 reasoning model (excludes gpt-5-chat-latest).

Checks if model is a GPT-4.1 model.

Checks if model is an o-series reasoning model (o1, o3, o4).

Checks if a model ID corresponds to an OpenAI reasoning model.

Checks if a model ID should default to the Responses API.

Translates ReqLLM's tool_choice format to OpenAI's function format.

Functions

add_parallel_tool_calls(body, opts, provider_opts)

@spec add_parallel_tool_calls(map(), keyword(), keyword()) :: map()

Adds parallel_tool_calls option to the request body.

Checks multiple option sources for the value:

  • opts[:parallel_tool_calls]
  • provider_opts[:openai_parallel_tool_calls]
  • provider_opts[:parallel_tool_calls]

add_response_format(body, provider_opts)

@spec add_response_format(
  map(),
  keyword()
) :: map()

Adds response_format to the request body with schema normalization.

Handles json_schema response formats by converting ReqLLM schema DSL to JSON Schema format. Supports both atom and string key maps.

add_strict_to_tools(body)

@spec add_strict_to_tools(map()) :: map()

Adds strict mode settings to tools that have strict: true on their function.

For tools with strict mode enabled:

  • Sets additionalProperties: false on the parameters schema
  • Makes all properties required

add_token_limits(body, model_id, opts)

@spec add_token_limits(map(), String.t(), keyword()) :: map()

Adds appropriate token limit parameters based on model type.

For reasoning models (o1, o3, o4, gpt-4.1, gpt-5):

  • Uses max_completion_tokens instead of max_tokens
  • Falls back to max_tokens value if max_completion_tokens not specified

For standard models:

  • Uses max_tokens and optionally max_completion_tokens

Cleans up any existing token limit keys to ensure consistent state.

codex_model?(model_id)

@spec codex_model?(term()) :: boolean()

Checks if model is a Codex model (codex-mini, gpt-5-codex, etc.).

deepseek_model?(arg1)

@spec deepseek_model?(term()) :: boolean()

Checks if model is a DeepSeek model.

ensure_all_properties_required(function)

@spec ensure_all_properties_required(map()) :: map()

Ensures all properties in a function's parameters schema are required.

Also sets additionalProperties: false for strict JSON schema compliance.

gpt4o_model?(arg1)

@spec gpt4o_model?(term()) :: boolean()

Checks if model is a GPT-4o family model.

gpt5_model?(arg1)

@spec gpt5_model?(term()) :: boolean()

Checks if model is a GPT-5 reasoning model (excludes gpt-5-chat-latest).

gpt41_model?(arg1)

@spec gpt41_model?(term()) :: boolean()

Checks if model is a GPT-4.1 model.

o_series_model?(arg1)

@spec o_series_model?(term()) :: boolean()

Checks if model is an o-series reasoning model (o1, o3, o4).

reasoning_model?(model_id)

@spec reasoning_model?(term()) :: boolean()

Checks if a model ID corresponds to an OpenAI reasoning model.

Reasoning models (o-series, gpt-4.1, gpt-5, codex) require special handling:

  • Use max_completion_tokens instead of max_tokens
  • Support reasoning_effort parameter

Note: gpt-5-chat-latest is a non-reasoning variant that uses standard conventions.

responses_model?(model_id)

@spec responses_model?(term()) :: boolean()

Checks if a model ID should default to the Responses API.

This includes reasoning/codex families plus GPT-4o models, which support Responses even when older metadata has not been updated yet.

translate_tool_choice_format(body)

@spec translate_tool_choice_format(map()) :: map()

Translates ReqLLM's tool_choice format to OpenAI's function format.

ReqLLM uses %{type: "tool", name: "tool_name"} for specific tool selection. OpenAI requires %{type: "function", function: %{name: "tool_name"}}.

Handles both atom and string key maps.