Skip to content

Commit 959a5cf

Browse files
committed
feat: Integrate GROQ API with configuration flexibility
Enables seamless integration with the GROQ API by introducing a service provider and a dedicated configuration file. This allows for easy interaction with the GROQ API within Laravel applications and provides developers with the flexibility to customize API settings according to their needs.
1 parent b2500a8 commit 959a5cf

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

config/groq.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* Configuration settings for the GROQ API integration.
5+
*
6+
* @return array
7+
* An array of GROQ API configuration settings.
8+
* - api_key: The API key to authenticate with the GROQ API.
9+
* - api_base: The base URL for the GROQ API endpoint.
10+
* - options: Additional options to pass to the GROQ API client.
11+
*/
12+
return [
13+
'api_key' => env('GROQ_API_KEY'),
14+
'api_base' => env('GROQ_API_BASE', 'https://api.groq.com/openai/v1'),
15+
'options' => [],
16+
];

src/GroqServiceProvider.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,46 @@
55
use Illuminate\Support\ServiceProvider;
66
use LucianoTonet\GroqPHP\Groq;
77

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+
*/
816
class GroqServiceProvider extends ServiceProvider
917
{
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
1128
{
12-
$this->app->bind(Groq::class, function ($app, $parameters) {
29+
$this->app->bind(Groq::class, function ($app, $parameters = []) {
1330
return new Groq(
1431
$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')])
1633
);
1734
});
1835
}
19-
}
2036

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

Comments
 (0)