langchain.js
    Preparing search index...

    Wikipedia query tool integration.

    Setup: Install @langchain/community. You'll also need an API key.

    npm install @langchain/community
    
    Instantiate
    import { WikipediaQueryRun } from "@langchain/community/tools/wikipedia_query_run";

    const tool = new WikipediaQueryRun({
    topKResults: 3,
    maxDocContentLength: 4000,
    });

    Invocation
    await tool.invoke("what is the current weather in sf?");
    

    Invocation with tool call
    // This is usually generated by a model, but we'll create a tool call directly for demo purposes.
    const modelGeneratedToolCall = {
    args: {
    input: "what is the current weather in sf?",
    },
    id: "tool_call_id",
    name: tool.name,
    type: "tool_call",
    };
    await tool.invoke(modelGeneratedToolCall);
    ToolMessage {
      "content": "...",
      "name": "wikipedia-api",
      "additional_kwargs": {},
      "response_metadata": {},
      "tool_call_id": "tool_call_id"
    }
    

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    baseUrl: string = "https://en.wikipedia.org/w/api.php"
    description: string = "A tool for interacting with and fetching data from the Wikipedia API."
    maxDocContentLength: number = 4000
    name: string = "wikipedia-api"
    topKResults: number = 3

    Methods

    • Parameters

      • query: string

      Returns Promise<string>

    • Builds a URL for the Wikipedia API using the provided parameters.

      Type Parameters

      • P extends UrlParameters

      Parameters

      • parameters: P

        The parameters to be used in building the URL.

      Returns string

      A string representing the built URL.

    • Fetches the content of a specific Wikipedia page. It returns the extracted content as a string.

      Parameters

      • page: string

        The specific Wikipedia page to fetch its content.

      • redirect: boolean = true

        A boolean value to indicate whether to redirect or not.

      Returns Promise<string>

      The extracted content of the specific Wikipedia page as a string.

    • Returns string