Class: Charai::Driver

Inherits:
Capybara::Driver::Base
  • Object
show all
Defined in:
lib/charai/driver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, **options)
  @openai_configuration = options[:openai_configuration]
  unless @openai_configuration
    raise ArgumentError, "driver_options[:openai_configuration] is required"
  end
  @headless = options[:headless]
  @callback = options[:callback]
  @introduction = options[:introduction]
  @debug_protocol = %w[1 true].include?(ENV['DEBUG'])
end

Instance Attribute Details

#additional_instruction=(value) ⇒ Object (writeonly)

Sets the attribute additional_instruction

Parameters:

  • value

    the value to set the attribute additional_instruction to.



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

Parameters:

  • value

    the value to set the attribute callback to.



16
17
18
# File 'lib/charai/driver.rb', line 16

def callback=(value)
  @callback = value
end

#introduction=(value) ⇒ Object (writeonly)

Sets the attribute introduction

Parameters:

  • value

    the value to set the attribute introduction to.



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_messageObject



25
26
27
# File 'lib/charai/driver.rb', line 25

def last_message
  agent.last_message
end

#needs_server?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


18
# File 'lib/charai/driver.rb', line 18

def wait?; false; end