@kaibanjs/tools
Version:
A set of tools to work with LLMs and KaibanJS
110 lines (109 loc) • 3.74 kB
TypeScript
/**
* Website Search Tool
*
* This tool is specifically crafted for conducting semantic searches within the content of a particular website.
* Leveraging a Retrieval-Augmented Generation (RAG) model, it navigates through the information provided on a given URL.
* Users have the flexibility to either initiate a search across any website known or discovered during its usage or to
* concentrate the search on a predefined, specific website.
*
* The tool uses the following components:
* - A RAG Toolkit instance, which handles the RAG process
* - 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';
/**
* Type for the parameters in WebsiteSearch
* @typedef {string} WebsiteSearchParams
* @example
* {
* query: "What is the main idea of the website?"
* url: "https://example.com",
*/
type WebsiteSearchParams = {
query: string;
url?: string;
};
/**
* Response type for the WebsiteSearch tool
* @typedef {string} RagToolkitAnswerResponse
* @example
* "The answer to your question is: [answer]"
*/
type RagToolkitAnswerResponse = string;
/**
* Error type for the WebsiteSearch tool
* @typedef {string} WebsiteSearchError
* @example
* "ERROR_MISSING_URL: No url was provided for analysis. Agent should provide valid url in the 'url' field."
*/
type WebsiteSearchError = string;
/**
* Type for the response from the WebsiteSearch tool
* @typedef {RagToolkitAnswerResponse | WebsiteSearchError} WebsiteSearchResponse
* @example
* "The answer to your question is: [answer]"
*/
type WebsiteSearchResponse = RagToolkitAnswerResponse | WebsiteSearchError;
/**
* Interface for the WebsiteSearch tool
* @typedef {Object} WebsiteSearchFields
* @property {string} OPENAI_API_KEY - The OpenAI API key
* @property {string} [url - The URL to process
*/
interface WebsiteSearchFields {
OPENAI_API_KEY: string;
url?: string;
chunkOptions?: {
chunkSize: number;
chunkOverlap: number;
};
embeddings?: OpenAIEmbeddings;
vectorStore?: MemoryVectorStore;
llmInstance?: ChatOpenAI;
promptQuestionTemplate?: string;
}
/**
* WebsiteSearch tool class
* @extends StructuredTool
*/
export declare class WebsiteSearch extends StructuredTool {
private OPENAI_API_KEY;
private url?;
private chunkOptions?;
private embeddings?;
private vectorStore?;
private llmInstance?;
private promptQuestionTemplate?;
private ragToolkit;
name: string;
description: string;
schema: z.ZodObject<{
url: z.ZodString;
query: z.ZodString;
}, "strip", z.ZodTypeAny, {
url: string;
query: string;
}, {
url: string;
query: string;
}>;
/**
* @param {WebsiteSearchFields} fields - The fields for the WebsiteSearch tool
*/
constructor(fields: WebsiteSearchFields);
/**
* @param {WebsiteSearchParams} input - The input for the WebsiteSearch tool
* @returns {Promise<WebsiteSearchResponse>} The response from the WebsiteSearch tool
*/
_call(input: WebsiteSearchParams): Promise<WebsiteSearchResponse>;
}
export {};