UNPKG

@kaibanjs/tools

Version:

A set of tools to work with LLMs and KaibanJS

202 lines (201 loc) 5.46 kB
/** * Exa Search Tool * * This tool integrates with Exa (https://exa.ai/), a search engine for AI that organizes * the web using embeddings. It provides high-quality web data specifically optimized * for AI applications. * * Key features: * - Neural Search: Meaning-based search using embeddings * - Keyword Search: Traditional search capabilities * - Auto Search: Dynamically chooses between neural and keyword * - Category-focused search * - Domain filtering * - Date filtering * - Text filtering */ import { StructuredTool } from '@langchain/core/tools'; import { z } from 'zod'; /** * Structure of an individual search result from Exa * @example * { * title: "Example Article", * url: "https://example.com/article", * snippet: "This is a sample search result...", * publishedDate: "2024-03-20", * author: "John Doe" * } */ type ExaSearchToolResult = { title: string; url: string; snippet: string; publishedDate: string; author: string; }; /** Error message returned when the search fails */ type ExaSearchToolError = string; /** * Response structure from the Exa search API * @example * { * results: [{ * title: "Example Article", * url: "https://example.com/article", * snippet: "This is a sample search result...", * publishedDate: "2024-03-20", * author: "John Doe" * }] * } */ type ExaSearchToolResponse = { [key: string]: any; results: ExaSearchToolResult[]; } | ExaSearchToolError; /** * Type of search to perform * - neural: Semantic search using embeddings * - keyword: Traditional keyword-based search * - auto: Automatically choose between neural and keyword */ type ExaSearchToolType = 'neural' | 'keyword' | 'auto'; /** * Categories that can be used to filter search results */ type ExaSearchToolCategory = 'company' | 'research paper' | 'news' | 'github' | 'tweet' | 'movie' | 'song' | 'personal site' | 'pdf'; /** * Live crawling behavior options * - never: Never perform live crawling * - fallback: Only crawl if cached version isn't available * - always: Always perform a fresh crawl */ type ExaLiveCrawl = 'never' | 'fallback' | 'always'; /** * Configuration for content extraction and processing * @example * { * text: { maxCharacters: 1000, includeHtmlTags: false }, * highlights: { numSentences: 3, highlightsPerUrl: 2, query: "AI technology" }, * summary: { query: "What are the main points?" }, * subpages: 5, * livecrawl: "fallback" * } */ interface ExaContentConfig { text?: { maxCharacters: number; includeHtmlTags: boolean; } | boolean; highlights?: { numSentences: number; highlightsPerUrl: number; query: string; }; summary?: { query: string; } | boolean; subpages?: number; subpageTarget?: number; livecrawl?: ExaLiveCrawl; livecrawlTimeout?: number; } /** * Configuration options for initializing the Exa search tool * @example * { * apiKey: "your-api-key", * type: "neural", * numResults: 5, * category: "news", * includeDomains: ["example.com"], * startPublishedDate: "2024-01-01" * } */ interface ExaSearchToolFields { apiKey: string; type?: ExaSearchToolType; useAutoprompt?: boolean; numResults?: number; category?: ExaSearchToolCategory; startPublishedDate?: string; endPublishedDate?: string; includeDomains?: string[]; excludeDomains?: string[]; includeText?: string[]; excludeText?: string[]; startCrawlDate?: string; endCrawlDate?: string; contents?: ExaContentConfig; } /** * Parameters for performing a search query * @example * { * query: "Latest developments in artificial intelligence" * } */ interface ExaSearchToolParams { query: string; } /** * ExaSearch tool for performing AI-optimized web searches using the Exa API * * @example * ```typescript * const exaSearch = new ExaSearch({ * apiKey: 'your-api-key', * type: 'neural', * numResults: 5, * category: 'news' * }); * * const results = await exaSearch.call({ query: 'Latest AI developments' }); * ``` */ export declare class ExaSearch extends StructuredTool { private apiKey; private type; private useAutoprompt; private category?; private numResults; private includeDomains; private excludeDomains; private startCrawlDate?; private endCrawlDate?; private startPublishedDate?; private endPublishedDate?; private includeText; private excludeText; private contents?; private httpClient; name: string; description: string; schema: z.ZodObject<{ query: z.ZodString; }, "strip", z.ZodTypeAny, { query: string; }, { query: string; }>; /** * Creates a new instance of the ExaSearch tool * * @param fields - Configuration options for the search tool * @throws {Error} If an invalid search type is provided */ constructor(fields: ExaSearchToolFields); /** * Performs a search using the Exa API * * @param input - The search parameters containing the query * @returns A promise that resolves to either search results or an error message * * @example * ```typescript * const results = await exaSearch._call({ query: 'AI technology trends' }); * ``` */ _call(input: ExaSearchToolParams): Promise<ExaSearchToolResponse>; } export {};