Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb1dc728d1 | ||
|
|
ed2c6b663b | ||
|
|
03728ce49f | ||
|
|
a7637aedcc |
@@ -30,6 +30,6 @@ Szkielet komponentu Joomla 6 do gromadzenia pytań testowych.
|
|||||||
|
|
||||||
## Instalacja
|
## Instalacja
|
||||||
|
|
||||||
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.42.3).
|
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**.
|
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<option value="openai">OpenAI</option>
|
<option value="openai">OpenAI</option>
|
||||||
<option value="grok">Grok</option>
|
<option value="grok">Grok</option>
|
||||||
</field>
|
</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>
|
</fieldset>
|
||||||
</fields>
|
</fields>
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
@@ -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 {
|
try {
|
||||||
$this->getModel('Result')->evaluateWithAi($id, $questionId);
|
$this->getModel('Result')->evaluateWithAi($id, $questionId);
|
||||||
} catch (\Throwable $error) {
|
} catch (\Throwable $error) {
|
||||||
$message = $error->getMessage() === 'AI_NOT_CONFIGURED'
|
$errorMessage = $error->getMessage();
|
||||||
? Text::_('COM_TESTQUESTIONS_AI_NOT_CONFIGURED')
|
$message = str_starts_with($errorMessage, 'AI_KEY_EMPTY|')
|
||||||
: Text::sprintf('COM_TESTQUESTIONS_AI_ERROR', $error->getMessage());
|
? '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';
|
$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>';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -93,6 +93,7 @@ class ResultModel extends BaseDatabaseModel
|
|||||||
$params = ComponentHelper::getParams('com_testquestions');
|
$params = ComponentHelper::getParams('com_testquestions');
|
||||||
$provider = trim((string) $params->get('ai_provider', 'openai'));
|
$provider = trim((string) $params->get('ai_provider', 'openai'));
|
||||||
$apiKey = trim((string) $params->get('ai_api_key', ''));
|
$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
|
// 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
|
// 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(
|
$feedback = (new AiService())->evaluate(
|
||||||
$provider,
|
$provider,
|
||||||
$apiKey,
|
$apiKey,
|
||||||
|
|||||||
@@ -11,14 +11,19 @@ class AiService
|
|||||||
public function evaluate(string $provider, string $apiKey, string $question, string $answer, string $pattern): string
|
public function evaluate(string $provider, string $apiKey, string $question, string $answer, string $pattern): string
|
||||||
{
|
{
|
||||||
$provider = strtolower(trim($provider));
|
$provider = strtolower(trim($provider));
|
||||||
|
$provider = preg_replace('/[^a-z]/', '', $provider);
|
||||||
$config = $provider === 'grok'
|
$config = $provider === 'grok'
|
||||||
? ['url' => 'https://api.x.ai/v1/responses', 'model' => 'grok-4.7']
|
? ['url' => 'https://api.x.ai/v1/responses', 'model' => 'grok-4.7']
|
||||||
: ['url' => 'https://api.openai.com/v1/responses', 'model' => 'gpt-4.1-mini'];
|
: ['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');
|
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"
|
$input = "Oceń odpowiedź ucznia na pytanie otwarte.\n\n"
|
||||||
. "Pytanie:\n" . $question . "\n\n"
|
. "Pytanie:\n" . $question . "\n\n"
|
||||||
. "Wzorzec odpowiedzi:\n" . $pattern . "\n\n"
|
. "Wzorzec odpowiedzi:\n" . $pattern . "\n\n"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<creationDate>2026-10-14</creationDate>
|
<creationDate>2026-10-14</creationDate>
|
||||||
<author>Komponent</author>
|
<author>Komponent</author>
|
||||||
<license>GNU General Public License version 2 or later</license>
|
<license>GNU General Public License version 2 or later</license>
|
||||||
<version>1.42.3</version>
|
<version>1.42.7</version>
|
||||||
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
||||||
<element>com_testquestions</element>
|
<element>com_testquestions</element>
|
||||||
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
||||||
|
|||||||
Reference in New Issue
Block a user