Add Gemini API as an AI provider
This commit is contained in:
@@ -8,9 +8,11 @@
|
||||
<?php $openaiKey = (string) ($this->settings['ai_openai_api_key'] ?? ($provider === 'openai' ? $legacyKey : '')); ?>
|
||||
<?php $grokKey = (string) ($this->settings['ai_grok_api_key'] ?? ($provider === 'grok' ? $legacyKey : '')); ?>
|
||||
<?php $groqKey = (string) ($this->settings['ai_groq_api_key'] ?? ($provider === 'groq' ? $legacyKey : '')); ?>
|
||||
<?php $geminiKey = (string) ($this->settings['ai_gemini_api_key'] ?? ($provider === 'gemini' ? $legacyKey : '')); ?>
|
||||
<?php $openaiModel = (string) ($this->settings['ai_openai_model'] ?? 'gpt-4.1-mini'); ?>
|
||||
<?php $grokModel = (string) ($this->settings['ai_grok_model'] ?? 'grok-4.7'); ?>
|
||||
<?php $groqModel = (string) ($this->settings['ai_groq_model'] ?? 'openai/gpt-oss-120b'); ?>
|
||||
<?php $geminiModel = (string) ($this->settings['ai_gemini_model'] ?? 'gemini-3.8-flash'); ?>
|
||||
<form action="<?php echo Route::_('index.php?option=com_testquestions&view=ai'); ?>" method="post" name="adminForm" id="adminForm">
|
||||
<div class="card" style="max-width: 900px;">
|
||||
<div class="card-body">
|
||||
@@ -20,6 +22,7 @@
|
||||
<option value="openai" <?php echo $provider === 'openai' ? 'selected' : ''; ?>>OpenAI</option>
|
||||
<option value="grok" <?php echo $provider === 'grok' ? 'selected' : ''; ?>>Grok</option>
|
||||
<option value="groq" <?php echo $provider === 'groq' ? 'selected' : ''; ?>>Groq</option>
|
||||
<option value="gemini" <?php echo $provider === 'gemini' ? 'selected' : ''; ?>>Gemini</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3" data-ai-provider-section="openai">
|
||||
@@ -76,6 +79,24 @@
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3" data-ai-provider-section="gemini">
|
||||
<label for="ai-gemini-api-key" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_GEMINI_KEY'); ?></label>
|
||||
<div class="input-group">
|
||||
<input type="password" id="ai-gemini-api-key" name="ai_gemini_api_key" value="<?php echo htmlspecialchars($geminiKey, ENT_QUOTES, 'UTF-8'); ?>" class="form-control" size="120" maxlength="4096" autocomplete="new-password">
|
||||
<button type="button" class="btn btn-outline-secondary" data-ai-key-toggle="ai-gemini-api-key">Pokaż</button>
|
||||
</div>
|
||||
<small class="form-text text-muted">
|
||||
<?php echo $geminiKey !== '' ? 'Zapisany klucz: ' . mb_strlen($geminiKey) . ' znaków. Pozostaw pole bez zmian, aby go zachować.' : 'Nie zapisano klucza Gemini.'; ?>
|
||||
</small>
|
||||
</div>
|
||||
<div class="mb-3" data-ai-provider-section="gemini">
|
||||
<label for="ai-gemini-model" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_GEMINI_MODEL'); ?></label>
|
||||
<select id="ai-gemini-model" name="ai_gemini_model" class="form-select" required>
|
||||
<?php foreach ($availableModels['gemini'] as $modelId => $modelLabel) : ?>
|
||||
<option value="<?php echo htmlspecialchars($modelId, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $geminiModel === $modelId ? 'selected' : ''; ?>><?php echo htmlspecialchars($modelLabel, ENT_QUOTES, 'UTF-8'); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<hr>
|
||||
<h3><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_TOKEN_USAGE'); ?></h3>
|
||||
<p class="text-muted"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_TOKEN_USAGE_INFO'); ?></p>
|
||||
@@ -92,7 +113,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach (['openai' => 'OpenAI', 'grok' => 'Grok', 'groq' => 'Groq'] as $usageProvider => $usageProviderLabel) : ?>
|
||||
<?php foreach (['openai' => 'OpenAI', 'grok' => 'Grok', 'groq' => 'Groq', 'gemini' => 'Gemini'] as $usageProvider => $usageProviderLabel) : ?>
|
||||
<?php $providerUsage = $usageTotals[$usageProvider]; ?>
|
||||
<tr>
|
||||
<th><?php echo $usageProviderLabel; ?></th>
|
||||
|
||||
@@ -64,7 +64,7 @@ $resolveImageUrl = static function ($path) {
|
||||
}
|
||||
?>
|
||||
<?php if ($usageTotals['total_tokens'] > 0) : ?>
|
||||
<?php $usageProviderLabels = array_map(static function ($usageProvider) { return ['openai' => 'OpenAI', 'grok' => 'Grok', 'groq' => 'Groq'][$usageProvider] ?? $usageProvider; }, array_keys($usageTotals['providers'])); ?>
|
||||
<?php $usageProviderLabels = array_map(static function ($usageProvider) { return ['openai' => 'OpenAI', 'grok' => 'Grok', 'groq' => 'Groq', 'gemini' => 'Gemini'][$usageProvider] ?? $usageProvider; }, array_keys($usageTotals['providers'])); ?>
|
||||
<span class="badge text-bg-light border ms-2" title="Suma dotychczasowych ocen AI">
|
||||
✦ <?php echo implode(' + ', array_map('htmlspecialchars', $usageProviderLabels)); ?>:
|
||||
<?php echo number_format($usageTotals['total_tokens'], 0, ',', ' '); ?> tokenów,
|
||||
@@ -96,8 +96,8 @@ $resolveImageUrl = static function ($path) {
|
||||
<?php if (!empty($answer['ai_usage']) && is_array($answer['ai_usage'])) : ?>
|
||||
<?php $usage = $answer['ai_usage']; ?>
|
||||
<?php $usageProvider = (string) ($usage['provider'] ?? ''); ?>
|
||||
<span class="badge text-bg-light border ms-2" title="<?php echo $usageProvider === 'grok' ? 'Koszt zwrócony przez dostawcę' : ($usageProvider === 'groq' ? 'Groq zwrócił wykorzystane tokeny; koszt nie jest zwracany przez to API' : 'Koszt obliczony z faktycznie wykorzystanych tokenów i stawek modelu'); ?>">
|
||||
<?php echo $usageProvider === 'grok' ? '✦ Grok' : ($usageProvider === 'groq' ? '⚡ Groq' : '◉ OpenAI'); ?> ·
|
||||
<span class="badge text-bg-light border ms-2" title="<?php echo $usageProvider === 'grok' ? 'Koszt zwrócony przez dostawcę' : (in_array($usageProvider, ['groq', 'gemini'], true) ? 'Dostawca zwrócił wykorzystane tokeny; koszt nie jest zwracany przez to API' : 'Koszt obliczony z faktycznie wykorzystanych tokenów i stawek modelu'); ?>">
|
||||
<?php echo $usageProvider === 'grok' ? '✦ Grok' : ($usageProvider === 'groq' ? '⚡ Groq' : ($usageProvider === 'gemini' ? '✧ Gemini' : '◉ OpenAI')); ?> ·
|
||||
<?php echo number_format((int) ($usage['input_tokens'] ?? 0), 0, ',', ' '); ?> in /
|
||||
<?php echo number_format((int) ($usage['output_tokens'] ?? 0), 0, ',', ' '); ?> out ·
|
||||
<?php echo is_numeric($usage['cost_usd'] ?? null) ? number_format((float) $usage['cost_usd'], 8, ',', ' ') . ' USD' : 'koszt niedostępny'; ?>
|
||||
|
||||
@@ -56,6 +56,12 @@ HTMLHelper::_('behavior.multiselect');
|
||||
(<?php echo number_format((int) $this->aiUsageTotals['providers']['groq']['input_tokens'], 0, ',', ' '); ?> wej. /
|
||||
<?php echo number_format((int) $this->aiUsageTotals['providers']['groq']['output_tokens'], 0, ',', ' '); ?> wyj.)
|
||||
</span>
|
||||
<span class="d-block">
|
||||
<strong>Gemini:</strong>
|
||||
<?php echo number_format((int) $this->aiUsageTotals['providers']['gemini']['total_tokens'], 0, ',', ' '); ?> tokenów
|
||||
(<?php echo number_format((int) $this->aiUsageTotals['providers']['gemini']['input_tokens'], 0, ',', ' '); ?> wej. /
|
||||
<?php echo number_format((int) $this->aiUsageTotals['providers']['gemini']['output_tokens'], 0, ',', ' '); ?> wyj.)
|
||||
</span>
|
||||
<span class="d-block"><strong>Łącznie:</strong> <?php echo number_format((int) $this->aiUsageTotals['total_tokens'], 0, ',', ' '); ?> tokenów</span>
|
||||
</div>
|
||||
<table class="table table-striped">
|
||||
@@ -92,6 +98,7 @@ HTMLHelper::_('behavior.multiselect');
|
||||
OpenAI: <?php echo number_format((int) $item->ai_tokens_by_provider['openai'], 0, ',', ' '); ?> ·
|
||||
Grok: <?php echo number_format((int) $item->ai_tokens_by_provider['grok'], 0, ',', ' '); ?> ·
|
||||
Groq: <?php echo number_format((int) $item->ai_tokens_by_provider['groq'], 0, ',', ' '); ?>
|
||||
· Gemini: <?php echo number_format((int) $item->ai_tokens_by_provider['gemini'], 0, ',', ' '); ?>
|
||||
</small>
|
||||
<small class="d-block text-muted">
|
||||
<?php echo number_format((int) $item->ai_total_tokens, 0, ',', ' '); ?> łącznie
|
||||
|
||||
Reference in New Issue
Block a user