Class: Legion::LLM::Types::Message
- Inherits:
-
Data
- Object
- Data
- Legion::LLM::Types::Message
- Extended by:
- Legion::Logging::Helper
- Defined in:
- lib/legion/llm/types/message.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#conversation_id ⇒ Object
readonly
Returns the value of attribute conversation_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#task_id ⇒ Object
readonly
Returns the value of attribute task_id.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#tool_call_id ⇒ Object
readonly
Returns the value of attribute tool_call_id.
-
#tool_calls ⇒ Object
readonly
Returns the value of attribute tool_calls.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def content @content end |
#conversation_id ⇒ Object (readonly)
Returns the value of attribute conversation_id
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def conversation_id @conversation_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def id @id end |
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def input_tokens @input_tokens end |
#model ⇒ Object (readonly)
Returns the value of attribute model
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def name @name end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def output_tokens @output_tokens end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def parent_id @parent_id end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def provider @provider end |
#role ⇒ Object (readonly)
Returns the value of attribute role
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def role @role end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def seq @seq end |
#status ⇒ Object (readonly)
Returns the value of attribute status
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def status @status end |
#task_id ⇒ Object (readonly)
Returns the value of attribute task_id
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def task_id @task_id end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def @timestamp end |
#tool_call_id ⇒ Object (readonly)
Returns the value of attribute tool_call_id
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def tool_call_id @tool_call_id end |
#tool_calls ⇒ Object (readonly)
Returns the value of attribute tool_calls
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def tool_calls @tool_calls end |
#version ⇒ Object (readonly)
Returns the value of attribute version
9 10 11 |
# File 'lib/legion/llm/types/message.rb', line 9 def version @version end |
Class Method Details
.build(**kwargs) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/legion/llm/types/message.rb', line 17 def self.build(**kwargs) log.debug("[types][message] action=build role=#{kwargs[:role]} id=#{kwargs[:id]}") new( id: kwargs[:id] || "msg_#{SecureRandom.hex(12)}", parent_id: kwargs[:parent_id], role: kwargs[:role]&.to_sym || :user, content: kwargs[:content], tool_calls: kwargs[:tool_calls], tool_call_id: kwargs[:tool_call_id], name: kwargs[:name], status: kwargs.fetch(:status, :created), version: kwargs.fetch(:version, 1), timestamp: kwargs[:timestamp] || Time.now, seq: kwargs[:seq], provider: kwargs[:provider], model: kwargs[:model], input_tokens: kwargs[:input_tokens], output_tokens: kwargs[:output_tokens], conversation_id: kwargs[:conversation_id], task_id: kwargs[:task_id] ) end |
.from_hash(hash) ⇒ Object
40 41 42 43 |
# File 'lib/legion/llm/types/message.rb', line 40 def self.from_hash(hash) hash = hash.transform_keys(&:to_sym) if hash.respond_to?(:transform_keys) build(**hash) end |
.wrap(input) ⇒ Object
45 46 47 48 49 |
# File 'lib/legion/llm/types/message.rb', line 45 def self.wrap(input) return input if input.is_a?(Message) from_hash(input) if input.is_a?(Hash) end |
Instance Method Details
#text ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/legion/llm/types/message.rb', line 51 def text case content when String then content when Array content.select { |b| b.is_a?(Hash) ? b[:type] == :text : b.respond_to?(:text) } .map { |b| b.is_a?(Hash) ? b[:text] : b.text } .join else content.to_s end end |
#to_h ⇒ Object
63 64 65 |
# File 'lib/legion/llm/types/message.rb', line 63 def to_h super.compact end |
#to_provider_hash ⇒ Object
67 68 69 |
# File 'lib/legion/llm/types/message.rb', line 67 def to_provider_hash { role: role.to_s, content: text }.compact end |