Skip to content

Commit

Permalink
Provider validation added.
Browse files Browse the repository at this point in the history
  • Loading branch information
halilcosdu committed Apr 23, 2024
1 parent ede1c2e commit 92252bc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/FineTunerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace HalilCosdu\FineTuner;

use HalilCosdu\FineTuner\Commands\FineTunerCommand;
use InvalidArgumentException;
use OpenAI;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand All @@ -25,11 +26,21 @@ public function configurePackage(Package $package): void
public function packageRegistered(): void
{
$this->app->singleton(FineTuner::class, function ($app) {
$apiKey = config('finetuner.api_key');
$organization = config('finetuner.organization');
$timeout = config('finetuner.request_timeout', 30);

if (! is_string($apiKey) || ($organization !== null && ! is_string($organization))) {
throw new InvalidArgumentException(
'The OpenAI API Key is missing. Please publish the [finetuner.php] configuration file and set the [api_key].'
);
}

return new FineTuner(
OpenAI::factory()
->withApiKey(config('finetuner.api_key'))
->withOrganization(config('finetuner.organization'))
->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('finetuner.request_timeout', 600)]))
->withApiKey($apiKey)
->withOrganization($organization)
->withHttpClient(new \GuzzleHttp\Client(['timeout' => $timeout]))
->make()
);
});
Expand Down

0 comments on commit 92252bc

Please sign in to comment.