TypeSafeGateway
class TypeSafeGateway implements ClassificationGateway
Traits
Methods
Get the path of the endpoint that answers questions.
Answer the given questions about the state, sending image attachments as referenced assets.
Get the answering model, preferring the checkpoint a routing server such as laya-serve chose.
Map an answer to an answer object, skipping unknown answer types.
Cast the string level keys the provider returns to integers.
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 temporarily unavailable.
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.
Place the image references in the state: keyed by name into a structured state, or labeled by name in a list.
Get an HTTP client for the TypeSafe API.
Details
at line 119
protected string
classificationEndpoint()
Get the path of the endpoint that answers questions.
at line 39
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, sending image attachments as referenced assets.
at line 127
protected string
answeringModel(array $data, string $model)
Get the answering model, preferring the checkpoint a routing server such as laya-serve chose.
in
AnswersQuestions at line 89
protected array
mapQuestion(Question $question)
Map a question to the decisions wire format.
in
AnswersQuestions at line 114
protected Answer|null
mapAnswer(array $answer, Question|null $question = null)
Map an answer to an answer object, skipping unknown answer types.
in
AnswersQuestions at line 132
protected array
withIntegerKeys(array $levels)
Cast the string level keys the provider returns to integers.
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
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.
at line 151
protected array
overloadedStatusCodes()
Get the status codes that indicate a provider is temporarily unavailable.
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 72
protected array
stateWithImages(string|array $state, array $references)
Place the image references in the state: keyed by name into a structured state, or labeled by name in a list.
at line 103
protected array
mapImage(File|UploadedFile $attachment)
Map an image to a base64 System One asset.
at line 135
protected PendingRequest
client(ClassificationProvider $provider, int $timeout = 30)
Get an HTTP client for the TypeSafe API.