Class: Raix::TranscriptAdapter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_chatObject (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 <<(message_hash)
  case message_hash
  when Array
    # Handle nested arrays (from function dispatch)
    message_hash.each { |msg| self << msg }
  when Hash
    add_message_from_hash(message_hash)
  end
  self
end

#clearObject

Clear all messages



43
44
45
46
47
# File 'lib/raix/transcript_adapter.rb', line 43

def clear
  @ruby_llm_chat.reset_messages!
  @pending_messages.clear
  self
end

#compactObject

Allow iteration



38
39
40
# File 'lib/raix/transcript_adapter.rb', line 38

def compact
  flatten.compact
end

#flattenObject

Return all messages in Raix-compatible format



26
27
28
29
30
# File 'lib/raix/transcript_adapter.rb', line 26

def flatten
  ruby_llm_messages = @ruby_llm_chat.messages.map { |msg| message_to_raix_format(msg) }
  pending = @pending_messages.map { |msg| normalize_message_format(msg) }
  (ruby_llm_messages + pending).flatten
end

#lastObject

Get last message



50
51
52
# File 'lib/raix/transcript_adapter.rb', line 50

def last
  flatten.last
end

#sizeObject 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_aObject

Get all messages including pending ones



33
34
35
# File 'lib/raix/transcript_adapter.rb', line 33

def to_a
  flatten
end