@kaibanjs/tools
Version:
A set of tools to work with LLMs and KaibanJS
106 lines (105 loc) • 3.79 kB
TypeScript
/**
* Simple RAG Tool
*
* This tool integrates with various components from the langchain library to provide
* a simple interface for asking questions and retrieving answers using the Retrieval-Augmented Generation (RAG) approach.
*
* The tool uses the following components:
* - A RAG Toolkit instance, which handles the RAG process
* - A Loader instance, which loads and processes documents for the RAG model
* - A Chunker instance, which chunks and processes text for the RAG model
* - An Embeddings instance, which handles embeddings for the RAG model
* - A VectorStore instance, which stores vectors for the RAG model
* - An LLM instance, which handles the language model for the RAG model
* - A promptQuestionTemplate, which defines the template for asking questions
* - An OpenAI API key, which is used for interacting with the OpenAI API
*/
import { StructuredTool } from '@langchain/core/tools';
import { z } from 'zod';
import { OpenAIEmbeddings } from '@langchain/openai';
import { MemoryVectorStore } from 'langchain/vectorstores/memory';
import { ChatOpenAI } from '@langchain/openai';
import { VectorStoreRetrieverInput } from '@langchain/core/vectorstores';
declare const SimpleRAGRetrieveSchema: z.ZodObject<{
query: z.ZodString;
}, "strip", z.ZodTypeAny, {
query: string;
}, {
query: string;
}>;
/**
* Type for the response in SimpleRAG
* @typedef {string} RagToolkitAnswerResponse
* @example
* "The answer to your question is: [answer]"
*/
type RagToolkitAnswerResponse = string;
/**
* Type for the error in SimpleRAG
* @typedef {string} SimpleRAGError
* @example
* "ERROR_MISSING_CONTENT: No text content was provided for analysis. Agent should provide content in the 'content' field."
*/
type SimpleRAGError = string;
/**
* Type for the response in SimpleRAG
* @typedef {RagToolkitAnswerResponse | SimpleRAGError} SimpleRAGResponse
* @example
* "The answer to your question is: [answer]"
*/
type SimpleRAGRetrieveResponse = RagToolkitAnswerResponse | SimpleRAGError;
/**
* Configuration options for the SimpleRAG tool
* @interface SimpleRAGFields
* @property {string} OPENAI_API_KEY - The OpenAI API key for authentication
* @property {string} [content] - The content text to process
* @property {any} [chunkOptions] - Chunking options for the RAG model
* @property {any} [embeddings] - Embeddings instance for the RAG model
*/
interface SimpleRAGRetrieveFields {
OPENAI_API_KEY: string;
chunkOptions?: {
chunkSize: number;
chunkOverlap: number;
};
embeddings?: OpenAIEmbeddings;
vectorStore: MemoryVectorStore;
llmInstance?: ChatOpenAI;
retrieverOptions?: VectorStoreRetrieverInput<MemoryVectorStore>;
promptQuestionTemplate?: string;
}
/**
* SimpleRAG tool class
* @extends StructuredTool
*/
export declare class SimpleRAGRetrieve extends StructuredTool {
private OPENAI_API_KEY;
private chunkOptions?;
private embeddings?;
private vectorStore;
private llmInstance?;
private retrieverOptions?;
private promptQuestionTemplate?;
private ragToolkit;
name: string;
description: string;
schema: z.ZodObject<{
query: z.ZodString;
}, "strip", z.ZodTypeAny, {
query: string;
}, {
query: string;
}>;
/**
* Constructor for the SimpleRAG tool
* @param {SimpleRAGFields} fields - The configuration fields for the tool
*/
constructor(fields: SimpleRAGRetrieveFields);
/**
* Call the SimpleRAG tool
* @param {SimpleRAGRetrieveSchema} input - The input parameters for the tool
* @returns {Promise<SimpleRAGResponse>} The response from the tool
*/
_call(input: z.infer<typeof SimpleRAGRetrieveSchema>): Promise<SimpleRAGRetrieveResponse>;
}
export {};