OpenAI.Responses.Prompt (OpenAI.Responses v0.8.4)

View Source

Helpers for composing and normalizing the input option for Responses.

These helpers are pure and return a new options map. They do not enforce any domain policy or deduplicate messages; they only help safely compose inputs and execute function outputs.

All helpers normalize :input to a list of message maps. When strings are provided (either as the whole input or individual items), they are converted to %{role: :user, content: string} messages. The :input option is never set to a single map — even a single message is wrapped in a list.

Summary

Functions

Shorthand to append a developer message.

Execute function_calls using provided functions and append the outputs.

Shorthand to append a system message.

Shorthand to append a user message.

Append message(s) to opts.input.

Prepend message(s) to opts.input.

Types

opts()

@type opts() :: map() | keyword()

Functions

add_developer(opts, content)

@spec add_developer(opts(), binary()) :: map()

Shorthand to append a developer message.

add_function_outputs(opts, function_calls, functions)

@spec add_function_outputs(opts(), [map()], map() | keyword()) :: map()

Execute function_calls using provided functions and append the outputs.

The produced messages follow the OpenAI Responses format: %{type: "function_call_output", call_id: id, output: result}

add_system(opts, content)

@spec add_system(opts(), binary()) :: map()

Shorthand to append a system message.

add_user(opts, content)

@spec add_user(opts(), binary()) :: map()

Shorthand to append a user message.

append(opts, messages)

@spec append(opts(), binary() | map() | [binary() | map()]) :: map()

Append message(s) to opts.input.

Accepts a binary, a %{role, content} map, or a list of such values. Returns a new options map with :input normalized to a list of message maps.

prepend(opts, messages)

@spec prepend(opts(), binary() | map() | [binary() | map()]) :: map()

Prepend message(s) to opts.input.

Same accepted inputs and return shape as append/2.