Skip to content

Commit 92252bc

Browse files
committed
Provider validation added.
1 parent ede1c2e commit 92252bc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/FineTunerServiceProvider.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace HalilCosdu\FineTuner;
44

55
use HalilCosdu\FineTuner\Commands\FineTunerCommand;
6+
use InvalidArgumentException;
67
use OpenAI;
78
use Spatie\LaravelPackageTools\Package;
89
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -25,11 +26,21 @@ public function configurePackage(Package $package): void
2526
public function packageRegistered(): void
2627
{
2728
$this->app->singleton(FineTuner::class, function ($app) {
29+
$apiKey = config('finetuner.api_key');
30+
$organization = config('finetuner.organization');
31+
$timeout = config('finetuner.request_timeout', 30);
32+
33+
if (! is_string($apiKey) || ($organization !== null && ! is_string($organization))) {
34+
throw new InvalidArgumentException(
35+
'The OpenAI API Key is missing. Please publish the [finetuner.php] configuration file and set the [api_key].'
36+
);
37+
}
38+
2839
return new FineTuner(
2940
OpenAI::factory()
30-
->withApiKey(config('finetuner.api_key'))
31-
->withOrganization(config('finetuner.organization'))
32-
->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('finetuner.request_timeout', 600)]))
41+
->withApiKey($apiKey)
42+
->withOrganization($organization)
43+
->withHttpClient(new \GuzzleHttp\Client(['timeout' => $timeout]))
3344
->make()
3445
);
3546
});

0 commit comments

Comments
 (0)