ParsesTextResponses
trait ParsesTextResponses
Traits
Constants
| private REQUEST_STEP_TYPES |
The step types Gemini derives from our own request rather than the model's turn. |
Methods
Decode a structured output payload, tolerating markdown code fences.
Join reasoning blocks, separating each block with a blank line.
Validate the Gemini response data.
Parse the Gemini response data into a single step response.
Get the steps that must be replayed verbatim on the next request.
Extract the provider-executed tool steps, such as search and code execution.
Determine if the given step was executed by Gemini rather than by us.
Determine if a step carries the model's reasoning.
Extract the reasoning text from the response steps.
Extract the answer text from the model output steps.
Concatenate the text blocks of the given step, which thought steps carry as a summary.
Extract the steps carrying function calls.
Map function call steps to ToolCall DTOs.
Get the signature of the turn's last thought step, which the next request must replay beside its calls.
Normalize function call arguments, which stream as a partial JSON string.
Extract citations from the annotations Gemini attaches to its text blocks.
Extract usage data from the response.
Extract usage data from an image generation response.
Get the token count Gemini reported for the given modality.
Extract and map the finish reason from the Gemini response.
Determine if the interaction failed because Gemini withheld the content.
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 37
protected void
validateTextResponse(array $data)
Validate the Gemini response data.
at line 62
protected StepResponse
parseTextResponse(array $data, Provider $provider, string $model, bool $structured)
Parse the Gemini response data into a single step response.
at line 89
protected array
replayableSteps(array $steps)
Get the steps that must be replayed verbatim on the next request.
at line 102
protected array
extractProviderToolCalls(array $steps)
Extract the provider-executed tool steps, such as search and code execution.
at line 117
protected bool
isProviderToolStep(array $step)
Determine if the given step was executed by Gemini rather than by us.
at line 128
protected bool
isThinkingStep(array $step)
Determine if a step carries the model's reasoning.
at line 136
protected string
extractReasoning(array $steps)
Extract the reasoning text from the response steps.
at line 147
protected string
extractText(array $steps)
Extract the answer text from the model output steps.
at line 158
protected string
textOf(array $step)
Concatenate the text blocks of the given step, which thought steps carry as a summary.
at line 172
protected array
extractFunctionCallSteps(array $steps)
Extract the steps carrying function calls.
at line 184
protected array
mapToolCalls(array $functionCallSteps, string|null $thoughtSignature = null)
Map function call steps to ToolCall DTOs.
at line 202
protected string|null
thoughtSignature(array $steps)
Get the signature of the turn's last thought step, which the next request must replay beside its calls.
at line 215
protected array
decodeArguments(mixed $arguments)
Normalize function call arguments, which stream as a partial JSON string.
at line 229
protected Collection
extractCitations(array $steps)
Extract citations from the annotations Gemini attaches to its text blocks.
at line 256
protected TextUsage
extractUsage(array $data)
Extract usage data from the response.
at line 274
protected ImageUsage
extractImageUsage(array $data)
Extract usage data from an image generation response.
at line 294
protected int|null
modalityTokens(array $details, string $modality)
Get the token count Gemini reported for the given modality.
at line 308
protected FinishReason
extractFinishReason(array $data, array $functionCallSteps)
Extract and map the finish reason from the Gemini response.
at line 332
protected bool
wasBlocked(array $errors)
Determine if the interaction failed because Gemini withheld the content.