Class: Kodo::Message

Inherits:
Data
  • Object
show all
Defined in:
lib/kodo/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: SecureRandom.uuid, channel_id:, sender:, content:, timestamp: Time.now, metadata: {}) ⇒ Message

Returns a new instance of Message.



14
15
16
# File 'lib/kodo/message.rb', line 14

def initialize(id: SecureRandom.uuid, channel_id:, sender:, content:, timestamp: Time.now, metadata: {})
  super
end

Instance Attribute Details

#channel_id ⇒ Object (readonly)

Returns the value of attribute channel_id

Returns:

  • (Object) —

    the current value of channel_id



6
7
8
# File 'lib/kodo/message.rb', line 6

def channel_id
  @channel_id
end

#content ⇒ Object (readonly)

Returns the value of attribute content

Returns:

  • (Object) —

    the current value of content



6
7
8
# File 'lib/kodo/message.rb', line 6

def content
  @content
end

#id ⇒ Object (readonly)

Returns the value of attribute id

Returns:

  • (Object) —

    the current value of id



6
7
8
# File 'lib/kodo/message.rb', line 6

def id
  @id
end

#metadata ⇒ Object (readonly)

Returns the value of attribute metadata

Returns:

  • (Object) —

    the current value of metadata



6
7
8
# File 'lib/kodo/message.rb', line 6

def 
  @metadata
end

#sender ⇒ Object (readonly)

Returns the value of attribute sender

Returns:

  • (Object) —

    the current value of sender



6
7
8
# File 'lib/kodo/message.rb', line 6

def sender
  @sender
end

#timestamp ⇒ Object (readonly)

Returns the value of attribute timestamp

Returns:

  • (Object) —

    the current value of timestamp



6
7
8
# File 'lib/kodo/message.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#from_agent? ⇒ Boolean

Returns:

  • (Boolean)


19
# File 'lib/kodo/message.rb', line 19

def from_agent? = sender == :agent

#from_system? ⇒ Boolean

Returns:

  • (Boolean)


20
# File 'lib/kodo/message.rb', line 20

def from_system? = sender == :system

#from_user? ⇒ Boolean

Returns:

  • (Boolean)


18
# File 'lib/kodo/message.rb', line 18

def from_user? = sender == :user

#to_llm_message ⇒ Object

Convert to the format expected by LLM providers



23
24
25
26
# File 'lib/kodo/message.rb', line 23

def to_llm_message
  role = from_user? ? "user" : "assistant"
  { role: role, content: content }
end