fix: use JSONFICATOR_OPENAI_API_KEY env var consistently

This commit is contained in:
Andrew
2026-10-08 22:22:56 +03:00
parent 325569b7a5
commit c092dbdda1
3 changed files with 6 additions and 5 deletions
+2 -2
View File
@@ -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.'
);
}
+2 -1
View File
@@ -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);
+2 -2
View File
@@ -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']);
}
}
}