Skip to content

Commit 25e073e

Browse files
Merge pull request #16 from designbycode/puter-ai-integration-15141914466800440140
Integrate Puter AI for Theme Generation and Metadata
2 parents 074b9be + 27d3577 commit 25e073e

8 files changed

Lines changed: 271 additions & 39 deletions

File tree

.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ PADDLE_PRICE_PRO_YEARLY=
7676
VITE_PADDLE_PRICE_PRO_MONTHLY="${PADDLE_PRICE_PRO_MONTHLY}"
7777
VITE_PADDLE_PRICE_PRO_YEARLY="${PADDLE_PRICE_PRO_YEARLY}"
7878

79-
OPENROUTER_API_KEY=
80-
OPENROUTER_MODEL=nvidia/nemotron-3-super-120b-a12b:free
79+
PUTER_AUTH_TOKEN=
80+
PUTER_MODEL=gpt-4o-mini
81+
VITE_PUTER_MODEL="${PUTER_MODEL}"

app/Services/AiService.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AiService
1010
{
1111
public function generateFullTheme(string $prompt): ?array
1212
{
13-
$apiKey = config('services.openrouter.key');
13+
$apiKey = config('services.puter.key');
1414

1515
if (! $apiKey) {
1616
return null;
@@ -42,10 +42,8 @@ public function generateFullTheme(string $prompt): ?array
4242

4343
$response = Http::withHeaders([
4444
'Authorization' => 'Bearer '.$apiKey,
45-
'HTTP-Referer' => config('app.url'),
46-
'X-Title' => config('app.name'),
47-
])->timeout(30)->post('https://openrouter.ai/api/v1/chat/completions', [
48-
'model' => config('services.openrouter.model'),
45+
])->timeout(30)->post('https://api.puter.com/puterai/openai/v1/chat/completions', [
46+
'model' => config('services.puter.model'),
4947
'messages' => [
5048
['role' => 'system', 'content' => $systemPrompt],
5149
['role' => 'user', 'content' => $prompt],
@@ -54,7 +52,7 @@ public function generateFullTheme(string $prompt): ?array
5452
]);
5553

5654
if ($response->failed()) {
57-
Log::warning('OpenRouter generateFullTheme failed', [
55+
Log::warning('Puter generateFullTheme failed', [
5856
'status' => $response->status(),
5957
'body' => $response->body(),
6058
]);
@@ -87,7 +85,7 @@ public function generateFullTheme(string $prompt): ?array
8785
*/
8886
public function generateThemeMetadata(string $name, array $colors): array
8987
{
90-
$apiKey = config('services.openrouter.key');
88+
$apiKey = config('services.puter.key');
9189

9290
if (! $apiKey) {
9391
return ['description' => null, 'tags' => []];
@@ -104,10 +102,8 @@ public function generateThemeMetadata(string $name, array $colors): array
104102

105103
$response = Http::withHeaders([
106104
'Authorization' => 'Bearer '.$apiKey,
107-
'HTTP-Referer' => config('app.url'),
108-
'X-Title' => config('app.name'),
109-
])->timeout(15)->post('https://openrouter.ai/api/v1/chat/completions', [
110-
'model' => config('services.openrouter.model'),
105+
])->timeout(15)->post('https://api.puter.com/puterai/openai/v1/chat/completions', [
106+
'model' => config('services.puter.model'),
111107
'messages' => [
112108
[
113109
'role' => 'user',
@@ -118,7 +114,7 @@ public function generateThemeMetadata(string $name, array $colors): array
118114
]);
119115

120116
if ($response->failed()) {
121-
Log::warning('OpenRouter generateThemeMetadata failed', [
117+
Log::warning('Puter generateThemeMetadata failed', [
122118
'status' => $response->status(),
123119
'body' => $response->body(),
124120
]);

config/services.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@
5151
'model' => env('OPENROUTER_MODEL', 'openrouter/free'),
5252
],
5353

54+
'puter' => [
55+
'key' => env('PUTER_AUTH_TOKEN'),
56+
'model' => env('PUTER_MODEL', 'gpt-4o-mini'),
57+
],
58+
5459
];

package-lock.json

Lines changed: 182 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@vitejs/plugin-react": "^5.2.0",
6161
"class-variance-authority": "^0.7.1",
6262
"clsx": "^2.1.1",
63+
"cmdk": "^1.1.1",
6364
"concurrently": "^9.2.1",
6465
"culori": "^4.0.2",
6566
"date-fns": "^4.1.0",

0 commit comments

Comments
 (0)