Class: Raix::TranscriptAdapter
- Inherits:
-
Object
- Object
- Raix::TranscriptAdapter
- Defined in:
- lib/raix/transcript_adapter.rb
Overview
Adapter to convert between Raix’s transcript array format and RubyLLM’s Message objects
Instance Attribute Summary collapse
-
#ruby_llm_chat ⇒ Object
readonly
Returns the value of attribute ruby_llm_chat.
Instance Method Summary collapse
-
#<<(message_hash) ⇒ Object
Add a message in Raix format (hash) to the transcript.
-
#clear ⇒ Object
Clear all messages.
-
#compact ⇒ Object
Allow iteration.
-
#flatten ⇒ Object
Return all messages in Raix-compatible format.
-
#initialize(ruby_llm_chat) ⇒ TranscriptAdapter
constructor
A new instance of TranscriptAdapter.
-
#last ⇒ Object
Get last message.
-
#size ⇒ Object
(also: #length)
Get size of transcript.
-
#to_a ⇒ Object
Get all messages including pending ones.
Constructor Details
#initialize(ruby_llm_chat) ⇒ TranscriptAdapter
Returns a new instance of TranscriptAdapter.
8 9 10 11 |
# File 'lib/raix/transcript_adapter.rb', line 8 def initialize(ruby_llm_chat) @ruby_llm_chat = ruby_llm_chat @pending_messages = [] end |
Instance Attribute Details
#ruby_llm_chat ⇒ Object (readonly)
Returns the value of attribute ruby_llm_chat.
6 7 8 |
# File 'lib/raix/transcript_adapter.rb', line 6 def ruby_llm_chat @ruby_llm_chat end |
Instance Method Details
#<<(message_hash) ⇒ Object
Add a message in Raix format (hash) to the transcript
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/raix/transcript_adapter.rb', line 14 def <<() case when Array # Handle nested arrays (from function dispatch) .each { |msg| self << msg } when Hash () end self end |
#clear ⇒ Object
Clear all messages
43 44 45 46 47 |
# File 'lib/raix/transcript_adapter.rb', line 43 def clear @ruby_llm_chat. @pending_messages.clear self end |
#compact ⇒ Object
Allow iteration
38 39 40 |
# File 'lib/raix/transcript_adapter.rb', line 38 def compact flatten.compact end |
#flatten ⇒ Object
Return all messages in Raix-compatible format
26 27 28 29 30 |
# File 'lib/raix/transcript_adapter.rb', line 26 def flatten = @ruby_llm_chat..map { |msg| (msg) } pending = @pending_messages.map { |msg| (msg) } ( + pending).flatten end |
#last ⇒ Object
Get last message
50 51 52 |
# File 'lib/raix/transcript_adapter.rb', line 50 def last flatten.last end |
#size ⇒ Object Also known as: length
Get size of transcript
55 56 57 |
# File 'lib/raix/transcript_adapter.rb', line 55 def size flatten.size end |
#to_a ⇒ Object
Get all messages including pending ones
33 34 35 |
# File 'lib/raix/transcript_adapter.rb', line 33 def to_a flatten end |