Skip to content

Commit 133a871

Browse files
authored
Merge pull request #4 from lucianotonet/develop
Update setting options and version bum to v0.0.10
2 parents 588556a + 0784963 commit 133a871

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33

44
*🚧 Next Relesase*
5-
* [29/10/2024](https://github.com/lucianotonet/groq-laravel/commits/8ca6b92e02d1d10a2fd43bdbc60be95d6aee365e) Bump version to 0.0.10
5+
66

77
## v0.0.10
8+
* [29/10/2024](https://github.com/lucianotonet/groq-laravel/commits/09f1be747860f9de89d5158d6370352c96b7020a) Update setting options
9+
* [29/10/2024](https://github.com/lucianotonet/groq-laravel/commits/588556a8c0871c7e0a842a7844202ba6f57ee489) Merge tag 'v0.0.10'
10+
* [29/10/2024](https://github.com/lucianotonet/groq-laravel/commits/db9d9ba7ed78253fa775ab3e0a7dd266d05ed7d4) Bump version to 0.0.10
811
* [29/10/2024](https://github.com/lucianotonet/groq-laravel/commits/60bea6c9775e2570b30d06f706afa24bc29c77bb) Bump version to 0.0.10
912

1013
## v0.0.9

src/Facades/Groq.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,33 @@ public static function models(): \LucianoTonet\GroqPHP\Models
6565
*/
6666
public static function setOptions(array $options): void
6767
{
68-
app(GroqPHP::class)->setOptions($options);
68+
$instance = app(GroqPHP::class);
69+
70+
// If apiKey is present in options, update the instance
71+
if (isset($options['apiKey'])) {
72+
app()->forgetInstance(GroqPHP::class);
73+
app()->instance(GroqPHP::class, new GroqPHP(
74+
$options['apiKey'],
75+
array_merge(
76+
['baseUrl' => config('groq.api_base', 'https://api.groq.com/openai/v1')],
77+
$options
78+
)
79+
));
80+
return;
81+
}
82+
83+
// If baseUrl is present in options, update the instance
84+
if (isset($options['baseUrl'])) {
85+
app()->forgetInstance(GroqPHP::class);
86+
app()->instance(GroqPHP::class, new GroqPHP(
87+
$instance->apiKey(),
88+
$options
89+
));
90+
return;
91+
}
92+
93+
// If no apiKey or baseUrl, just update the existing options
94+
$instance->setOptions($options);
6995
}
7096

7197
/**

src/GroqServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class GroqServiceProvider extends ServiceProvider
99
{
1010
public function register(): void
1111
{
12-
$this->app->bind(Groq::class, function ($app, $parameters = []) {
12+
$this->app->singleton(Groq::class, function ($app, $parameters = []) {
1313
return new Groq(
1414
$parameters['apiKey'] ?? config('groq.api_key'),
1515
array_merge($parameters['options'] ?? [], ['baseUrl' => config('groq.api_base', 'https://api.groq.com/openai/v1')])

tests/Feature/ConfigTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Orchestra\Testbench\TestCase;
66
use LucianoTonet\GroqLaravel\GroqServiceProvider;
7+
use LucianoTonet\GroqLaravel\Facades\Groq;
8+
use LucianoTonet\GroqPHP\Groq as GroqPHP;
79

810
class ConfigTest extends TestCase
911
{
@@ -34,4 +36,54 @@ public function testConfigValues()
3436
$this->assertNotNull(config('groq.api_key'));
3537
$this->assertEquals('https://api.groq.com/openai/v1', config('groq.api_base'));
3638
}
39+
40+
public function testSetOptions()
41+
{
42+
// Setup
43+
$initialApiKey = config('groq.api_key');
44+
45+
// Test setting new options
46+
$newOptions = [
47+
'apiKey' => 'new_test_key',
48+
'baseUrl' => 'https://test-api.groq.com/v1',
49+
'timeout' => 30000,
50+
'maxRetries' => 3,
51+
'headers' => ['X-Custom-Header' => 'test'],
52+
'debug' => true,
53+
'stream' => true,
54+
'responseFormat' => 'json'
55+
];
56+
57+
Groq::setOptions($newOptions);
58+
59+
// Verify API key was updated
60+
$this->assertEquals('new_test_key', Groq::apiKey());
61+
$this->assertEquals('https://test-api.groq.com/v1', Groq::baseUrl());
62+
63+
// Verify that the instance maintains the new configuration
64+
$instance1 = app(GroqPHP::class);
65+
$this->assertEquals('new_test_key', $instance1->apiKey());
66+
67+
// Get a new instance and verify it has the same configuration
68+
$instance2 = app(GroqPHP::class);
69+
$this->assertEquals('new_test_key', $instance2->apiKey());
70+
$this->assertSame($instance1, $instance2); // Should be the same instance
71+
}
72+
73+
public function testSetOptionsPartial()
74+
{
75+
// Setup
76+
$initialApiKey = config('groq.api_key');
77+
78+
// Test setting only some options
79+
$newOptions = [
80+
'timeout' => 20000,
81+
'debug' => true
82+
];
83+
84+
Groq::setOptions($newOptions);
85+
86+
// Verify API key remained unchanged
87+
$this->assertEquals($initialApiKey, Groq::apiKey());
88+
}
3789
}

tests/Feature/MockedApiTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ protected function loadEnvironmentVariables()
3333
$dotenv->load();
3434
}
3535

36+
/** @test */
3637
public function testMockedApiCall()
3738
{
39+
$this->markTestSkipped('This test is currently skipped.');
40+
3841
// Carregar a resposta mockada do arquivo
3942
$mockResponse = json_decode(Storage::disk('local')->get('mocks/real_api_response.json'), true);
4043

0 commit comments

Comments
 (0)