class TypeSafeGateway implements ClassificationGateway

Traits

Methods

string
classificationEndpoint()

Get the path of the endpoint that answers questions.

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.

string
answeringModel(array $data, string $model)

Get the answering model, preferring the checkpoint a routing server such as laya-serve chose.

array
mapQuestion(Question $question)

Map a question to the decisions wire format.

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

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

array
withIntegerKeys(array $levels)

Cast the string level keys the provider returns to integers.

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.

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 temporarily unavailable.

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.

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.

array
mapImage(File|UploadedFile $attachment)

Map an image to a base64 System One asset.

client(ClassificationProvider $provider, int $timeout = 30)

Get an HTTP client for the TypeSafe API.

Details

at line 119
protected string classificationEndpoint()

Get the path of the endpoint that answers questions.

Return Value

string

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.

Parameters

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

Return Value

ClassificationResponse

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.

Parameters

array $data
string $model

Return Value

string

in AnswersQuestions at line 89
protected array mapQuestion(Question $question)

Map a question to the decisions wire format.

Parameters

Question $question

Return Value

array

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.

Parameters

array $answer
Question|null $question

Return Value

Answer|null

in AnswersQuestions at line 132
protected array withIntegerKeys(array $levels)

Cast the string level keys the provider returns to integers.

Parameters

array $levels

Return Value

array

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 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

at line 151
protected array overloadedStatusCodes()

Get the status codes that indicate a provider is temporarily unavailable.

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

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.

Parameters

string|array $state
array $references

Return Value

array

Exceptions

InvalidArgumentException

at line 103
protected array mapImage(File|UploadedFile $attachment)

Map an image to a base64 System One asset.

Parameters

File|UploadedFile $attachment

Return Value

array

Exceptions

InvalidArgumentException

at line 135
protected PendingRequest client(ClassificationProvider $provider, int $timeout = 30)

Get an HTTP client for the TypeSafe API.

Parameters

ClassificationProvider $provider
int $timeout

Return Value

PendingRequest