aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/dynamic/WordCountTool.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/dynamic/WordCountTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/dynamic/WordCountTool.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/dynamic/WordCountTool.ts b/src/client/views/nodes/chatbot/tools/dynamic/WordCountTool.ts
new file mode 100644
index 000000000..5e15b4795
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/dynamic/WordCountTool.ts
@@ -0,0 +1,33 @@
+import { Observation } from '../../types/types';
+import { ParametersType, ToolInfo } from '../../types/tool_types';
+import { BaseTool } from '../BaseTool';
+
+const wordCountParams = [
+ {
+ name: 'phrase',
+ type: 'string',
+ description: 'The phrase to count words in',
+ required: true
+ }
+ ] as const;
+
+ type WordCountParamsType = typeof wordCountParams;
+
+ const wordCountInfo: ToolInfo<WordCountParamsType> = {
+ name: 'wordcount',
+ description: 'Counts the number of words in a given phrase',
+ citationRules: 'No citation needed.',
+ parameterRules: wordCountParams
+ };
+
+ export class WordCountTool extends BaseTool<WordCountParamsType> {
+ constructor() {
+ super(wordCountInfo);
+ }
+
+ async execute(args: ParametersType<WordCountParamsType>): Promise<Observation[]> {
+ const { phrase } = args;
+ const wordCount = phrase ? phrase.trim().split(/\s+/).length : 0;
+ return [{ type: 'text', text: `Word count: ${wordCount}` }];
+ }
+ } \ No newline at end of file