Class: Langchain::Tool::Tavily
- Inherits:
-
Object
- Object
- Langchain::Tool::Tavily
- Extended by:
- Langchain::ToolDefinition
- Defined in:
- lib/langchain/tool/tavily.rb
Overview
Instance Method Summary collapse
-
#initialize(api_key:) ⇒ Tavily
constructor
A new instance of Tavily.
-
#search(query:, search_depth: "basic", include_images: false, include_answer: false, include_raw_content: false, max_results: 5, include_domains: [], exclude_domains: []) ⇒ String
Search for data based on a query.
Methods included from Langchain::ToolDefinition
define_function, function_schemas, tool_name
Constructor Details
#initialize(api_key:) ⇒ Tavily
Returns a new instance of Tavily.
29 30 31 |
# File 'lib/langchain/tool/tavily.rb', line 29 def initialize(api_key:) @api_key = api_key end |
Instance Method Details
#search(query:, search_depth: "basic", include_images: false, include_answer: false, include_raw_content: false, max_results: 5, include_domains: [], exclude_domains: []) ⇒ String
Search for data based on a query.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/langchain/tool/tavily.rb', line 45 def search( query:, search_depth: "basic", include_images: false, include_answer: false, include_raw_content: false, max_results: 5, include_domains: [], exclude_domains: [] ) uri = URI("https://api.tavily.com/search") request = Net::HTTP::Post.new(uri) request.content_type = "application/json" request.body = { api_key: @api_key, query: query, search_depth: search_depth, include_images: include_images, include_answer: include_answer, include_raw_content: include_raw_content, max_results: max_results, include_domains: include_domains, exclude_domains: exclude_domains }.to_json response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http| http.request(request) end response.body end |