AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

FakeDriver.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 = match ($request->task) {
  25. 'edit' => ['reply' => 'Fake AI: I made the main colour darker.', 'theme' => ['colors' => ['primary' => '#3B2A20']]],
  26. 'pulse' => ['summary' => 'Fake AI: sales are steady this month. Ship your waiting orders first, then check your stock.'],
  27. 'logo' => ['logos' => [
  28. ['svg' => '<svg viewBox="0 0 400 100"><circle cx="50" cy="50" r="34" fill="#1F3D32"/><text x="100" y="64" font-size="40">Fake Logo</text></svg>'],
  29. ['svg' => '<svg viewBox="0 0 400 100"><rect x="8" y="16" width="68" height="68" rx="12" fill="#9CC5C0"/><text x="96" y="64" font-size="40">Fake Logo</text></svg>'],
  30. ['svg' => '<svg viewBox="0 0 400 100"><text x="10" y="64" font-size="44" font-weight="700">Fake Logo</text><rect x="10" y="76" width="120" height="4" fill="#1F3D32"/></svg>'],
  31. ]],
  32. default => SamplePlan::forName($this->storeName($request->prompt)),
  33. };
  34. return new AiResponse(
  35. text: (string) json_encode($answer),
  36. provider: $this->provider,
  37. model: $request->model,
  38. inputTokens: 0,
  39. outputTokens: 0,
  40. );
  41. }
  42. private function storeName(string $prompt): string
  43. {
  44. return preg_match('/^Store name: (.+)$/m', $prompt, $match) === 1 ? trim($match[1]) : 'Sample Store';
  45. }
  46. }