trait BuildsTextRequests

Methods

array
buildTextRequestBody(Provider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options)

Build the request body for the Anthropic Messages API.

array
applyPromptCacheBreakpoints(array $body, TextGenerationOptions|null $options)

Stamp the requested cache breakpoints onto the final request body.

void
ensureValidPromptCacheOrder(array $body, TextGenerationOptions|null $options)

Ensure longer-lived cache breakpoints precede shorter-lived breakpoints.

array
cacheControl(string|null $ttl)

Build the cache control block for the given TTL.

bool
supportsSamplingParameters(string $model)

Determine if the model accepts temperature and top_p.

array
resolveToolChoice(array|null $schema, array $tools, array $providerOptions, ToolChoice|null $toolChoice = null)

Determine the tool_choice strategy for the request.

bool
supportsNativeStructuredOutput(Provider $provider)

Determine if the provider supports native structured output via output_config.

array
buildStructuredOutputTool(array $schema)

Build the synthetic tool definition for structured output.

Details

at line 22
protected array buildTextRequestBody(Provider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options)

Build the request body for the Anthropic Messages API.

Parameters

Provider $provider
string $model
string|null $instructions
array $messages
array $tools
array|null $schema
TextGenerationOptions|null $options

Return Value

array

at line 87
protected array applyPromptCacheBreakpoints(array $body, TextGenerationOptions|null $options)

Stamp the requested cache breakpoints onto the final request body.

Parameters

array $body
TextGenerationOptions|null $options

Return Value

array

at line 118
protected void ensureValidPromptCacheOrder(array $body, TextGenerationOptions|null $options)

Ensure longer-lived cache breakpoints precede shorter-lived breakpoints.

Parameters

array $body
TextGenerationOptions|null $options

Return Value

void

at line 141
protected array cacheControl(string|null $ttl)

Build the cache control block for the given TTL.

Parameters

string|null $ttl

Return Value

array

at line 149
protected bool supportsSamplingParameters(string $model)

Determine if the model accepts temperature and top_p.

Parameters

string $model

Return Value

bool

at line 157
protected array resolveToolChoice(array|null $schema, array $tools, array $providerOptions, ToolChoice|null $toolChoice = null)

Determine the tool_choice strategy for the request.

Parameters

array|null $schema
array $tools
array $providerOptions
ToolChoice|null $toolChoice

Return Value

array

at line 192
protected bool supportsNativeStructuredOutput(Provider $provider)

Determine if the provider supports native structured output via output_config.

Parameters

Provider $provider

Return Value

bool

at line 206
protected array buildStructuredOutputTool(array $schema)

Build the synthetic tool definition for structured output.

Parameters

array $schema

Return Value

array