langchain.js
    Preparing search index...

    SearchApi Class Definition.

    Provides a wrapper around the SearchApi.

    Ensure you've set the SEARCHAPI_API_KEY environment variable for authentication. You can obtain a free API key from https://www.searchapi.io/.

    const searchApi = new SearchApi("your-api-key", {
    engine: "google_news",
    });
    const agent = RunnableSequence.from([
    ChatPromptTemplate.fromMessages([
    ["ai", "Answer the following questions using a bulleted list markdown format.""],
    ["human", "{input}"],
    ]),
    new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
    (input: BaseMessageChunk) => ({
    log: "test",
    returnValues: {
    output: input,
    },
    }),
    ]);
    const executor = AgentExecutor.fromAgentAndTools({
    agent,
    tools: [searchApi],
    });
    const res = await executor.invoke({
    input: "What's happening in Ukraine today?"",
    });
    console.log(res);

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      Returns SearchApi

    Properties

    apiKey: string
    description: string = "a search engine. useful for when you need to answer questions about current events. input should be a search query."
    name: string = "search"
    params: Partial<SearchApiParameters>

    Methods

    • Calls the SearchAPI.

      Accepts an input query and fetches the result from SearchApi.

      Parameters

      • input: string

        Search query.

      Returns Promise<any>

      • Formatted search results or an error message.

      NOTE: This method is the core search handler and processes various types of search results including Google organic results, videos, jobs, and images.

    • Builds a URL for the SearchApi request.

      Parameters

      • searchQuery: string

      Returns string

      A string representing the built URL.

    • Converts the SearchApi instance to JSON. This method is not implemented and will throw an error if called.

      Returns any

      Throws an error.

    • Returns string