Compare commits

...
1 Commits
Author SHA1 Message Date
Wojtek bb1dc728d1 Diagnose empty AI API key configuration 2026-10-16 12:27:23 +02:00
5 changed files with 21 additions and 5 deletions
+1 -1
View File
@@ -30,6 +30,6 @@ Szkielet komponentu Joomla 6 do gromadzenia pytań testowych.
## Instalacja
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.42.6).
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.42.7).
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
@@ -0,0 +1 @@
-- No database changes required for version 1.42.7.
@@ -47,9 +47,12 @@ class ResultController extends BaseController
try {
$this->getModel('Result')->evaluateWithAi($id, $questionId);
} catch (\Throwable $error) {
$message = $error->getMessage() === 'AI_NOT_CONFIGURED'
? Text::_('COM_TESTQUESTIONS_AI_NOT_CONFIGURED')
: Text::sprintf('COM_TESTQUESTIONS_AI_ERROR', $error->getMessage());
$errorMessage = $error->getMessage();
$message = str_starts_with($errorMessage, 'AI_KEY_EMPTY|')
? 'Diagnostyka konfiguracji AI (1.42.7): ' . substr($errorMessage, strlen('AI_KEY_EMPTY|'))
: ($errorMessage === 'AI_NOT_CONFIGURED'
? Text::_('COM_TESTQUESTIONS_AI_NOT_CONFIGURED')
: Text::sprintf('COM_TESTQUESTIONS_AI_ERROR', $errorMessage));
$type = 'error';
}
@@ -93,6 +93,7 @@ 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', ''));
$componentKeyLength = mb_strlen($apiKey);
// Odczytaj zapisane parametry bezpośrednio z bazy. Dzięki temu nie użyjemy
// nieaktualnej wartości z pamięci ComponentHelper, a maska pola hasła
@@ -120,6 +121,17 @@ class ResultModel extends BaseDatabaseModel
}
}
if (trim($apiKey) === '') {
$databaseKey = is_array($storedParams) ? trim((string) ($storedParams['ai_api_key'] ?? '')) : '';
$databaseKeyLength = preg_match('/^\*+$/', $databaseKey) ? 0 : mb_strlen($databaseKey);
throw new \RuntimeException(
'AI_KEY_EMPTY|provider=' . ($provider !== '' ? $provider : '(pusty)')
. '|component_chars=' . $componentKeyLength
. '|database_chars=' . $databaseKeyLength
. '|database_params=' . (is_array($storedParams) ? 'json' : 'unreadable')
);
}
$feedback = (new AiService())->evaluate(
$provider,
$apiKey,
+1 -1
View File
@@ -4,7 +4,7 @@
<creationDate>2026-10-14</creationDate>
<author>Komponent</author>
<license>GNU General Public License version 2 or later</license>
<version>1.42.6</version>
<version>1.42.7</version>
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
<element>com_testquestions</element>
<namespace path="src">Komponent\Component\Testquestions</namespace>