Normalize AI provider validation
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user