Class: Nanobot::Agent::Tools::WebSearch
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- Nanobot::Agent::Tools::WebSearch
- Defined in:
- lib/nanobot/agent/tools/web.rb
Overview
Tool for web search using Brave Search API
Constant Summary collapse
- SEARCH_OPEN_TIMEOUT =
10- SEARCH_READ_TIMEOUT =
15
Instance Method Summary collapse
-
#execute(query:, count: 5) ⇒ String
Perform a web search and return formatted results.
-
#initialize(api_key: nil) ⇒ WebSearch
constructor
A new instance of WebSearch.
Constructor Details
#initialize(api_key: nil) ⇒ WebSearch
Returns a new instance of WebSearch.
21 22 23 24 |
# File 'lib/nanobot/agent/tools/web.rb', line 21 def initialize(api_key: nil) super() @api_key = api_key || ENV.fetch('BRAVE_SEARCH_API_KEY', nil) end |
Instance Method Details
#execute(query:, count: 5) ⇒ String
Perform a web search and return formatted results.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nanobot/agent/tools/web.rb', line 30 def execute(query:, count: 5) return 'Error: Brave Search API key not configured' unless @api_key begin response = search(query, count) format_results(response) rescue StandardError => e "Error performing web search: #{e.}" end end |