AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FakeDriver.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Ai\Drivers;
  3. use App\Ai\AiDriver;
  4. use App\Ai\AiRequest;
  5. use App\Ai\AiResponse;
  6. use App\StorePlan\SamplePlan;
  7. use Illuminate\Support\Sleep;
  8. /**
  9. * A stand-in that needs no API key and costs nothing.
  10. * It answers "generate" with the built-in sample design and "edit" with one small colour change.
  11. */
  12. final class FakeDriver implements AiDriver
  13. {
  14. /**
  15. * @param array<string, mixed> $config
  16. */
  17. public function __construct(
  18. private readonly string $provider,
  19. private readonly array $config,
  20. ) {}
  21. public function complete(AiRequest $request): AiResponse
  22. {
  23. Sleep::for((int) ($this->config['delay'] ?? 0))->seconds();
  24. $answer = $request->task === 'edit'
  25. ? ['reply' => 'Fake AI: I made the main colour darker.', 'theme' => ['colors' => ['primary' => '#3B2A20']]]
  26. : SamplePlan::forName($this->storeName($request->prompt));
  27. return new AiResponse(
  28. text: (string) json_encode($answer),
  29. provider: $this->provider,
  30. model: $request->model,
  31. inputTokens: 0,
  32. outputTokens: 0,
  33. );
  34. }
  35. private function storeName(string $prompt): string
  36. {
  37. return preg_match('/^Store name: (.+)$/m', $prompt, $match) === 1 ? trim($match[1]) : 'Sample Store';
  38. }
  39. }