Class: Pedicab::Ride

Inherits:
Object
  • Object
show all
Defined in:
lib/pedicab/ride.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(k) ⇒ Ride

Returns a new instance of Ride.



4
5
6
7
8
# File 'lib/pedicab/ride.rb', line 4

def initialize(k)
  @id = k
  @model = ENV['MODEL'] || 'qwen'
  reset!
end

Instance Attribute Details

#model ⇒ Object

Returns the value of attribute model.



3
4
5
# File 'lib/pedicab/ride.rb', line 3

def model
  @model
end

#state ⇒ Object

Returns the value of attribute state.



3
4
5
# File 'lib/pedicab/ride.rb', line 3

def state
  @state
end

Instance Method Details

#[](k) ⇒ Object



40
41
42
# File 'lib/pedicab/ride.rb', line 40

def [] k
  @state[k]
end

#[]=(k, v) ⇒ Object



44
45
46
# File 'lib/pedicab/ride.rb', line 44

def []= k,v
  @state[k] = v
end

#each(&b) ⇒ Object



17
18
19
# File 'lib/pedicab/ride.rb', line 17

def each &b
  @state[:content].split("\n").each { |e| @state[:for] = e; b.call(self) }
end

#go(prompt, &b) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pedicab/ride.rb', line 14

def go(prompt, &b)
  @state[:action] = "respond: #{prompt}"
  rider(role: 'user', model: @model, content: prompt)
  def each &b
    @state[:content].split("\n").each { |e| @state[:for] = e; b.call(self) }
  end
  if block_given?
    b.call(self)
  else
    @state[:content]
  end
end

#if?(condition, &b) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pedicab/ride.rb', line 27

def if?(condition, &b)
  @state[:action] = "gate: #{condition}"
  @state[:yes] = false
  gate_prompt = "If the following statement is true respond 'yes', otherwise respond 'no':\n#{condition}"
  rider(role: 'system', model: @model, content: gate_prompt)
  @state[:yes] = (@state[:content] == 'yes')
  if block_given? && @state[:yes] == true
    b.call(self)
  else
    @state[:yes]
  end
end

#reset! ⇒ Object



10
11
12
# File 'lib/pedicab/ride.rb', line 10

def reset!
  @state = {}
end

#to_h ⇒ Object



48
49
50
# File 'lib/pedicab/ride.rb', line 48

def to_h
  @state
end