Skip to content

Commit

Permalink
Allow to customize OpenAI Model
Browse files Browse the repository at this point in the history
  • Loading branch information
arnebr authored Jul 20, 2024
1 parent f139ef7 commit e5209d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/SolutionProviders/Laravel/OpenAiSolutionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function getSolutions(Throwable $throwable): array
cacheTtlInSeconds: 60,
applicationType: 'Laravel ' . Str::before(app()->version(), '.'),
applicationPath: base_path(),
openAiModel: config('error-solutions.open_ai_model','gpt-3.5-turbo'),
);

return $solutionProvider->getSolutions($throwable);
Expand Down
8 changes: 2 additions & 6 deletions src/Solutions/OpenAi/OpenAiSolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(
protected int|null $cacheTtlInSeconds = 60,
protected string|null $applicationType = null,
protected string|null $applicationPath = null,
protected string $openAiModel,
) {
$this->prompt = $this->generatePrompt();

Expand Down Expand Up @@ -60,7 +61,7 @@ public function getAiSolution(): ?OpenAiSolutionResponse
$solutionText = OpenAI::client($this->openAiKey)
->chat()
->create([
'model' => $this->getModel(),
'model' => $this->openAiModel(),
'messages' => [['role' => 'user', 'content' => $this->prompt]],
'max_tokens' => 1000,
'temperature' => 0,
Expand Down Expand Up @@ -97,11 +98,6 @@ protected function generatePrompt(): string
);
}

protected function getModel(): string
{
return 'gpt-3.5-turbo';
}

protected function getApplicationFrame(Throwable $throwable): ?Frame
{
$backtrace = Backtrace::createForThrowable($throwable);
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/OpenAi/OpenAiSolutionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct(
protected int $cacheTtlInSeconds = 60 * 60,
protected string|null $applicationType = null,
protected string|null $applicationPath = null,
protected string $openAiModel='gpt-3.5-turbo',
) {
$this->cache ??= new DummyCache();
}
Expand All @@ -33,6 +34,7 @@ public function getSolutions(Throwable $throwable): array
$this->cacheTtlInSeconds,
$this->applicationType,
$this->applicationPath,
$this->openAiModel
),
];
}
Expand Down

0 comments on commit e5209d3

Please sign in to comment.