ParsesTextResponses
trait ParsesTextResponses
Traits
Methods
Decode a structured output payload, tolerating markdown code fences.
Join reasoning blocks, separating each block with a blank line.
Validate the xAI response data.
Parse a single xAI response into a StepResponse.
Extract the text content from the output array.
Extract citations from the output array.
Extract the provider-hosted tool items from the output array.
Extract usage data from the response.
Extract and map the finish reason from the xAI response.
Extract the reasoning text from the output array.
Map tool calls with their associated reasoning blocks.
Details
in
DecodesStructuredOutput at line 12
protected array
decodeStructuredOutput(string|null $text)
Decode a structured output payload, tolerating markdown code fences.
in
JoinsReasoning at line 16
static protected string
joinReasoning(iterable $blocks)
Join reasoning blocks, separating each block with a blank line.
at line 30
protected void
validateTextResponse(array $data)
Validate the xAI response data.
at line 54
protected StepResponse
parseTextResponse(array $data, Provider $provider, bool $structured)
Parse a single xAI response into a StepResponse.
at line 85
protected string
extractText(array $output)
Extract the text content from the output array.
at line 107
protected Collection
extractCitations(array $output)
Extract citations from the output array.
at line 138
protected array
extractProviderToolCalls(array $output)
Extract the provider-hosted tool items from the output array.
at line 151
protected TextUsage
extractUsage(array $data)
Extract usage data from the response.
at line 167
protected FinishReason
extractFinishReason(array $data)
Extract and map the finish reason from the xAI response.
at line 196
protected string
extractReasoning(array $output)
Extract the reasoning text from the output array.
at line 213
protected array
mapToolCallsWithReasoning(array $output)
Map tool calls with their associated reasoning blocks.