class OpenAiCompatibleClassificationGateway extends OpenAiClassificationGateway

Traits

Methods

createClient(string $baseUrl, array $headers = [], array $configuredHeaders = [], int|null $timeout = 60, bool $throw = true)

Create an HTTP client with the provider's request options.

string
httpConnection(Provider $provider)

Select a boot-registered connection without retaining dynamic provider names.

client(Provider $provider, int|null $timeout = null)

Get an HTTP client for the OpenAI API.

string
baseUrl(Provider $provider)

Get the base URL for the OpenAI-compatible API.

mixed
withErrorHandling(string $providerName, Closure $callback)

Execute a callback with failoverable error handling.

int|null
retryAfterSeconds(Throwable $exception)

Get the short Retry-After delay of a rate limited or overloaded response, if it has one.

bool
isInsufficientCredits(RequestException $exception)

Determine if the response is a 402, or a 429 insufficient credits or quota error rather than a rate limit.

array
overloadedStatusCodes()

Get the status codes that indicate a provider is transiently unavailable and the request should fail over.

array
insufficientCreditPatterns()

Get the patterns used to detect insufficient credits or quota errors.

array
insufficientCreditCodes()

Get the error codes or types that indicate insufficient credits or quota on a 429 response.

array
resolveInlineImage(File|UploadedFile $attachment, string $endpoint, array $formats)

Resolve an attachment to an image with its content and MIME type.

classify(ClassificationProvider $provider, string $model, string|array $state, array $questions, int $timeout = 30, array $providerOptions = [], array $attachments = [])

Answer the given questions about the state.

string|array
mapInput(string|array $state, array $attachments)

Map the state and attachments to the decisions input.

array
mapImage(File|UploadedFile $attachment)

Map an image to an input image part, which the decisions endpoint only accepts as an inline data URL.

Lab
providerOptionsKey()

Get the provider key used to resolve image attachment options.

array
mapQuestion(string $name, Question $question)

Map a question to the OpenAI decisions wire format.

array
mapLevel(string|array $level)

Map a score level to a label, keeping the description of levels given as a label and description.

string
predicateInstructions(Boolean $question)

Get the predicate instructions, folding in the true and false criteria the endpoint has no field for.

Answer|null
mapAnswer(array $answer, Question|null $question)

Map an answer to an answer object, skipping refusals and unknown answer types.

string
toText(string|array $value)

Convert structured content to the text the endpoint accepts.

Details

in CreatesClient at line 21
protected PendingRequest createClient(string $baseUrl, array $headers = [], array $configuredHeaders = [], int|null $timeout = 60, bool $throw = true)

Create an HTTP client with the provider's request options.

Parameters

string $baseUrl
array $headers
array $configuredHeaders
int|null $timeout
bool $throw

Return Value

PendingRequest

in CreatesClient at line 43
protected string httpConnection(Provider $provider)

Select a boot-registered connection without retaining dynamic provider names.

Parameters

Provider $provider

Return Value

string

protected PendingRequest client(Provider $provider, int|null $timeout = null)

Get an HTTP client for the OpenAI API.

Parameters

Provider $provider
int|null $timeout

Return Value

PendingRequest

protected string baseUrl(Provider $provider)

Get the base URL for the OpenAI-compatible API.

Parameters

Provider $provider

Return Value

string

protected mixed withErrorHandling(string $providerName, Closure $callback)

Execute a callback with failoverable error handling.

Parameters

string $providerName
Closure $callback

Return Value

mixed

protected int|null retryAfterSeconds(Throwable $exception)

Get the short Retry-After delay of a rate limited or overloaded response, if it has one.

Parameters

Throwable $exception

Return Value

int|null

protected bool isInsufficientCredits(RequestException $exception)

Determine if the response is a 402, or a 429 insufficient credits or quota error rather than a rate limit.

Parameters

RequestException $exception

Return Value

bool

protected array overloadedStatusCodes()

Get the status codes that indicate a provider is transiently unavailable and the request should fail over.

Return Value

array

protected array insufficientCreditPatterns()

Get the patterns used to detect insufficient credits or quota errors.

Return Value

array

protected array insufficientCreditCodes()

Get the error codes or types that indicate insufficient credits or quota on a 429 response.

Return Value

array

protected array resolveInlineImage(File|UploadedFile $attachment, string $endpoint, array $formats)

Resolve an attachment to an image with its content and MIME type.

Parameters

File|UploadedFile $attachment
string $endpoint
array $formats

Return Value

array

Exceptions

InvalidArgumentException

ClassificationResponse classify(ClassificationProvider $provider, string $model, string|array $state, array $questions, int $timeout = 30, array $providerOptions = [], array $attachments = [])

Answer the given questions about the state.

Parameters

ClassificationProvider $provider
string $model
string|array $state
array $questions
int $timeout
array $providerOptions
array $attachments

Return Value

ClassificationResponse

protected string|array mapInput(string|array $state, array $attachments)

Map the state and attachments to the decisions input.

Parameters

string|array $state
array $attachments

Return Value

string|array

protected array mapImage(File|UploadedFile $attachment)

Map an image to an input image part, which the decisions endpoint only accepts as an inline data URL.

Parameters

File|UploadedFile $attachment

Return Value

array

Exceptions

InvalidArgumentException

at line 19
protected Lab providerOptionsKey()

Get the provider key used to resolve image attachment options.

Return Value

Lab

protected array mapQuestion(string $name, Question $question)

Map a question to the OpenAI decisions wire format.

Parameters

string $name
Question $question

Return Value

array

protected array mapLevel(string|array $level)

Map a score level to a label, keeping the description of levels given as a label and description.

Parameters

string|array $level

Return Value

array

protected string predicateInstructions(Boolean $question)

Get the predicate instructions, folding in the true and false criteria the endpoint has no field for.

Parameters

Boolean $question

Return Value

string

protected Answer|null mapAnswer(array $answer, Question|null $question)

Map an answer to an answer object, skipping refusals and unknown answer types.

Parameters

array $answer
Question|null $question

Return Value

Answer|null

protected string toText(string|array $value)

Convert structured content to the text the endpoint accepts.

Parameters

string|array $value

Return Value

string