trait BuildsTextRequests

Methods

array
buildTextRequestBody(Provider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options)

Build the request body for the OpenAI Responses API.

array
buildContinuationBody(Provider $provider, string $model, string $continuationToken, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options = null)

Build the request body for a stateful Responses API continuation.

array
extractToolResultsInput(array $messages)

Extract the latest tool results for a stateful continuation request.

array
mergeSharedResponsesRequestOptions(array $body, array $tools, array|null $schema, TextGenerationOptions|null $options, Provider $provider)

Merge shared Responses API options onto the given request body.

string|array
mapToolChoice(ToolChoice $choice)

Map a tool choice to the OpenAI Responses tool_choice shape.

bool
isStateless(Provider $provider)

Determine if OpenAI should receive full stateless conversation history.

bool
isReasoningModel(string $model)

Determine if the model supports encrypted reasoning content.

array
buildSchemaFormat(array $schema, bool $strict)

Build the text format options for structured output.

Details

at line 21
protected array buildTextRequestBody(Provider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options)

Build the request body for the OpenAI Responses API.

Parameters

Provider $provider
string $model
string|null $instructions
array $messages
array $tools
array|null $schema
TextGenerationOptions|null $options

Return Value

array

at line 41
protected array buildContinuationBody(Provider $provider, string $model, string $continuationToken, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options = null)

Build the request body for a stateful Responses API continuation.

Parameters

Provider $provider
string $model
string $continuationToken
array $messages
array $tools
array|null $schema
TextGenerationOptions|null $options

Return Value

array

at line 62
protected array extractToolResultsInput(array $messages)

Extract the latest tool results for a stateful continuation request.

Parameters

array $messages

Return Value

array

at line 82
protected array mergeSharedResponsesRequestOptions(array $body, array $tools, array|null $schema, TextGenerationOptions|null $options, Provider $provider)

Merge shared Responses API options onto the given request body.

Parameters

array $body
array $tools
array|null $schema
TextGenerationOptions|null $options
Provider $provider

Return Value

array

at line 142
protected string|array mapToolChoice(ToolChoice $choice)

Map a tool choice to the OpenAI Responses tool_choice shape.

Parameters

ToolChoice $choice

Return Value

string|array

at line 156
protected bool isStateless(Provider $provider)

Determine if OpenAI should receive full stateless conversation history.

Parameters

Provider $provider

Return Value

bool

at line 168
protected bool isReasoningModel(string $model)

Determine if the model supports encrypted reasoning content.

Parameters

string $model

Return Value

bool

at line 180
protected array buildSchemaFormat(array $schema, bool $strict)

Build the text format options for structured output.

Parameters

array $schema
bool $strict

Return Value

array