Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb1dc728d1 | ||
|
|
ed2c6b663b | ||
|
|
03728ce49f | ||
|
|
a7637aedcc | ||
|
|
7f4f86080a | ||
|
|
9e940c5710 |
@@ -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.1).
|
||||
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**.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<option value="openai">OpenAI</option>
|
||||
<option value="grok">Grok</option>
|
||||
</field>
|
||||
<field name="ai_api_key" type="password" label="COM_TESTQUESTIONS_AI_API_KEY" filter="raw" autocomplete="off" />
|
||||
<field name="ai_api_key" type="aiapikey" addfieldprefix="Komponent\Component\Testquestions\Administrator\Field" label="COM_TESTQUESTIONS_AI_API_KEY" filter="raw" autocomplete="off" size="120" class="w-100" />
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.2.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.3.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.4.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.5.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.6.
|
||||
@@ -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'
|
||||
$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', $error->getMessage());
|
||||
: Text::sprintf('COM_TESTQUESTIONS_AI_ERROR', $errorMessage));
|
||||
$type = 'error';
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Komponent\Component\Testquestions\Administrator\Field;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Form\FormField;
|
||||
|
||||
class AiapikeyField extends FormField
|
||||
{
|
||||
protected $type = 'Aiapikey';
|
||||
|
||||
protected function getInput(): string
|
||||
{
|
||||
$id = htmlspecialchars($this->id, ENT_QUOTES, 'UTF-8');
|
||||
$name = htmlspecialchars($this->name, ENT_QUOTES, 'UTF-8');
|
||||
$value = htmlspecialchars((string) $this->value, ENT_QUOTES, 'UTF-8');
|
||||
$length = mb_strlen((string) $this->value);
|
||||
|
||||
return '<div class="input-group">'
|
||||
. '<input type="password" id="' . $id . '" name="' . $name . '" value="' . $value . '" size="120" autocomplete="off" class="form-control">'
|
||||
. '<button type="button" class="btn btn-outline-secondary" data-ai-key-toggle="' . $id . '">Pokaż</button>'
|
||||
. '</div>'
|
||||
. '<small class="form-text text-muted">Zapisany klucz: ' . (int) $length . ' znaków.</small>'
|
||||
. '<script>
|
||||
document.addEventListener("click", function (event) {
|
||||
var button = event.target.closest("[data-ai-key-toggle]");
|
||||
if (!button) return;
|
||||
var input = document.getElementById(button.getAttribute("data-ai-key-toggle"));
|
||||
if (!input) return;
|
||||
var visible = input.type === "text";
|
||||
input.type = visible ? "password" : "text";
|
||||
button.textContent = visible ? "Pokaż" : "Ukryj";
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
@@ -91,9 +91,50 @@ 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
|
||||
// (np. ********) nie zostanie potraktowana jako prawdziwy klucz.
|
||||
$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)) {
|
||||
$storedProvider = trim((string) ($storedParams['ai_provider'] ?? ''));
|
||||
$storedApiKey = trim((string) ($storedParams['ai_api_key'] ?? ''));
|
||||
|
||||
if ($storedProvider !== '') {
|
||||
$provider = $storedProvider;
|
||||
}
|
||||
|
||||
if ($storedApiKey !== '' && !preg_match('/^\*+$/', $storedApiKey)) {
|
||||
$apiKey = $storedApiKey;
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
(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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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.1</version>
|
||||
<version>1.42.7</version>
|
||||
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
||||
<element>com_testquestions</element>
|
||||
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
||||
|
||||
Reference in New Issue
Block a user