aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/RAGTool.ts
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2024-10-17 10:41:49 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2024-10-17 10:41:49 -0400
commit80d86bd5ae3e1d3dc70e7636f72a872a5fb2f01d (patch)
tree0eaea49f596bd16720f05a6535958ab8270673c8 /src/client/views/nodes/chatbot/tools/RAGTool.ts
parent596502c232ea6b6b88c3c58486e139074ea056ff (diff)
Implemented strict typechecking for tools, specifically tool inputs
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/RAGTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/RAGTool.ts30
1 files changed, 17 insertions, 13 deletions
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<RAGToolParamsType> {
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 {
</follow_up_questions>
</answer>
`,
-
`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<Observation[]> {
+ async execute(args: ParametersType<RAGToolParamsType>): Promise<Observation[]> {
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<Observation[]> {