blob: 5e15b4795a6a6353ff464143fe78c35de3edaa92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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}` }];
}
}
|