Class: Pedicab::P
- Inherits:
-
Object
- Object
- Pedicab::P
- Defined in:
- lib/pedicab.rb
Overview
Main conversation interface for AI interactions Provides context management, state tracking, and elegant operator syntax
Instance Attribute Summary collapse
- #context ⇒ Proc, Hash
- #handler ⇒ Proc, Hash
- #last ⇒ Float, ... readonly
- #out ⇒ Float, ... readonly
- #prompt ⇒ Float, ... readonly
- #response ⇒ Float, ... readonly
- #ride ⇒ Float, ... readonly
- #thoughts ⇒ Float, ... readonly
- #time ⇒ Float, ... readonly
- #took ⇒ Float, ... readonly
Instance Method Summary collapse
-
#<<(input) ⇒ Object
Continue an existing conversation with context Maintains previous exchanges and builds upon them.
-
#[](input) ⇒ Object
Start a fresh conversation with the given prompt Clears previous context and begins a new conversation.
-
#handle(&block) ⇒ Proc
Set or execute the response handler.
-
#initialize(k) ⇒ P
constructor
Initialize a new conversation instance.
-
#life ⇒ Float
Calculate total processing time for all requests in the conversation.
-
#reset! ⇒ void
Reset all conversation state, context, and history Clears prompts, responses, timing data, and ride state.
Constructor Details
Instance Attribute Details
#context ⇒ Proc, Hash
48 49 50 |
# File 'lib/pedicab.rb', line 48 def context @context end |
#handler ⇒ Proc, Hash
48 49 50 |
# File 'lib/pedicab.rb', line 48 def handler @handler end |
#last ⇒ Float, ... (readonly)
44 45 46 |
# File 'lib/pedicab.rb', line 44 def last @last end |
#out ⇒ Float, ... (readonly)
44 45 46 |
# File 'lib/pedicab.rb', line 44 def out @out end |
#prompt ⇒ Float, ... (readonly)
44 45 46 |
# File 'lib/pedicab.rb', line 44 def prompt @prompt end |
#response ⇒ Float, ... (readonly)
44 45 46 |
# File 'lib/pedicab.rb', line 44 def response @response end |
#ride ⇒ Float, ... (readonly)
44 45 46 |
# File 'lib/pedicab.rb', line 44 def ride @ride end |
#thoughts ⇒ Float, ... (readonly)
44 45 46 |
# File 'lib/pedicab.rb', line 44 def thoughts @thoughts end |
#time ⇒ Float, ... (readonly)
44 45 46 |
# File 'lib/pedicab.rb', line 44 def time @time end |
#took ⇒ Float, ... (readonly)
44 45 46 |
# File 'lib/pedicab.rb', line 44 def took @took end |
Instance Method Details
#<<(input) ⇒ Object
Continue an existing conversation with context Maintains previous exchanges and builds upon them
124 125 126 127 128 129 |
# File 'lib/pedicab.rb', line 124 def << input @last << @prompt if @prompt @prompt = input think(input) @handler.call(self) end |
#[](input) ⇒ Object
Start a fresh conversation with the given prompt Clears previous context and begins a new conversation
109 110 111 112 113 114 |
# File 'lib/pedicab.rb', line 109 def [] input reset! @prompt = input think(input) @handler.call(self) end |
#handle(&block) ⇒ Proc
Set or execute the response handler
92 93 94 95 96 97 98 99 |
# File 'lib/pedicab.rb', line 92 def handle(&block) @handler = block if @response.length > Pedicab.memory @response.shift @last.shift @thoughts.shift end end |
#life ⇒ Float
Calculate total processing time for all requests in the conversation
138 139 140 141 142 |
# File 'lib/pedicab.rb', line 138 def life a = 0 @time.map { |e| a += e } return a end |
#reset! ⇒ void
This method returns an undefined value.
Reset all conversation state, context, and history Clears prompts, responses, timing data, and ride state
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pedicab.rb', line 70 def reset! @ride.reset! @exe = "" @time = [] @last = [] @response = [] @thoughts = [] @prompt = nil @out = nil @took = 0 end |