class FakeClassificationGateway implements ClassificationGateway

Properties

protected int $currentResponseIndex
protected bool $preventStrayClassifications

Methods

__construct(Closure|array $responses = [])

Create a classification gateway with fake responses.

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

Answer the given questions about the state.

nextResponse(ClassificationProvider $provider, string $model, ClassificationPrompt $prompt)

Get the next response instance.

marshalResponse(mixed $response, ClassificationProvider $provider, string $model, ClassificationPrompt $prompt)

Marshal the given response into a full response instance.

generateFakeAnswer(Question $question)

Generate a shape-valid fake answer for the given question.

fakeChoiceAnswer(array $options)

Generate a fake choice answer.

fakeScoreAnswer(array $levels)

Generate a fake score answer.

array
randomDistribution(array $keys)

Generate random probabilities summing to one over the given keys.

preventStrayClassifications(bool $prevent = true)

Indicate that an exception should be thrown if any classification is not faked.

Details

at line 36
__construct(Closure|array $responses = [])

Create a classification gateway with fake responses.

Parameters

Closure|array $responses

at line 49
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

at line 66
protected ClassificationResponse nextResponse(ClassificationProvider $provider, string $model, ClassificationPrompt $prompt)

Get the next response instance.

Parameters

ClassificationProvider $provider
string $model
ClassificationPrompt $prompt

Return Value

ClassificationResponse

at line 89
protected ClassificationResponse marshalResponse(mixed $response, ClassificationProvider $provider, string $model, ClassificationPrompt $prompt)

Marshal the given response into a full response instance.

Parameters

mixed $response
ClassificationProvider $provider
string $model
ClassificationPrompt $prompt

Return Value

ClassificationResponse

at line 129
protected Answer generateFakeAnswer(Question $question)

Generate a shape-valid fake answer for the given question.

Parameters

Question $question

Return Value

Answer

Exceptions

RuntimeException

at line 144
protected ChoiceAnswer fakeChoiceAnswer(array $options)

Generate a fake choice answer.

Parameters

array $options

Return Value

ChoiceAnswer

at line 160
protected ScoreAnswer fakeScoreAnswer(array $levels)

Generate a fake score answer.

Parameters

array $levels

Return Value

ScoreAnswer

at line 175
protected array randomDistribution(array $keys)

Generate random probabilities summing to one over the given keys.

Parameters

array $keys

Return Value

array

at line 190
FakeClassificationGateway preventStrayClassifications(bool $prevent = true)

Indicate that an exception should be thrown if any classification is not faked.

When the shared manager holds this fake gateway, the setting affects every request in the worker.

Parameters

bool $prevent

Return Value

FakeClassificationGateway