mirror of
https://github.com/Geckon01/JsonFicatorPHP.git
synced 2026-10-13 23:15:12 +00:00
fix: use JSONFICATOR_OPENAI_API_KEY env var consistently
This commit is contained in:
@@ -54,11 +54,11 @@ final class OpenAIProvider implements LLMProviderInterface
|
||||
array $config = [],
|
||||
) {
|
||||
$host = $config['host'] ?? 'https://api.openai.com/v1';
|
||||
$key = $config['key'] ?? ($_SERVER['OPENAI_API_KEY'] ?? null);
|
||||
$key = $config['key'] ?? ($_SERVER['JSONFICATOR_OPENAI_API_KEY'] ?? $_ENV['JSONFICATOR_OPENAI_API_KEY'] ?? null);
|
||||
|
||||
if ($key === null || $key === '') {
|
||||
throw new ProviderException(
|
||||
'OpenAI API key is required. Provide it via the "key" config option or the OPENAI_API_KEY environment variable.'
|
||||
'OpenAI API key is required. Provide it via the "key" config option or the JSONFICATOR_OPENAI_API_KEY environment variable.'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,9 @@ final class OpenAIIntegrationTest extends TestCase
|
||||
public function testToJsonExtractsData(): void
|
||||
{
|
||||
$provider = new OpenAIProvider([
|
||||
'host' => 'https://llm.geckon01.ru',
|
||||
'key' => self::$apiKey,
|
||||
'model' => 'gpt-4o-mini',
|
||||
'model' => 'gemma4:latest',
|
||||
]);
|
||||
|
||||
$jsonFicator = new JsonFicator($provider);
|
||||
|
||||
@@ -39,13 +39,13 @@ final class OpenAIProviderTest extends TestCase
|
||||
|
||||
public function testAcceptsApiKeyFromEnvironment(): void
|
||||
{
|
||||
$_SERVER['OPENAI_API_KEY'] = 'sk-env';
|
||||
$_SERVER['JSONFICATOR_OPENAI_API_KEY'] = 'sk-env';
|
||||
|
||||
try {
|
||||
$provider = new OpenAIProvider();
|
||||
$this->assertInstanceOf(OpenAIProvider::class, $provider);
|
||||
} finally {
|
||||
unset($_SERVER['OPENAI_API_KEY']);
|
||||
unset($_SERVER['JSONFICATOR_OPENAI_API_KEY']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user