Normalize AI provider validation

This commit is contained in:
Wojtek
2026-10-16 12:22:38 +02:00
parent 03728ce49f
commit ed2c6b663b
4 changed files with 9 additions and 3 deletions
@@ -11,14 +11,19 @@ class AiService
public function evaluate(string $provider, string $apiKey, string $question, string $answer, string $pattern): string
{
$provider = strtolower(trim($provider));
$provider = preg_replace('/[^a-z]/', '', $provider);
$config = $provider === 'grok'
? ['url' => 'https://api.x.ai/v1/responses', 'model' => 'grok-4.7']
: ['url' => 'https://api.openai.com/v1/responses', 'model' => 'gpt-4.1-mini'];
if (!in_array($provider, ['openai', 'grok'], true) || trim($apiKey) === '') {
if (trim($apiKey) === '') {
throw new \RuntimeException('AI_NOT_CONFIGURED');
}
if (!in_array($provider, ['openai', 'grok'], true)) {
throw new \RuntimeException('Nieprawidłowy dostawca AI: ' . $provider);
}
$input = "Oceń odpowiedź ucznia na pytanie otwarte.\n\n"
. "Pytanie:\n" . $question . "\n\n"
. "Wzorzec odpowiedzi:\n" . $pattern . "\n\n"