Skip to content

Commit d170cd0

Browse files
authored
Fix & improve error AI solutions (#628)
1 parent 41075a2 commit d170cd0

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

config/restify.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,15 @@
164164
|
165165
| By default this feature is enabled, but you still have to extend the Exception handler with the Restify one and set the API key.
166166
*/
167-
'ai_solutions' => true,
167+
'ai_solutions' => [
168+
/*
169+
| Specify the OpenAI model to use.
170+
*/
171+
'model' => 'gpt-4.1-mini',
172+
173+
/*
174+
| Specify the OpenAI temperature to use.
175+
*/
176+
'max_tokens' => 1000,
177+
],
168178
];

src/Commands/SetupCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public function handle()
3030
'--tag' => 'restify-migrations',
3131
]);
3232

33+
$this->comment('Publishing Restify views...');
34+
$this->call('vendor:publish', [
35+
'--tag' => 'restify-views',
36+
]);
37+
3338
$this->registerRestifyServiceProvider();
3439

3540
$this->comment('Generating User Repository...');

src/Exceptions/Solutions/OpenAiSolution.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ public function __construct(protected Throwable $throwable)
1616
{
1717
$this->solution = Cache::remember('restify-solution-'.sha1($this->throwable->getTraceAsString()),
1818
now()->addHour(),
19-
fn () => OpenAI::completions()->create([
20-
'model' => 'text-davinci-003',
21-
'prompt' => $this->generatePrompt($this->throwable),
22-
'max_tokens' => 100,
19+
fn () => OpenAI::chat()->create([
20+
'model' => config('restify.ai_solutions.model', 'gpt-4.1-mini'),
21+
'messages' =>
22+
[
23+
[
24+
'role' => 'user',
25+
'content' => $this->generatePrompt($this->throwable),
26+
],
27+
[
28+
'role' => 'system',
29+
'content' => 'Provide a concise solution to the problem described, tailored for a Laravel application using the Restify framework. Avoid explanations, examples, or code snippets. Respond with only the direct answer.',
30+
],
31+
],
32+
'max_tokens' => config('restify.ai_solutions.max_tokens', 1000),
2333
'temperature' => 0,
24-
])->choices[0]->text
34+
])->choices[0]->message->content
2535
);
2636
}
2737

src/LaravelRestifyServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,9 @@ protected function registerPublishing(): void
7171
$this->publishes([
7272
__DIR__.'/Commands/stubs/RestifyServiceProvider.stub' => app_path('Providers/RestifyServiceProvider.php'),
7373
], 'restify-provider');
74+
75+
$this->publishes([
76+
__DIR__.'/../resources/views' => resource_path('views/vendor/restify'),
77+
], 'restify-views');
7478
}
7579
}

0 commit comments

Comments
 (0)