Class: Langchain::Tool::Wikipedia

Inherits:
Object
  • Object
show all
Extended by:
Langchain::ToolDefinition
Includes:
DependencyHelper
Defined in:
lib/langchain/tool/wikipedia.rb

Overview

Tool that adds the capability to search using the Wikipedia API

Gem requirements:

gem "wikipedia-client", "~> 1.17.0"

Usage:

wikipedia = Langchain::Tool::Wikipedia.new
wikipedia.execute(input: "The Roman Empire")

Instance Method Summary collapse

Methods included from Langchain::ToolDefinition

define_function, function_schemas, tool_name

Methods included from DependencyHelper

#depends_on

Constructor Details

#initializeWikipedia

Initializes the Wikipedia tool



23
24
25
# File 'lib/langchain/tool/wikipedia.rb', line 23

def initialize
  depends_on "wikipedia-client", req: "wikipedia"
end

Instance Method Details

#execute(input:) ⇒ String

Executes Wikipedia API search and returns the answer

Parameters:

  • input (String)

    search query

Returns:

  • (String)

    Answer



31
32
33
34
35
36
37
# File 'lib/langchain/tool/wikipedia.rb', line 31

def execute(input:)
  Langchain.logger.debug("#{self.class} - Executing \"#{input}\"")

  page = ::Wikipedia.find(input)
  # It would be nice to figure out a way to provide page.content but the LLM token limit is an issue
  page.summary
end