Class: OmniAI::Tools::BrowserTool
- Inherits:
-
OmniAI::Tool
- Object
- OmniAI::Tool
- OmniAI::Tools::BrowserTool
- Defined in:
- lib/omniai/tools/browser_tool.rb
Overview
A tool for controller a browser.
Defined Under Namespace
Modules: Action
Constant Summary collapse
- ACTIONS =
[ Action::VISIT, Action::PAGE_INSPECT, Action::UI_INSPECT, Action::SELECTOR_INSPECT, Action::CLICK, Action::TEXT_FIELD_SET, Action::SCREENSHOT, ].freeze
Instance Method Summary collapse
- #cleanup! ⇒ Object
- #execute(action:, url: nil, selector: nil, value: nil, context_size: 2, full_html: false, text_content: nil) ⇒ String
-
#initialize(logger:, driver:) ⇒ BrowserTool
constructor
A new instance of BrowserTool.
Constructor Details
#initialize(logger:, driver:) ⇒ BrowserTool
Returns a new instance of BrowserTool.
146 147 148 149 150 |
# File 'lib/omniai/tools/browser_tool.rb', line 146 def initialize(logger:, driver:) super() @logger = logger @driver = driver end |
Instance Method Details
#cleanup! ⇒ Object
152 153 154 |
# File 'lib/omniai/tools/browser_tool.rb', line 152 def cleanup! @driver.close end |
#execute(action:, url: nil, selector: nil, value: nil, context_size: 2, full_html: false, text_content: nil) ⇒ String
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/omniai/tools/browser_tool.rb', line 165 def execute(action:, url: nil, selector: nil, value: nil, context_size: 2, full_html: false, text_content: nil) case action.to_s.downcase when Action::VISIT require_param!(:url, url) visit_tool.execute(url:) when Action::PAGE_INSPECT if full_html page_inspect_tool.execute else page_inspect_tool.execute(summarize: true) end when Action::UI_INSPECT require_param!(:text_content, text_content) inspect_tool.execute(text_content:, selector:, context_size:) when Action::SELECTOR_INSPECT require_param!(:selector, selector) selector_inspect_tool.execute(selector:, context_size:) when Action::CLICK require_param!(:selector, selector) click_tool.execute(selector:) when Action::TEXT_FIELD_SET require_param!(:selector, selector) require_param!(:value, value) text_field_area_set_tool.execute(selector:, text: value) when Action::SCREENSHOT page_screenshot_tool.execute else { error: "Unsupported action: #{action}. Supported actions are: #{ACTIONS.join(', ')}" } end end |