Skip to content

Commit 931d4e1

Browse files
committed
feat: add to the tool's getParameters and getPrompt methods as an argument
1 parent c053471 commit 931d4e1

21 files changed

+47
-42
lines changed

core/components/modai/controllers/tool/update.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function process(array $scriptProperties = [])
2222

2323
$this->toolData = $tool->toArray();
2424
$this->toolData['classConfig'] = $this->toolData['class']::getConfig($this->modx);
25-
$this->toolData['defaultPrompt'] = $this->toolData['class']::getPrompt();
25+
$this->toolData['defaultPrompt'] = $this->toolData['class']::getPrompt($this->modx);
2626
}
2727

2828
public function getPageTitle()
@@ -44,7 +44,7 @@ public function loadCustomCssJs()
4444
$this->addHtml('
4545
<script type="text/javascript">
4646
Ext.onReady(function() {
47-
MODx.load({
47+
MODx.load({
4848
xtype: "modai-page-tool",
4949
record: ' . $this->modx->toJSON($this->toolData) . ',
5050
permissions: ' . json_encode($this->permissions) . '

core/components/modai/src/API/Prompt/Chat.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public function post(ServerRequestInterface $request): void
9696

9797
Settings::setSetting($this->modx, "$customOptionsKey.agent_options", json_encode($customOptionsValue));
9898
}
99-
10099
}
101100
}
102101
}
@@ -167,7 +166,7 @@ public function post(ServerRequestInterface $request): void
167166
$aiService = AIServiceFactory::new($model, $this->modx);
168167
$result = $aiService->getCompletions(
169168
$userMessages,
170-
CompletionsConfig::new($model)
169+
CompletionsConfig::new($model, $this->modx)
171170
->tools($tools)
172171
->messages($messages)
173172
->options(['max_tokens' => $maxTokens, 'temperature' => $temperature], $customOptions, $agentOptions, $additionalOptions)

core/components/modai/src/API/Prompt/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function post(ServerRequestInterface $request): void
4646
$aiService = AIServiceFactory::new($model, $this->modx);
4747
$result = $aiService->generateImage(
4848
$prompt,
49-
ImageConfig::new($model)
49+
ImageConfig::new($model, $this->modx)
5050
->options(['quality' => $quality, 'style' => $style, 'size' => $size, 'response_format' => $responseFormat], $customOptions, $additionalOptions)
5151
->attachments($attachments)
5252
);

core/components/modai/src/API/Prompt/Text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function post(ServerRequestInterface $request): void
9191
$aiService = AIServiceFactory::new($model, $this->modx);
9292
$result = $aiService->getCompletions(
9393
[['content' => $content]],
94-
CompletionsConfig::new($model)
94+
CompletionsConfig::new($model, $this->modx)
9595
->options(['max_tokens' => $maxTokens, 'temperature' => $temperature], $customOptions)
9696
->systemInstructions($systemInstructions)
9797
->stream($stream)

core/components/modai/src/API/Prompt/Vision.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function post(ServerRequestInterface $request): void
4343
$result = $aiService->getVision(
4444
$prompt,
4545
$image,
46-
VisionConfig::new($model)
46+
VisionConfig::new($model, $this->modx)
4747
->options(['max_tokens' => $maxTokens], $customOptions)
4848
->stream($stream)
4949
);

core/components/modai/src/Processors/Combos/ToolClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public function process()
4040
}
4141
}
4242

43-
return $this->outputArray(array_map(function($class) {
43+
return $this->outputArray(array_map(function ($class) {
4444
return [
4545
'class' => $class,
4646
'config' => $class::getConfig($this->modx),
4747
'suggestedName' => $class::getSuggestedName(),
4848
'description' => $class::getDescription(),
49-
'defaultPrompt' => $class::getPrompt(),
49+
'defaultPrompt' => $class::getPrompt($this->modx),
5050
];
5151
}, $classes), count($classes));
5252
}

core/components/modai/src/Services/Config/CompletionsConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public function getTools(): array
7676
$prompt = $tool->get('prompt');
7777
$tools[] = [
7878
'name' => $toolName,
79-
'description' => !empty($prompt) ? $prompt : $toolClass::getPrompt(),
80-
'parameters' => $toolClass::getParameters(),
79+
'description' => !empty($prompt) ? $prompt : $toolClass::getPrompt($this->modx),
80+
'parameters' => $toolClass::getParameters($this->modx),
8181
];
8282
}
8383

core/components/modai/src/Services/Config/Model.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
namespace modAI\Services\Config;
44

5+
use MODX\Revolution\modX;
6+
57
trait Model
68
{
79
private string $model;
10+
private modX $modx;
811

9-
private function __construct(string $model)
12+
private function __construct(string $model, modX $modx)
1013
{
1114
$this->model = $model;
15+
$this->modx = $modx;
1216
}
1317

14-
public static function new(string $model): self
18+
public static function new(string $model, modX $modx): self
1519
{
16-
return new self($model);
20+
return new self($model, $modx);
1721
}
1822

1923
public function getModel(): string

core/components/modai/src/Tools/CreateCategory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public static function getSuggestedName(): string
1414
return 'create_category';
1515
}
1616

17-
public static function getPrompt(): string
17+
public static function getPrompt(modX $modx): string
1818
{
1919
return "Creates a new Category that any element (chunks or templates) can be grouped by. Use the get categories tool first to check if a category already exists. When successful, this tool returns the category ID to use when creating chunks or templates.";
2020
}
2121

22-
public static function getParameters(): array
22+
public static function getParameters(modX $modx): array
2323
{
2424
return [
2525
'type' => 'object',

core/components/modai/src/Tools/CreateChunk.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public static function getSuggestedName(): string
1414
return 'create_chunk';
1515
}
1616

17-
public static function getPrompt(): string
17+
public static function getPrompt(modX $modx): string
1818
{
1919
return "Creates a new Chunk, which is a reusable piece of HTML or other code that can be inserted into pages, templates, or other elements. Use when explicitly asked to create a chunk or when creating templates to break up reusable pieces. Once created, chunks can be rendered by using [[\$name_of_chunk]] in a template or elsewhere. ALWAYS ask for explicit user confirmation with the chunk name, description, and category name in a separate message BEFORE calling this function.";
2020
}
2121

22-
public static function getParameters(): array
22+
public static function getParameters(modX $modx): array
2323
{
2424
return [
2525
'type' => 'object',

0 commit comments

Comments
 (0)