Class: LLM::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role, content, extra = {}) ⇒ LLM::Message

Parameters:

  • role (Symbol)
  • content (String)
  • extra (Hash) (defaults to: {})


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

def initialize(role, content, extra = {})
  @role = role.to_s
  @content = content
  @extra = extra
end

Instance Attribute Details

#contentString (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/llm/message.rb', line 11

def content
  @content
end

#extraHash (readonly)

Returns:

  • (Hash)


15
16
17
# File 'lib/llm/message.rb', line 15

def extra
  @extra
end

#roleSymbol (readonly)

Returns:

  • (Symbol)


7
8
9
# File 'lib/llm/message.rb', line 7

def role
  @role
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns true when the “other” object has the same role and content

Parameters:

  • other (Object)

    The other object to compare

Returns:

  • (Boolean)

    Returns true when the “other” object has the same role and content



46
47
48
49
50
51
52
# File 'lib/llm/message.rb', line 46

def ==(other)
  if other.respond_to?(:to_h)
    to_h == other.to_h
  else
    false
  end
end

#logprobsOpenStruct

Returns:



30
31
32
33
# File 'lib/llm/message.rb', line 30

def logprobs
  return nil unless extra.key?(:logprobs)
  OpenStruct.from_hash(extra[:logprobs])
end

#to_hHash

Returns:

  • (Hash)


37
38
39
# File 'lib/llm/message.rb', line 37

def to_h
  {role:, content:}
end