Class: RubyCode::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycode/value_objects.rb

Overview

Represents a conversation message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role:, content:, tool_calls: nil) ⇒ Message

Returns a new instance of Message.



8
9
10
11
12
13
# File 'lib/rubycode/value_objects.rb', line 8

def initialize(role:, content:, tool_calls: nil)
  @role = role
  @content = content
  @tool_calls = tool_calls
  @timestamp = Time.now
end

Instance Attribute Details

#content ⇒ Object (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/rubycode/value_objects.rb', line 6

def content
  @content
end

#role ⇒ Object (readonly)

Returns the value of attribute role.



6
7
8
# File 'lib/rubycode/value_objects.rb', line 6

def role
  @role
end

#timestamp ⇒ Object (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/rubycode/value_objects.rb', line 6

def timestamp
  @timestamp
end

#tool_calls ⇒ Object (readonly)

Returns the value of attribute tool_calls.



6
7
8
# File 'lib/rubycode/value_objects.rb', line 6

def tool_calls
  @tool_calls
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
25
26
# File 'lib/rubycode/value_objects.rb', line 21

def ==(other)
  other.is_a?(Message) &&
    role == other.role &&
    content == other.content &&
    tool_calls == other.tool_calls
end

#to_h ⇒ Object



15
16
17
18
19
# File 'lib/rubycode/value_objects.rb', line 15

def to_h
  hash = { role: role, content: content }
  hash[:tool_calls] = tool_calls if tool_calls && !tool_calls.empty?
  hash
end