class FakeTextGateway implements StepTextGateway

Properties

protected int $currentResponseIndex
protected bool $preventStrayPrompts

Methods

__construct(Closure|array $responses)

Create a text gateway with fake responses.

generateTextStep(TextProvider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options, int|null $timeout, StepContext $stepContext)

Generate text for a single step in a conversation.

generateStreamStep(string $invocationId, TextProvider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options, int|null $timeout, StepContext $stepContext)

Stream text for a single step in a conversation.

nextStep(TextProvider $provider, string $model, array $messages, array|null $schema)

Resolve the next fake response and marshal it into a step response.

toStepResponse(mixed $response, TextProvider $provider, string $model)

Convert a marshalled fake response into a step response for the generation loop.

mixed
nextResponse(TextProvider $provider, string $model, string $prompt, Collection $attachments, array|null $schema)

Get the next response instance.

mixed
marshalResponse(mixed $response, TextProvider $provider, string $model, string $prompt, Collection $attachments, array|null $schema)

Marshal the given response into a full response instance.

preventStrayPrompts(bool $prevent = true)

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

Details

at line 48
__construct(Closure|array $responses)

Create a text gateway with fake responses.

Parameters

Closure|array $responses

at line 58
StepResponse generateTextStep(TextProvider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options, int|null $timeout, StepContext $stepContext)

Generate text for a single step in a conversation.

Parameters

TextProvider $provider
string $model
string|null $instructions
array $messages
array $tools
array|null $schema
TextGenerationOptions|null $options
int|null $timeout
StepContext $stepContext

Return Value

StepResponse

at line 78
Generator generateStreamStep(string $invocationId, TextProvider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options, int|null $timeout, StepContext $stepContext)

Stream text for a single step in a conversation.

Parameters

string $invocationId
TextProvider $provider
string $model
string|null $instructions
array $messages
array $tools
array|null $schema
TextGenerationOptions|null $options
int|null $timeout
StepContext $stepContext

Return Value

Generator

at line 142
protected StepResponse nextStep(TextProvider $provider, string $model, array $messages, array|null $schema)

Resolve the next fake response and marshal it into a step response.

Parameters

TextProvider $provider
string $model
array $messages
array|null $schema

Return Value

StepResponse

at line 164
protected StepResponse toStepResponse(mixed $response, TextProvider $provider, string $model)

Convert a marshalled fake response into a step response for the generation loop.

Parameters

mixed $response
TextProvider $provider
string $model

Return Value

StepResponse

at line 215
protected mixed nextResponse(TextProvider $provider, string $model, string $prompt, Collection $attachments, array|null $schema)

Get the next response instance.

Parameters

TextProvider $provider
string $model
string $prompt
Collection $attachments
array|null $schema

Return Value

mixed

at line 237
protected mixed marshalResponse(mixed $response, TextProvider $provider, string $model, string $prompt, Collection $attachments, array|null $schema)

Marshal the given response into a full response instance.

Parameters

mixed $response
TextProvider $provider
string $model
string $prompt
Collection $attachments
array|null $schema

Return Value

mixed

at line 285
FakeTextGateway preventStrayPrompts(bool $prevent = true)

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

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

Parameters

bool $prevent

Return Value

FakeTextGateway