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(mixed $data)

Validate the Cohere response data.

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

Parse the Cohere response data into a single step response.

extractUsage(array $usage)

Extract usage data from a Cohere usage object.

FinishReason
extractFinishReason(string|null $finishReason)

Map a Cohere finish reason to the finish reason enum.

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 27
protected void validateTextResponse(mixed $data)

Validate the Cohere response data.

Parameters

mixed $data

Return Value

void

Exceptions

AiException

at line 40
protected StepResponse parseTextResponse(array $data, Provider $provider, string $model, bool $structured)

Parse the Cohere response data into a single step response.

Parameters

array $data
Provider $provider
string $model
bool $structured

Return Value

StepResponse

at line 80
protected TextUsage extractUsage(array $usage)

Extract usage data from a Cohere usage object.

Parameters

array $usage

Return Value

TextUsage

at line 92
protected FinishReason extractFinishReason(string|null $finishReason)

Map a Cohere finish reason to the finish reason enum.

Parameters

string|null $finishReason

Return Value

FinishReason