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

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

Parse a single xAI response into a StepResponse.

string
extractText(array $output)

Extract the text content from the output array.

extractCitations(array $output)

Extract citations from the output array.

array
extractProviderToolCalls(array $output)

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

extractUsage(array $data)

Extract usage data from the response.

FinishReason
extractFinishReason(array $data)

Extract and map the finish reason from the xAI response.

string
extractReasoning(array $output)

Extract the reasoning text from the output array.

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

Validate the xAI response data.

Parameters

array $data

Return Value

void

Exceptions

AiException

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

Parse a single xAI response into a StepResponse.

Parameters

array $data
Provider $provider
bool $structured

Return Value

StepResponse

at line 85
protected string extractText(array $output)

Extract the text content from the output array.

Parameters

array $output

Return Value

string

at line 107
protected Collection extractCitations(array $output)

Extract citations from the output array.

Parameters

array $output

Return Value

Collection

at line 138
protected array extractProviderToolCalls(array $output)

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

Parameters

array $output

Return Value

array

at line 151
protected TextUsage extractUsage(array $data)

Extract usage data from the response.

Parameters

array $data

Return Value

TextUsage

at line 167
protected FinishReason extractFinishReason(array $data)

Extract and map the finish reason from the xAI response.

Parameters

array $data

Return Value

FinishReason

at line 196
protected string extractReasoning(array $output)

Extract the reasoning text from the output array.

Parameters

array $output

Return Value

string

at line 213
protected array mapToolCallsWithReasoning(array $output)

Map tool calls with their associated reasoning blocks.

Parameters

array $output

Return Value

array