$config
*/
public function __construct(
private readonly string $provider,
private readonly array $config,
) {}
public function complete(AiRequest $request): AiResponse
{
Sleep::for((int) ($this->config['delay'] ?? 0))->seconds();
$answer = match ($request->task) {
'edit' => ['reply' => 'Fake AI: I made the main colour darker.', 'theme' => ['colors' => ['primary' => '#3B2A20']]],
'pulse' => ['summary' => 'Fake AI: sales are steady this month. Ship your waiting orders first, then check your stock.'],
'logo' => ['logos' => [
['svg' => ''],
['svg' => ''],
['svg' => ''],
]],
default => SamplePlan::forName($this->storeName($request->prompt)),
};
return new AiResponse(
text: (string) json_encode($answer),
provider: $this->provider,
model: $request->model,
inputTokens: 0,
outputTokens: 0,
);
}
private function storeName(string $prompt): string
{
return preg_match('/^Store name: (.+)$/m', $prompt, $match) === 1 ? trim($match[1]) : 'Sample Store';
}
}