Skip to content

Commit

Permalink
test: specific API key scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
badasswp committed Feb 5, 2025
1 parent e039583 commit de36a1d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/OpenAiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,29 @@
$this->assertStringContainsString('"object": "list"', $steps);
$this->assertStringContainsString('data', $steps);
})->group('working');

$open_ai_with_unset_api_key = new OpenAi();

it('should throw error when API key is not set', function () use ($open_ai_with_unset_api_key) {
expect(fn () => $open_ai_with_unset_api_key->completion([
'prompt' => "Hello",
'temperature' => 0.9,
"max_tokens" => 150,
"frequency_penalty" => 0,
"presence_penalty" => 0.6,
]))->toThrow(Exception::class, 'Please provide an API key.');
})->group('api-keys');

$open_ai_with_set_api_key = (new OpenAi())->setApiKey(getenv('OPENAI_API_KEY'));

it('should handle simple completion with API key set', function () use ($open_ai_with_set_api_key) {
$result = $open_ai_with_set_api_key->completion([
'prompt' => "Hello",
'temperature' => 0.9,
"max_tokens" => 150,
"frequency_penalty" => 0,
"presence_penalty" => 0.6,
]);

$this->assertStringContainsString('text', $result);
})->group('api-keys');

0 comments on commit de36a1d

Please sign in to comment.