Skip to content

Commit 97590df

Browse files
committed
feat: rename tool's description to prompt and add internal description to tools & context providers
1 parent 4241ada commit 97590df

26 files changed

+180
-53
lines changed

assets/components/modai/mgr/js/context_provider/panel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,17 @@ Ext.extend(modAIAdmin.panel.ContextProvider, MODx.FormPanel, {
128128
xtype: 'modai-combo-context_provider_class',
129129
value: config.record.class,
130130
listeners: {
131-
select: (self, record) => {
131+
beforeselect: (self, record) => {
132+
const name = this.getForm().findField('name');
133+
if (name && (self.getValue() !== record.data.class || !name.getValue())) {
134+
name.setValue(record.data.suggestedName);
135+
}
136+
137+
const description = this.getForm().findField('description');
138+
if (description && (self.getValue() !== record.data.class || !description.getValue())) {
139+
description.setValue(record.data.description);
140+
}
141+
132142
this.configSection.removeAll();
133143
Object.entries(record.data.config).forEach(([key, config]) => {
134144
this.configSection.add(modAIAdmin.formatConfigItem(key, config));

assets/components/modai/mgr/js/tool/panel.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,17 @@ Ext.extend(modAIAdmin.panel.Tool, MODx.FormPanel, {
125125
xtype: 'modai-combo-tool_class',
126126
value: config.record.class,
127127
listeners: {
128-
select: (self, record) => {
128+
beforeselect: (self, record) => {
129129
const name = this.getForm().findField('name');
130-
if (name && !name.getValue()) {
130+
if (name && (self.getValue() !== record.data.class || !name.getValue())) {
131131
name.setValue(record.data.suggestedName);
132132
}
133133

134+
const description = this.getForm().findField('description');
135+
if (description && (self.getValue() !== record.data.class ||!description.getValue())) {
136+
description.setValue(record.data.description);
137+
}
138+
134139
this.configSection.removeAll();
135140
Object.entries(record.data.config).forEach(([key, config]) => {
136141
this.configSection.add(modAIAdmin.formatConfigItem(key, config));

assets/components/modai/mgr/js/utils/combos.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ modAIAdmin.combo.ContextProviderClass = function (config) {
133133
hiddenName: 'class',
134134
displayField: 'class',
135135
valueField: 'class',
136-
fields: ['class', 'config'],
136+
fields: ['class', 'config', 'suggestedName', 'description'],
137137
typeAhead: false,
138138
editable: true,
139139
forceSelection: true,
@@ -142,7 +142,13 @@ modAIAdmin.combo.ContextProviderClass = function (config) {
142142
url: MODx.config.connector_url,
143143
baseParams: {
144144
action: 'modAI\\Processors\\Combos\\ContextProviderClass',
145-
}
145+
},
146+
tpl: new Ext.XTemplate('<tpl for=".">' +
147+
'<div class="x-combo-list-item x-combo-list-item-grouped">' +
148+
'<div class="x-combo-list-title">{class:htmlEncode}</div>' +
149+
'{description:htmlEncode()}' +
150+
'</div>' +
151+
'</tpl>')
146152
});
147153
modAIAdmin.combo.ContextProviderClass.superclass.constructor.call(this, config);
148154
};
@@ -156,7 +162,7 @@ modAIAdmin.combo.ToolClass = function (config) {
156162
hiddenName: 'class',
157163
displayField: 'class',
158164
valueField: 'class',
159-
fields: ['class', 'config', 'suggestedName'],
165+
fields: ['class', 'config', 'suggestedName', 'description'],
160166
typeAhead: false,
161167
editable: true,
162168
forceSelection: true,
@@ -165,7 +171,13 @@ modAIAdmin.combo.ToolClass = function (config) {
165171
url: MODx.config.connector_url,
166172
baseParams: {
167173
action: 'modAI\\Processors\\Combos\\ToolClass',
168-
}
174+
},
175+
tpl: new Ext.XTemplate('<tpl for=".">' +
176+
'<div class="x-combo-list-item x-combo-list-item-grouped">' +
177+
'<div class="x-combo-list-title">{class:htmlEncode}</div>' +
178+
'{description:htmlEncode()}' +
179+
'</div>' +
180+
'</tpl>')
169181
});
170182
modAIAdmin.combo.ToolClass.superclass.constructor.call(this, config);
171183
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function process(array $scriptProperties = [])
2121
}
2222

2323
$this->contextProviderData = $contextProvider->toArray();
24-
$this->contextProviderData['classConfig'] = $this->contextProviderData['class']::getConfig();
24+
$this->contextProviderData['classConfig'] = $this->contextProviderData['class']::getConfig($this->modx);
2525
}
2626

2727
public function getPageTitle()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function process(array $scriptProperties = [])
2121
}
2222

2323
$this->toolData = $tool->toArray();
24-
$this->toolData['classConfig'] = $this->toolData['class']::getConfig();
24+
$this->toolData['classConfig'] = $this->toolData['class']::getConfig($this->modx);
2525
}
2626

2727
public function getPageTitle()

core/components/modai/lexicon/en/default.inc.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@
9090
$_lang['modai.admin.related_agent.remove'] = 'Unassign Agent';
9191
$_lang['modai.admin.related_agent.remove_confirm'] = 'Are you sure you want to unassign "[[+name]]" agent?';
9292

93+
$_lang['modai.admin.context_provider.pinecone.api_key'] = 'API Key';
94+
$_lang['modai.admin.context_provider.pinecone.api_key_desc'] = 'API Key to access Pinecone';
95+
$_lang['modai.admin.context_provider.pinecone.endpoint'] = 'API endpoint';
96+
$_lang['modai.admin.context_provider.pinecone.endpoint_desc'] = 'Endpoint of your Pinecone API instance.';
97+
$_lang['modai.admin.context_provider.pinecone.namespace'] = 'Namespace';
98+
$_lang['modai.admin.context_provider.pinecone.namespace_desc'] = 'Namespace that will be used to store/query your data.';
99+
$_lang['modai.admin.context_provider.pinecone.fields'] = 'Fields to index';
100+
$_lang['modai.admin.context_provider.pinecone.fields_desc'] = 'Comma separated list of fields to index.';
101+
$_lang['modai.admin.context_provider.pinecone.fields_map'] = 'Map fields to a different name';
102+
$_lang['modai.admin.context_provider.pinecone.fields_map_desc'] = 'Comma separated list of original_name:new_name pairs';
103+
$_lang['modai.admin.context_provider.pinecone.context_messages'] = 'Context Messages';
104+
$_lang['modai.admin.context_provider.pinecone.context_messages_desc'] = 'Additional context messages that will be put in front of the data from DB. One message per line. Can contain {id} or any {field} (defined in fields config) placeholder, you can also reference a system setting with using ++ as a prefix, for example {++site_url}.';
105+
106+
93107
$_lang['modai.admin.error.required'] = 'Field is required.';
94108

95109
$_lang['modai.admin.error.context_provider_name_already_exists'] = 'Context Provider with this name already exists.';

core/components/modai/src/ContextProviders/ContextProviderInterface.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,19 @@ public function __construct(modX $modx, array $config = []);
1414
*/
1515
public function provideContext(string $prompt): array;
1616

17-
public static function getConfig(): array;
17+
public static function getConfig(modX $modx): array;
18+
19+
/**
20+
* Internal description
21+
*
22+
* @return string
23+
*/
24+
public static function getDescription(): string;
25+
26+
/**
27+
* The suggested name for the context provider, this will be pre-filled for the user when configuring the context provider.
28+
*
29+
* @return string
30+
*/
31+
public static function getSuggestedName(): string;
1832
}

core/components/modai/src/ContextProviders/Pinecone.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,42 +220,42 @@ private function formatMessage($msg, $data): string
220220
return str_replace($search, $replace, $msg);
221221
}
222222

223-
public static function getConfig(): array
223+
public static function getConfig(modX $modx): array
224224
{
225225
return [
226226
'api_key' => [
227-
'name' => 'API Key',
228-
'description' => 'API Key to access Pinecone',
227+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.api_key'),
228+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.api_key_desc'),
229229
'required' => true,
230230
'type' => 'text-password'
231231
],
232232
'endpoint' => [
233-
'name' => 'API endpoint',
234-
'description' => 'Endpoint of your Pinecone API instance.',
233+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.endpoint'),
234+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.endpoint_desc'),
235235
'required' => true,
236236
'type' => 'textfield'
237237
],
238238
'namespace' => [
239-
'name' => 'Namespace',
240-
'description' => 'Namespace that will be used to store/query your data.',
239+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.namespace'),
240+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.namespace_desc'),
241241
'required' => true,
242242
'type' => 'textfield'
243243
],
244244
'fields' => [
245-
'name' => 'Fields to index',
246-
'description' => 'Comma separated list of fields to index.',
245+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.fields'),
246+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.fields_desc'),
247247
'required' => true,
248248
'type' => 'textfield'
249249
],
250250
'fields_map' => [
251-
'name' => 'Map fields to a different name',
252-
'description' => 'Comma separated list of original_name:new_name pairs',
251+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.fields_map'),
252+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.fields_map_desc'),
253253
'required' => false,
254254
'type' => 'textfield'
255255
],
256256
'context_messages' => [
257-
'name' => 'Context Messages',
258-
'description' => 'Additional context messages that will be put in front of the data from DB. One message per line. Can contain {id} or any {field} (defined in fields config) placeholder, you can also reference a system setting with using ++ as a prefix, for example {++site_url}.',
257+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.context_messages'),
258+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.context_messages_desc'),
259259
'required' => false,
260260
'type' => 'textarea',
261261
'extraProperties' => [
@@ -264,4 +264,14 @@ public static function getConfig(): array
264264
],
265265
];
266266
}
267+
268+
public static function getDescription(): string
269+
{
270+
return 'Pinecone\'s vector database';
271+
}
272+
273+
public static function getSuggestedName(): string
274+
{
275+
return 'pinecone';
276+
}
267277
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function process()
4343
return $this->outputArray(array_map(function($class) {
4444
return [
4545
'class' => $class,
46-
'config' => $class::getConfig(),
46+
'config' => $class::getConfig($this->modx),
47+
'description' => $class::getDescription(),
48+
'suggestedName' => $class::getSuggestedName(),
4749
];
4850
}, $classes), count($classes));
4951
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ public function process()
4343
return $this->outputArray(array_map(function($class) {
4444
return [
4545
'class' => $class,
46-
'config' => $class::getConfig(),
46+
'config' => $class::getConfig($this->modx),
4747
'suggestedName' => $class::getSuggestedName(),
48+
'description' => $class::getDescription(),
4849
];
4950
}, $classes), count($classes));
5051
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function getCompletions(array $data, CompletionsConfig $config): AIRespon
206206

207207
$tools[] = [
208208
'name' => $toolName,
209-
'description' => $toolClass::getDescription(),
209+
'description' => $toolClass::getPrompt(),
210210
'input_schema' => (object)$params,
211211
];
212212
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function getCompletions(array $data, CompletionsConfig $config): AIRespon
174174
'type' => 'function',
175175
'function' => [
176176
'name' => $toolName,
177-
'description' => $toolClass::getDescription(),
177+
'description' => $toolClass::getPrompt(),
178178
'parameters' => (object)$toolClass::getParameters(),
179179
]
180180
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function getCompletions(array $data, CompletionsConfig $config): AIRespon
222222

223223
$tools[] = [
224224
'name' => $toolName,
225-
'description' => $toolClass::getDescription(),
225+
'description' => $toolClass::getPrompt(),
226226
'parameters' => $params,
227227
];
228228
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function getCompletions(array $data, CompletionsConfig $config): AIRespon
168168
'type' => 'function',
169169
'function' => [
170170
'name' => $toolName,
171-
'description' => $toolClass::getDescription(),
171+
'description' => $toolClass::getPrompt(),
172172
'parameters' => (object)$toolClass::getParameters(),
173173
]
174174
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function getCompletions(array $data, CompletionsConfig $config): AIRespon
168168
'type' => 'function',
169169
'function' => [
170170
'name' => $toolName,
171-
'description' => $toolClass::getDescription(),
171+
'description' => $toolClass::getPrompt(),
172172
'parameters' => (object)$toolClass::getParameters(),
173173
]
174174
];

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

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

17-
public static function getDescription(): string
17+
public static function getPrompt(): 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
}
@@ -54,7 +54,7 @@ public static function getParameters(): array
5454
];
5555
}
5656

57-
public static function getConfig(): array
57+
public static function getConfig(modX $modx): array
5858
{
5959
return [];
6060
}
@@ -115,4 +115,9 @@ public static function checkPermissions(modX $modx): bool
115115
{
116116
return $modx->hasPermission('save_category');
117117
}
118+
119+
public static function getDescription(): string
120+
{
121+
return 'Creates a new category';
122+
}
118123
}

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

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

17-
public static function getDescription(): string
17+
public static function getPrompt(): 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
}
@@ -55,7 +55,7 @@ public static function getParameters(): array
5555
];
5656
}
5757

58-
public static function getConfig(): array
58+
public static function getConfig(modX $modx): array
5959
{
6060
return [];
6161
}
@@ -103,4 +103,9 @@ public static function checkPermissions(modX $modx): bool
103103
{
104104
return $modx->hasPermission('save_chunk');
105105
}
106+
107+
public static function getDescription(): string
108+
{
109+
return 'Creates a new chunk';
110+
}
106111
}

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

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

17-
public static function getDescription(): string
17+
public static function getPrompt(): string
1818
{
1919
return "Creates a new resource, or page, on the website. ALWAYS ask for explicit user confirmation in a separate message before calling this function, even if user asks directly to create a resource, ask the user to confirm the resource before calling the tool with the information you intend to use. ";
2020
}
@@ -55,7 +55,7 @@ public static function getParameters(): array
5555
];
5656
}
5757

58-
public static function getConfig(): array
58+
public static function getConfig(modX $modx): array
5959
{
6060
return [];
6161
}
@@ -128,4 +128,9 @@ public static function checkPermissions(modX $modx): bool
128128
{
129129
return $modx->hasPermission('save_document');
130130
}
131+
132+
public static function getDescription(): string
133+
{
134+
return 'Creates a new resource';
135+
}
131136
}

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

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

17-
public static function getDescription(): string
17+
public static function getPrompt(): string
1818
{
1919
return "Creates a new template for the website, which can be assigned to resources to determine how they are rendered in the frontend. Only use when explicitly asked to create a new template, and always check if appropriate templates already exist first. Always ask for explicit user confirmation in a separate message, providing the user with the template name and a summary of what the contents would be, BEFORE calling this function. Do NOT output the full template content. When generating template content you MUST make sure it uses the MODX templating syntax.";
2020
}
@@ -55,7 +55,7 @@ public static function getParameters(): array
5555
];
5656
}
5757

58-
public static function getConfig(): array
58+
public static function getConfig(modX $modx): array
5959
{
6060
return [];
6161
}
@@ -103,4 +103,9 @@ public static function checkPermissions(modX $modx): bool
103103
{
104104
return $modx->hasPermission('save_template');
105105
}
106+
107+
public static function getDescription(): string
108+
{
109+
return 'Creates a new template';
110+
}
106111
}

0 commit comments

Comments
 (0)