Class: SmartPrompt::Message
- Inherits:
-
Object
- Object
- SmartPrompt::Message
- Defined in:
- lib/smart_prompt/message.rb
Overview
Message represents a single message in a conversation history It contains role, content, timestamp, and metadata
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#importance_score ⇒ Object
Returns the value of attribute importance_score.
-
#is_summary ⇒ Object
Returns the value of attribute is_summary.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#token_count ⇒ Object
readonly
Returns the value of attribute token_count.
Instance Method Summary collapse
-
#calculate_tokens(counter) ⇒ Object
Calculate token count using provided counter.
-
#initialize(data) ⇒ Message
constructor
A new instance of Message.
-
#system_message? ⇒ Boolean
Check if this is a system message.
-
#to_h ⇒ Object
Convert message to hash format.
Constructor Details
#initialize(data) ⇒ Message
Returns a new instance of Message.
10 11 12 13 14 15 16 17 18 |
# File 'lib/smart_prompt/message.rb', line 10 def initialize(data) @role = data[:role] || data["role"] @content = data[:content] || data["content"] @timestamp = (data[:timestamp] || data["timestamp"]) @metadata = data[:metadata] || data["metadata"] || {} @token_count = nil # Lazy calculation @importance_score = data[:importance_score] || data["importance_score"] @is_summary = data[:is_summary] || data["is_summary"] || false end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/smart_prompt/message.rb', line 7 def content @content end |
#importance_score ⇒ Object
Returns the value of attribute importance_score.
8 9 10 |
# File 'lib/smart_prompt/message.rb', line 8 def importance_score @importance_score end |
#is_summary ⇒ Object
Returns the value of attribute is_summary.
8 9 10 |
# File 'lib/smart_prompt/message.rb', line 8 def is_summary @is_summary end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/smart_prompt/message.rb', line 7 def @metadata end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
7 8 9 |
# File 'lib/smart_prompt/message.rb', line 7 def role @role end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/smart_prompt/message.rb', line 7 def @timestamp end |
#token_count ⇒ Object (readonly)
Returns the value of attribute token_count.
7 8 9 |
# File 'lib/smart_prompt/message.rb', line 7 def token_count @token_count end |
Instance Method Details
#calculate_tokens(counter) ⇒ Object
Calculate token count using provided counter
21 22 23 |
# File 'lib/smart_prompt/message.rb', line 21 def calculate_tokens(counter) @token_count ||= counter.count(@content) end |
#system_message? ⇒ Boolean
Check if this is a system message
26 27 28 |
# File 'lib/smart_prompt/message.rb', line 26 def @role == "system" || @role == :system end |
#to_h ⇒ Object
Convert message to hash format
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/smart_prompt/message.rb', line 31 def to_h { role: @role, content: @content, timestamp: @timestamp.iso8601, metadata: @metadata, importance_score: @importance_score, is_summary: @is_summary } end |