Skip to content

Commit cb18e86

Browse files
committed
Added OpenAI client dependency and fixed facade loading
1 parent 91283dc commit cb18e86

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

config/aiemail.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return [
4+
'demo_mode' => env('AIEMAIL_DEMO', false),
45
'provider' => env('AI_EMAIL_PROVIDER', 'openai'),
56
'openai_key' => env('OPENAI_API_KEY'),
67

src/Services/AIEmailGenerator.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,22 @@ public function __construct(AIClientInterface $client, array $config = [])
1717

1818
public function generate(string $templateName, array $details = [], array $options = []): array
1919
{
20+
// ✅ 1. Check for demo mode (set via config or .env)
21+
if (config('aiemail.demo_mode', false)) {
22+
return [
23+
'subject' => 'Welcome to ' . ($details['company_name'] ?? 'Our Company'),
24+
'body' => "Hi " . ($details['customer_name'] ?? 'there') . ",\n\n" .
25+
"We're excited to have you try our " . ($details['product'] ?? 'AI Email Assistant') . "!\n" .
26+
"This is a sample email generated in demo mode.\n\n" .
27+
"Cheers,\nThe " . ($details['company_name'] ?? 'OM Diaries') . " Team"
28+
];
29+
}
30+
31+
// 🧠 2. Proceed normally with real API call
2032
$template = \OmDiaries\AIEmailAssistant\Support\PromptTemplates::get($templateName);
2133
$prompt = $this->buildPrompt($template, $details, $options);
2234
$result = $this->client->complete($prompt, array_merge($this->config['default_options'] ?? [], $options));
35+
2336
$parts = preg_split('/\r?\n\r?\n|###/', trim($result), 2);
2437

2538
return [
@@ -40,4 +53,4 @@ protected function buildPrompt(string $template, array $details = [], array $opt
4053
}
4154
return $prompt;
4255
}
43-
}
56+
}

0 commit comments

Comments
 (0)