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 OpenRouter response data.

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

Parse the OpenRouter response data into a single step response.

string
extractReasoning(array $message)

Extract the reasoning text from an assistant message.

array
extractReasoningDetails(array $message)

Extract the reasoning details to replay with the message's tool calls.

extractCitations(array $message)

Extract URL citations from the message annotations array.

extractUsage(array $data)

Extract usage data from the response.

FinishReason
extractFinishReason(array $choice)

Extract and map the finish reason from the response.

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 32
protected void validateTextResponse(array $data)

Validate the OpenRouter response data.

Parameters

array $data

Return Value

void

Exceptions

AiException

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

Parse the OpenRouter response data into a single step response.

Parameters

array $data
Provider $provider
bool $structured

Return Value

StepResponse

at line 99
protected string extractReasoning(array $message)

Extract the reasoning text from an assistant message.

Parameters

array $message

Return Value

string

at line 116
protected array extractReasoningDetails(array $message)

Extract the reasoning details to replay with the message's tool calls.

Parameters

array $message

Return Value

array

at line 126
protected Collection extractCitations(array $message)

Extract URL citations from the message annotations array.

Parameters

array $message

Return Value

Collection

at line 149
protected TextUsage extractUsage(array $data)

Extract usage data from the response.

Parameters

array $data

Return Value

TextUsage

at line 165
protected FinishReason extractFinishReason(array $choice)

Extract and map the finish reason from the response.

Parameters

array $choice

Return Value

FinishReason