trait ParsesTextResponses

Traits

Methods

array
decodeStructuredOutput(string|null $text)

Decode a structured output payload, tolerating markdown code fences.

static string
joinReasoning(iterable $blocks)

Join reasoning blocks, separating each block with a blank line.

void
validateTextResponse(array $data)

Validate the OpenAI response data.

parseTextResponse(array $data, Provider $provider, bool $structured)

Parse the OpenAI response data into a single step response.

string
extractText(array $output)

Extract the text content from the output array.

string
extractReasoning(array $output)

Extract the reasoning text from the output array.

extractCitations(array $output)

Extract citations from the output array.

array
extractReplayBlocks(array $output)

Extract the ordered response output for full-history replay.

array
extractProviderToolCalls(array $output)

Extract the provider-hosted tool items from the output array.

extractUsage(array $data)

Extract usage data from the response.

extractImageUsage(array $data)

Extract usage data from an image generation response.

FinishReason
extractFinishReason(array $data)

Extract and map the finish reason from the response.

array
mapToolCallsWithReasoning(array $output)

Map tool calls with their associated reasoning blocks.

Details

protected array decodeStructuredOutput(string|null $text)

Decode a structured output payload, tolerating markdown code fences.

Parameters

string|null $text

Return Value

array

in JoinsReasoning at line 16
static protected string joinReasoning(iterable $blocks)

Join reasoning blocks, separating each block with a blank line.

Parameters

iterable $blocks

Return Value

string

at line 31
protected void validateTextResponse(array $data)

Validate the OpenAI response data.

Parameters

array $data

Return Value

void

Exceptions

AiException

at line 55
protected StepResponse parseTextResponse(array $data, Provider $provider, bool $structured)

Parse the OpenAI response data into a single step response.

Parameters

array $data
Provider $provider
bool $structured

Return Value

StepResponse

at line 80
protected string extractText(array $output)

Extract the text content from the output array.

Parameters

array $output

Return Value

string

at line 102
protected string extractReasoning(array $output)

Extract the reasoning text from the output array.

Parameters

array $output

Return Value

string

at line 117
protected Collection extractCitations(array $output)

Extract citations from the output array.

Parameters

array $output

Return Value

Collection

at line 150
protected array extractReplayBlocks(array $output)

Extract the ordered response output for full-history replay.

Parameters

array $output

Return Value

array

at line 160
protected array extractProviderToolCalls(array $output)

Extract the provider-hosted tool items from the output array.

Parameters

array $output

Return Value

array

at line 173
protected TextUsage extractUsage(array $data)

Extract usage data from the response.

Parameters

array $data

Return Value

TextUsage

at line 189
protected ImageUsage extractImageUsage(array $data)

Extract usage data from an image generation response.

Parameters

array $data

Return Value

ImageUsage

at line 205
protected FinishReason extractFinishReason(array $data)

Extract and map the finish reason from the response.

Parameters

array $data

Return Value

FinishReason

at line 237
protected array mapToolCallsWithReasoning(array $output)

Map tool calls with their associated reasoning blocks.

Parameters

array $output

Return Value

array