diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/chatbot/tools/DictionaryTool.ts | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/src/client/views/nodes/chatbot/tools/DictionaryTool.ts b/src/client/views/nodes/chatbot/tools/DictionaryTool.ts deleted file mode 100644 index 3493f38d7..000000000 --- a/src/client/views/nodes/chatbot/tools/DictionaryTool.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Observation } from '../types/types'; -import { ParametersType, ToolInfo } from '../types/tool_types'; -import { BaseTool } from './BaseTool'; - -const dictionaryToolParams = [ - { - name: 'word', - type: 'string', - description: 'The word to look up in the dictionary.', - required: true, - }, -] as const; - -type DictionaryToolParamsType = typeof dictionaryToolParams; - -const dictionaryToolInfo: ToolInfo<DictionaryToolParamsType> = { - name: 'dictionary', - citationRules: 'No citation needed.', - parameterRules: dictionaryToolParams, - description: 'Fetches the definition of a given word using an open dictionary API.', -}; - -/** - * DictionaryTool is a tool that fetches the definition of a given word using an open dictionary API. - */ -export class DictionaryTool extends BaseTool<DictionaryToolParamsType> { - constructor() { - super(dictionaryToolInfo); - } - - async execute(args: ParametersType<DictionaryToolParamsType>): Promise<Observation[]> { - const url = `https://api.dictionaryapi.dev/api/v2/entries/en/${args.word}`; - - try { - const response = await fetch(url); - const data = await response.json(); - - // Handle cases where the word is not found - if (data.title === 'No Definitions Found') { - return [ - { - type: 'text', - text: `Sorry, I couldn't find a definition for the word "${args.word}".`, - }, - ]; - } - - // Extract the first definition - const definition = data[0]?.meanings[0]?.definitions[0]?.definition; - return [ - { - type: 'text', - text: `The definition of "${args.word}" is: ${definition}`, - }, - ]; - } catch (error) { - return [ - { - type: 'text', - text: `An error occurred while fetching the definition: ${error}`, - }, - ]; - } - } -} |