Class: Charai::Driver
- Inherits:
-
Capybara::Driver::Base
- Object
- Capybara::Driver::Base
- Charai::Driver
- Defined in:
- lib/charai/driver.rb
Instance Attribute Summary collapse
-
#additional_instruction ⇒ Object
writeonly
Sets the attribute additional_instruction.
-
#callback ⇒ Object
writeonly
Sets the attribute callback.
-
#introduction ⇒ Object
writeonly
Sets the attribute introduction.
Instance Method Summary collapse
- #<<(text) ⇒ Object
-
#initialize(_app, **options) ⇒ Driver
constructor
A new instance of Driver.
- #last_message ⇒ Object
- #needs_server? ⇒ Boolean
- #reset! ⇒ Object
- #visit(path) ⇒ Object
- #wait? ⇒ Boolean
Constructor Details
#initialize(_app, **options) ⇒ Driver
Returns a new instance of Driver.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/charai/driver.rb', line 5 def initialize(_app, **) @openai_configuration = [:openai_configuration] unless @openai_configuration raise ArgumentError, "driver_options[:openai_configuration] is required" end @headless = [:headless] @callback = [:callback] @introduction = [:introduction] @debug_protocol = %w[1 true].include?(ENV['DEBUG']) end |
Instance Attribute Details
#additional_instruction=(value) ⇒ Object (writeonly)
Sets the attribute additional_instruction
16 17 18 |
# File 'lib/charai/driver.rb', line 16 def additional_instruction=(value) @additional_instruction = value end |
#callback=(value) ⇒ Object (writeonly)
Sets the attribute callback
16 17 18 |
# File 'lib/charai/driver.rb', line 16 def callback=(value) @callback = value end |
#introduction=(value) ⇒ Object (writeonly)
Sets the attribute introduction
16 17 18 |
# File 'lib/charai/driver.rb', line 16 def introduction=(value) @introduction = value end |
Instance Method Details
#<<(text) ⇒ Object
21 22 23 |
# File 'lib/charai/driver.rb', line 21 def <<(text) agent << text end |
#last_message ⇒ Object
25 26 27 |
# File 'lib/charai/driver.rb', line 25 def agent. end |
#needs_server? ⇒ Boolean
19 |
# File 'lib/charai/driver.rb', line 19 def needs_server?; true; end |
#reset! ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/charai/driver.rb', line 29 def reset! @browsing_context&.close @browsing_context = nil @browser&.close @browser = nil @openai_chat&.clear @agent = nil @additional_instruction = nil end |
#visit(path) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/charai/driver.rb', line 39 def visit(path) host = Capybara.app_host || Capybara.default_host url = if host Addressable::URI.parse(host) + path else path end browsing_context.navigate(url) end |
#wait? ⇒ Boolean
18 |
# File 'lib/charai/driver.rb', line 18 def wait?; false; end |