Read saved AI component parameters
This commit is contained in:
@@ -91,9 +91,31 @@ class ResultModel extends BaseDatabaseModel
|
||||
}
|
||||
|
||||
$params = ComponentHelper::getParams('com_testquestions');
|
||||
$provider = trim((string) $params->get('ai_provider', 'openai'));
|
||||
$apiKey = trim((string) $params->get('ai_api_key', ''));
|
||||
|
||||
// Pole typu password może zwrócić zamaskowaną wartość zamiast pustej.
|
||||
// W takim przypadku odczytaj rzeczywiste parametry bezpośrednio z rekordu rozszerzenia.
|
||||
if ($apiKey === '' || preg_match('/^\*+$/', $apiKey)) {
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$storedParams = (string) $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select($db->quoteName('params'))
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
|
||||
->where($db->quoteName('element') . ' = ' . $db->quote('com_testquestions'))
|
||||
)->loadResult();
|
||||
$storedParams = json_decode($storedParams, true);
|
||||
|
||||
if (is_array($storedParams)) {
|
||||
$provider = trim((string) ($storedParams['ai_provider'] ?? $provider));
|
||||
$apiKey = trim((string) ($storedParams['ai_api_key'] ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
$feedback = (new AiService())->evaluate(
|
||||
(string) $params->get('ai_provider', 'openai'),
|
||||
(string) $params->get('ai_api_key', ''),
|
||||
$provider,
|
||||
$apiKey,
|
||||
strip_tags((string) $question->question),
|
||||
(string) ($answer['selected'] ?? ''),
|
||||
(string) $question->answer_open
|
||||
|
||||
Reference in New Issue
Block a user