From 80d86bd5ae3e1d3dc70e7636f72a872a5fb2f01d Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Thu, 17 Oct 2024 10:41:49 -0400 Subject: Implemented strict typechecking for tools, specifically tool inputs --- src/client/views/nodes/chatbot/tools/RAGTool.ts | 30 ++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/client/views/nodes/chatbot/tools/RAGTool.ts') diff --git a/src/client/views/nodes/chatbot/tools/RAGTool.ts b/src/client/views/nodes/chatbot/tools/RAGTool.ts index 4babf540a..482069f36 100644 --- a/src/client/views/nodes/chatbot/tools/RAGTool.ts +++ b/src/client/views/nodes/chatbot/tools/RAGTool.ts @@ -1,21 +1,26 @@ -import { O } from '@fullcalendar/core/internal-common'; import { Networking } from '../../../../Network'; import { Observation, RAGChunk } from '../types/types'; +import { ParametersType } from './ToolTypes'; import { Vectorstore } from '../vectorstore/Vectorstore'; import { BaseTool } from './BaseTool'; -export class RAGTool extends BaseTool { +const ragToolParams = [ + { + name: 'hypothetical_document_chunk', + type: 'string', + description: "A detailed prompt representing an ideal chunk to embed and compare against document vectors to retrieve the most relevant content for answering the user's query.", + required: true, + }, +] as const; + +type RAGToolParamsType = typeof ragToolParams; + +export class RAGTool extends BaseTool { constructor(private vectorstore: Vectorstore) { super( 'rag', 'Perform a RAG search on user documents', - { - hypothetical_document_chunk: { - type: 'string', - description: "A detailed prompt representing an ideal chunk to embed and compare against document vectors to retrieve the most relevant content for answering the user's query.", - required: 'true', - }, - }, + ragToolParams, ` When using the RAG tool, the structure must adhere to the format described in the ReAct prompt. Below are additional guidelines specifically for RAG-based responses: @@ -52,15 +57,14 @@ export class RAGTool extends BaseTool { `, - `Performs a RAG (Retrieval-Augmented Generation) search on user documents and returns a set of document chunks (text or images) to provide a grounded response based on user documents.` ); } - async execute(args: { hypothetical_document_chunk: string }): Promise { + async execute(args: ParametersType): Promise { const relevantChunks = await this.vectorstore.retrieve(args.hypothetical_document_chunk); - const formatted_chunks = await this.getFormattedChunks(relevantChunks); - return formatted_chunks; + const formattedChunks = await this.getFormattedChunks(relevantChunks); + return formattedChunks; } async getFormattedChunks(relevantChunks: RAGChunk[]): Promise { -- cgit v1.2.3-70-g09d2