Skip to content

Commit 5150c47

Browse files
committed
feat: consolidate api services
1 parent 19fcae4 commit 5150c47

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

_build/gpm.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ plugins:
1010
- OnManagerPageBeforeRender
1111

1212
systemSettings:
13-
- key: chatgpt.key
13+
- key: api.chatgpt.key
1414
type: text-password
15-
area: chatgpt
15+
area: api
1616
description: "Your API key found at https://platform.openai.com/api-keys"
17-
- key: gemini.key
17+
18+
- key: api.gemini.key
1819
type: text-password
19-
area: gemini
20+
area: api
2021
description: "Your API key found at https://ai.google.dev/gemini-api/docs/api-key"
21-
- key: anthropic.key
22+
23+
- key: api.claude.key
2224
type: text-password
23-
area: anthropic
25+
area: api
2426
description: "Your API key found at https://console.anthropic.com/settings/keys"
2527

2628
- key: global.base.output

core/components/modai/src/Services/AIServiceFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static function new($model, modX &$modx): AIService {
1010
}
1111

1212
if (substr($model, 0, 7) === 'claude-') {
13-
return new Anthropic($modx);
13+
return new Claude($modx);
1414
}
1515

1616
switch ($model) {

core/components/modai/src/Services/ChatGPT.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public function generateImage(string $prompt, ImageConfig $config): string {
7171
*/
7272
public function getCompletions(array $data, CompletionsConfig $config): string
7373
{
74-
$chatgptApiKey = $this->modx->getOption('modai.chatgpt.key');
74+
$chatgptApiKey = $this->modx->getOption('modai.api.chatgpt.key');
7575
if (empty($chatgptApiKey)) {
76-
throw new \Exception('Missing modai.chatgpt.key');
76+
throw new \Exception('Missing modai.api.chatgpt.key');
7777
}
7878

7979
$messages = [];

core/components/modai/src/Services/Anthropic.php renamed to core/components/modai/src/Services/Claude.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use modAI\Services\Config\VisionConfig;
77
use MODX\Revolution\modX;
88

9-
class Anthropic implements AIService
9+
class Claude implements AIService
1010
{
1111
private modX $modx;
1212

@@ -22,9 +22,9 @@ public function __construct(modX &$modx)
2222
*/
2323
public function getCompletions(array $data, CompletionsConfig $config): string
2424
{
25-
$apiKey = $this->modx->getOption('modai.anthropic.key');
25+
$apiKey = $this->modx->getOption('modai.api.claude.key');
2626
if (empty($apiKey)) {
27-
throw new \Exception('Missing modai.anthropic.key');
27+
throw new \Exception('Missing modai.api.claude.key');
2828
}
2929

3030
$messages = [];

core/components/modai/src/Services/Gemini.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function __construct(modX &$modx)
2121
*/
2222
public function getCompletions(array $data, CompletionsConfig $config): string
2323
{
24-
$apiKey = $this->modx->getOption('modai.gemini.key');
24+
$apiKey = $this->modx->getOption('modai.api.gemini.key');
2525
if (empty($apiKey)) {
26-
throw new \Exception('Missing modai.gemini.key');
26+
throw new \Exception('Missing modai.api.gemini.key');
2727
}
2828

2929
$url = self::COMPLETIONS_API;

0 commit comments

Comments
 (0)