Skip to content

Commit 0334d00

Browse files
committed
code review
1 parent b5406c8 commit 0334d00

File tree

9 files changed

+70
-12
lines changed

9 files changed

+70
-12
lines changed

app/base/commands/App/Ai.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class Ai extends BaseCommand
3030

3131
protected array $interactions = [];
3232

33-
protected $availableAIs = ['googlegemini', 'chatgpt', 'claude', 'mistral'];
34-
3533
/**
3634
* {@inheritdoc}
3735
*/
@@ -93,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
9391
}
9492

9593
if ($doEnable) {
96-
$aiType = $this->keepAsking('Which AI do you want to enable? ('.implode(', ', $this->availableAIs).') ', $this->availableAIs);
94+
$aiType = $this->keepAsking('Which AI do you want to enable? ('.implode(', ', $this->getSiteData()->getAvailableAIs()).') ', $this->getSiteData()->getAvailableAIs());
9795
$apiTokenValue = $this->keepAsking($aiType . ' token value? ');
9896

9997
switch ($aiType) {
@@ -120,7 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
120118
return Command::SUCCESS;
121119
}
122120

123-
$availableAIs = array_filter($this->availableAIs, fn($el) => App::getInstance()->getSiteData()->isAiAvailable($el));
121+
$availableAIs = array_filter($this->getSiteData()->getAvailableAIs(), fn($el) => App::getInstance()->getSiteData()->isAiAvailable($el));
124122

125123
if (count($availableAIs) > 1) {
126124
$aiType = $this->keepAsking('Which AI do you want to use? (' . implode(', ', $availableAIs) . ') ', $availableAIs);

app/base/controllers/Admin/Json/ChatGPT.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public static function isEnabled() : bool
4242
return !empty(App::getInstance()->getSiteData()->getConfigValue(self::CHATGPT_TOKEN_PATH));
4343
}
4444

45+
/**
46+
* returns model name
47+
*
48+
* @return string
49+
*/
50+
public static function getModelName() : string
51+
{
52+
return 'ChatGPT';
53+
}
54+
4555
/**
4656
* {@inheritdoc}
4757
*

app/base/controllers/Admin/Json/Claude.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public static function isEnabled() : bool
3737
return !empty(App::getInstance()->getSiteData()->getConfigValue(self::CLAUDE_TOKEN_PATH));
3838
}
3939

40+
/**
41+
* returns model name
42+
*
43+
* @return string
44+
*/
45+
public static function getModelName() : string
46+
{
47+
return 'Claude';
48+
}
49+
4050
/**
4151
* {@inheritdoc}
4252
*

app/base/controllers/Admin/Json/GoogleGemini.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public static function isEnabled() : bool
3737
return !empty(App::getInstance()->getSiteData()->getConfigValue(self::GEMINI_TOKEN_PATH));
3838
}
3939

40+
/**
41+
* returns model name
42+
*
43+
* @return string
44+
*/
45+
public static function getModelName() : string
46+
{
47+
return 'Google Gemini';
48+
}
49+
4050
/**
4151
* {@inheritdoc}
4252
*

app/base/controllers/Admin/Json/Mistral.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public static function isEnabled() : bool
3737
return !empty(App::getInstance()->getSiteData()->getConfigValue(self::MISTRAL_TOKEN_PATH));
3838
}
3939

40+
/**
41+
* returns model name
42+
*
43+
* @return string
44+
*/
45+
public static function getModelName() : string
46+
{
47+
return 'Mistral';
48+
}
49+
4050
/**
4151
* {@inheritdoc}
4252
*

app/base/tools/Plates/SiteBase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ public function getQrCode($url) : string
415415
return $this->getHtmlRenderer()->getQrCode($url);
416416
}
417417

418+
public function getAvailableAIs(bool $withNames = false) : array
419+
{
420+
return $this->getSiteData()->getAvailableAIs($withNames);
421+
}
422+
418423
public function isAiAvailable(string|array|null $ai = null) : bool
419424
{
420425
return $this->getSiteData()->isAiAvailable($ai);

app/base/tools/Utils/SiteData.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,27 @@ public function getAdminSidebarVisibleLinks(AdminPage $controller)
730730
return $links;
731731
}
732732

733+
public function getAvailableAIs(bool $withNames = false) : array
734+
{
735+
$AIs = [
736+
'googlegemini' => GoogleGemini::getModelName(),
737+
'chatgpt' => ChatGPT::getModelName(),
738+
'claude' => Claude::getModelName(),
739+
'mistral' => Mistral::getModelName()
740+
];
741+
742+
if ($withNames) {
743+
return $AIs;
744+
}
745+
746+
return array_keys($AIs);
747+
}
748+
733749
public function isAiAvailable(string|array|null $ai = null): bool
734750
{
735751
if (is_array($ai)) {
736752
$out = true;
737-
$ai = array_intersect(array_map('strtolower', $ai), ['google', 'gemini']);
753+
$ai = array_intersect(array_map('strtolower', $ai), $this->getAvailableAIs());
738754
if (empty($ai)) {
739755
return false;
740756
}

js/src/admin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
case 'chatGPT':
253253
$(that).appAdmin('askChatGPT', {'prompt': text, 'messageId': messageId}, callbackFunc);
254254
break;
255-
case 'gemini':
255+
case 'googlegemini':
256256
$(that).appAdmin('askGoogleGemini', {'prompt': text, 'messageId': messageId}, callbackFunc);
257257
break;
258258
case 'claude':
@@ -456,7 +456,7 @@
456456
case 'chatGPT':
457457
AIUrl = $(this).appAdmin('getSettings').chatGPTUrl;
458458
break;
459-
case 'gemini':
459+
case 'googlegemini':
460460
AIUrl = $(this).appAdmin('getSettings').googleGeminiUrl;
461461
break;
462462
case 'claude':
@@ -507,7 +507,7 @@
507507
$(this).appAdmin('askAI', 'chatGPT', params, targetOrCallback);
508508
},
509509
askGoogleGemini: function(params, targetOrCallback) {
510-
$(this).appAdmin('askAI', 'gemini', params, targetOrCallback);
510+
$(this).appAdmin('askAI', 'googlegemini', params, targetOrCallback);
511511
},
512512
askClaude: function(params, targetOrCallback) {
513513
$(this).appAdmin('askAI', 'claude', params, targetOrCallback);

templates/admin/layout.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@
8383
<div class="p-1 border-bottom d-flex justify-content-between align-items-center">
8484
<strong class="ml-3">Chat AI</strong>
8585
<select id="chatAISelector" class="select-processed" style="width: 150px;">
86-
<?php if ($this->sitebase()->isAiAvailable('chatgpt')) : ?><option value="chatGPT">ChatGPT</option><?php endif; ?>
87-
<?php if ($this->sitebase()->isAiAvailable('googlegemini')) : ?><option value="gemini">Google Gemini</option><?php endif; ?>
88-
<?php if ($this->sitebase()->isAiAvailable('claude')) : ?><option value="claude">Claude</option><?php endif; ?>
89-
<?php if ($this->sitebase()->isAiAvailable('mistral')) : ?><option value="mistral">Mistral</option><?php endif; ?>
86+
<?php foreach ($this->sitebase()->getAvailableAIs(true) as $ai => $name) : ?>
87+
<?php if ($this->sitebase()->isAiAvailable($ai)) : ?><option value="<?= $ai; ?>"><?= ucfirst($name); ?></option><?php endif; ?>
88+
<?php endforeach; ?>
9089
</select>
9190
<a href="#" class="closebtn mr-2">&times;</a>
9291
</div>

0 commit comments

Comments
 (0)