@kaibanjs/tools
Version:
A set of tools to work with LLMs and KaibanJS
117 lines (116 loc) • 4.52 kB
TypeScript
/**
* Pdf Search Tool
*
* This tool is used to perform a RAG (Retrieval-Augmented Generation) search within the content of a text file.
* It allows for semantic searching of a query within a specified text file's content, making it an invaluable resource
* for quickly extracting information or finding specific sections of text based on the query provided.
*
* The tool uses the following components:
* - A Chunker options, 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';
/**
* Input parameters for the PdfSearch tool
* @typedef {Object} PdfSearchParams
* @property {string} query - The question to ask
* @property {string | File} [file] - The pdf file path or file object to process
*/
type PdfSearchParams = {
query: string;
file?: string | File;
};
/**
* Response type for the PdfSearch tool
* @typedef {string} RagToolkitAnswerResponse
* @example
* "The answer to your question is: [answer]"
*/
type RagToolkitAnswerResponse = string;
/**
* Error type for the PdfSearch tool
* @typedef {string} PdfSearchError
* @example
* "ERROR_MISSING_FILE: No pdf file was provided for analysis. Agent should provide valid pdf file in the 'file' field."
*/
type PdfSearchError = string;
/**
* Response type for the PdfSearch tool
* @typedef {RagToolkitAnswerResponse | PdfSearchError} PdfSearchResponse
*/
type PdfSearchResponse = RagToolkitAnswerResponse | PdfSearchError;
/**
* Configuration options for the PdfSearch tool
* @interface PdfSearchFields
* @property {string} OPENAI_API_KEY - The OpenAI API key for authentication
* @property {string | File} [file] - The pdf file path or file object to process
* @property {any} [chunkOptions] - Chunking options for the RAG model
* @property {any} [embeddings] - Embeddings instance for the RAG model
* @property {any} [vectorStore] - Vector store instance for the RAG model
* @property {any} [llmInstance] - LLM instance for the RAG model
* @property {string} [promptQuestionTemplate] - Prompt question template for the RAG model
*/
interface PdfSearchFields {
OPENAI_API_KEY: string;
file?: string | File;
chunkOptions?: any;
embeddings?: any;
vectorStore?: any;
llmInstance?: any;
promptQuestionTemplate?: string;
}
/**
* PdfSearch tool for performing semantic search within a PDF file
*
* This tool allows for semantic searching of a query within the content of a text file.
* It uses the RAGToolkit to perform the search, which includes a Chunker, Embeddings,
* VectorStore, and LLM instance. The tool also supports loading a PDF file from a URL.
*
* The tool supports the following components:
* - A Chunker options, 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
*/
export declare class PdfSearch extends StructuredTool {
private OPENAI_API_KEY;
private file?;
private chunkOptions;
private embeddings;
private vectorStore;
private llmInstance;
private promptQuestionTemplate;
private ragToolkit;
private httpClient;
name: string;
description: string;
schema: z.ZodObject<{
file: z.ZodString;
query: z.ZodString;
}, "strip", z.ZodTypeAny, {
query: string;
file: string;
}, {
query: string;
file: string;
}>;
/**
* Constructor for the PdfSearch tool
* @param {PdfSearchFields} fields - The configuration fields for the tool
*/
constructor(fields: PdfSearchFields);
/**
* Call the PdfSearch tool
* @param {PdfSearchParams} input - The input parameters for the tool
* @returns {Promise<PdfSearchResponse>} The response from the tool
*/
_call(input: PdfSearchParams): Promise<PdfSearchResponse>;
}
export {};