UNPKG

@kaibanjs/tools

Version:

A set of tools to work with LLMs and KaibanJS

120 lines (119 loc) 3.39 kB
/** * Serper * * This tool integrates with Serper (https://serper.dev/), a Google Search API service * that provides access to Google Search results programmatically. * * Serper allows you to perform various types of Google searches including web search, * image search, news search, and more, making it ideal for AI applications that need * real-time information from the web. * * Available search types: * - "search" (default): For general search queries * - "images": For image search * - "videos": For video search * - "places": For location-based search * - "maps": For map search * - "news": For news search * - "shopping": For shopping search * - "scholar": For academic publications search * - "patents": For patents search * - "webpage": For scraping webpages * Note: The Scraper option is in Beta and may be subject to changes * * Key features: * - Multiple search types * - Clean, structured JSON responses * - High-performance API with good uptime * - Webpage scraping capability (Beta) * * For more information about Serper, visit: https://serper.dev/ */ import { StructuredTool } from '@langchain/core/tools'; import { z } from 'zod'; /** * Type for the search type in Serper * @typedef {string} SerperSearchType * @example * "search" */ type SerperSearchType = 'search' | 'images' | 'videos' | 'places' | 'maps' | 'news' | 'shopping' | 'scholar' | 'patents' | 'webpage'; /** * Type for the parameters in Serper * @typedef {url: string} SerperWebpageParams * @example * { * url: "https://example.com" */ type SerperWebpageParams = { url: string; }; /** * Type for the parameters in Serper * @typedef {query: string} SerperQueryParams * @example * { * query: "search query" */ type SerperQueryParams = { query: string; }; /** * Type for the parameters in Serper * @typedef {SerperWebpageParams | SerperQueryParams} SerperParams * @example * { * url: "https://example.com" */ type SerperParams = SerperWebpageParams | SerperQueryParams; /** * Type for the response in Serper * @typedef {Record<string, any>} SerperApiResponse * @example * { * url: "https://example.com" */ type SerperApiResponse = Record<string, any>; /** * Type for the error in Serper * @typedef {string} SerperError * @example * "API request failed: Client Error (404)" */ type SerperError = string; /** * Type for the response in Serper * @typedef {SerperApiResponse | SerperError} SerperResponse * @example * { * url: "https://example.com" */ type SerperResponse = SerperApiResponse | SerperError; /** * Configuration options for the Serper tool * @interface SerperFields * @property {string} apiKey - The API key for the Serper tool * @property {SerperSearchType} [type] - The type of search to perform * @property {Record<string, any>} [params] - Additional parameters for the search */ interface SerperFields { apiKey: string; type?: SerperSearchType; params?: Record<string, any>; } /** * Serper tool for performing Google searches * @extends {StructuredTool} */ export declare class Serper extends StructuredTool { private apiKey; private params; private type; private httpClient; name: string; description: string; schema: z.ZodObject<any>; constructor(fields: SerperFields); _call(input: SerperParams): Promise<SerperResponse>; } export {};