OpenAiClassificationGateway
class OpenAiClassificationGateway implements ClassificationGateway
Traits
Methods
Create an HTTP client with the provider's request options.
Select a boot-registered connection without retaining dynamic provider names.
Execute a callback with failoverable error handling.
Get the short Retry-After delay of a rate limited or overloaded response, if it has one.
Determine if the response is a 402, or a 429 insufficient credits or quota error rather than a rate limit.
Get the status codes that indicate a provider is transiently unavailable and the request should fail over.
Get the patterns used to detect insufficient credits or quota errors.
Get the error codes or types that indicate insufficient credits or quota on a 429 response.
Resolve an attachment to an image with its content and MIME type.
Answer the given questions about the state.
Map the state and attachments to the decisions input.
Map an image to an input image part, which the decisions endpoint only accepts as an inline data URL.
Get the provider key used to resolve image attachment options.
Map a score level to a label, keeping the description of levels given as a label and description.
Get the predicate instructions, folding in the true and false criteria the endpoint has no field for.
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.
in
CreatesClient at line 43
protected string
httpConnection(Provider $provider)
Select a boot-registered connection without retaining dynamic provider names.
in
CreatesOpenAiClient at line 18
protected PendingRequest
client(Provider $provider, int|null $timeout = null)
Get an HTTP client for the OpenAI API.
in
CreatesOpenAiClient at line 31
protected string
baseUrl(Provider $provider)
Get the base URL for the OpenAI-compatible API.
in
HandlesFailoverErrors at line 26
protected mixed
withErrorHandling(string $providerName, Closure $callback)
Execute a callback with failoverable error handling.
in
HandlesFailoverErrors at line 91
protected int|null
retryAfterSeconds(Throwable $exception)
Get the short Retry-After delay of a rate limited or overloaded response, if it has one.
in
HandlesFailoverErrors at line 115
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.
in
HandlesFailoverErrors at line 138
protected array
overloadedStatusCodes()
Get the status codes that indicate a provider is transiently unavailable and the request should fail over.
in
HandlesFailoverErrors at line 148
protected array
insufficientCreditPatterns()
Get the patterns used to detect insufficient credits or quota errors.
in
HandlesFailoverErrors at line 158
protected array
insufficientCreditCodes()
Get the error codes or types that indicate insufficient credits or quota on a 429 response.
in
ResolvesInlineImages at line 25
protected array
resolveInlineImage(File|UploadedFile $attachment, string $endpoint, array $formats)
Resolve an attachment to an image with its content and MIME type.
at line 43
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.
at line 92
protected string|array
mapInput(string|array $state, array $attachments)
Map the state and attachments to the decisions input.
at line 118
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.
at line 133
protected Lab
providerOptionsKey()
Get the provider key used to resolve image attachment options.
at line 141
protected array
mapQuestion(string $name, Question $question)
Map a question to the OpenAI decisions wire format.
at line 173
protected array
mapLevel(string|array $level)
Map a score level to a label, keeping the description of levels given as a label and description.
at line 188
protected string
predicateInstructions(Boolean $question)
Get the predicate instructions, folding in the true and false criteria the endpoint has no field for.
at line 202
protected Answer|null
mapAnswer(array $answer, Question|null $question)
Map an answer to an answer object, skipping refusals and unknown answer types.
at line 224
protected string
toText(string|array $value)
Convert structured content to the text the endpoint accepts.