|
5 | 5 | use Illuminate\Support\ServiceProvider;
|
6 | 6 | use LucianoTonet\GroqPHP\Groq;
|
7 | 7 |
|
| 8 | +/** |
| 9 | + * Provides the Groq service provider for the Laravel application. |
| 10 | + * |
| 11 | + * The GroqServiceProvider registers the Groq class with the application's service |
| 12 | + * container, allowing it to be resolved and used throughout the application. It |
| 13 | + * also publishes the default Groq configuration file to the application's config |
| 14 | + * directory, allowing the user to customize the configuration as needed. |
| 15 | + */ |
8 | 16 | class GroqServiceProvider extends ServiceProvider
|
9 | 17 | {
|
10 |
| - public function register() |
| 18 | + /** |
| 19 | + * Registers the Groq service with the application's service container. |
| 20 | + * |
| 21 | + * This method binds the Groq class to the service container, allowing it to be |
| 22 | + * resolved and used throughout the application. The Groq instance is configured |
| 23 | + * with the API key and base URL specified in the application's environment. |
| 24 | + * |
| 25 | + * @return void |
| 26 | + */ |
| 27 | + public function register(): void |
11 | 28 | {
|
12 |
| - $this->app->bind(Groq::class, function ($app, $parameters) { |
| 29 | + $this->app->bind(Groq::class, function ($app, $parameters = []) { |
13 | 30 | return new Groq(
|
14 | 31 | $parameters['apiKey'] ?? env('GROQ_API_KEY'),
|
15 |
| - $parameters['options'] ?? [] |
| 32 | + array_merge($parameters['options'] ?? [], ['baseUrl' => env('GROQ_API_BASE', 'https://api.groq.com/openai/v1')]) |
16 | 33 | );
|
17 | 34 | });
|
18 | 35 | }
|
19 |
| -} |
20 | 36 |
|
| 37 | + /** |
| 38 | + * Publishes the Groq configuration file to the application's config directory. |
| 39 | + * |
| 40 | + * This method is called during the package's boot process. It allows the user to |
| 41 | + * publish the default Groq configuration file to their application, so they can |
| 42 | + * customize the configuration as needed. |
| 43 | + */ |
| 44 | + public function boot(): void |
| 45 | + { |
| 46 | + $this->publishes([ |
| 47 | + __DIR__ . '/../config/groq.php' => config_path('groq.php'), |
| 48 | + ]); |
| 49 | + } |
| 50 | +} |
0 commit comments