Class: Common::Message
- Inherits:
-
Object
- Object
- Common::Message
- Defined in:
- lib/rubygpt/common/message.rb
Overview
Represents a Message object that is used in OpenAI Chat API requests This object is referenced by both ChatRequester and ChatCompletion objects
Constant Summary collapse
- MESSAGE_REQUEST_KEYS =
The keys that are used in the request body for messages
%i[role content name tool_calls tool_call_id].freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
The contents of the message.
-
#name ⇒ Object
readonly
Provides the model information to differentiate between participants of the same role.
-
#role ⇒ Object
readonly
The role of the author of this message.
-
#tool_call_id ⇒ Object
readonly
Tool call that this message is responding to.
-
#tool_calls ⇒ Object
readonly
The tool calls generated by the model, such as function calls.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(options = {}) ⇒ Message
constructor
Initializes the Message object.
- #json? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Message
Initializes the Message object
32 33 34 35 36 37 38 39 40 |
# File 'lib/rubygpt/common/message.rb', line 32 def initialize( = {}) if .is_a?(String) @role = "system" @content = else () end json_content_parse end |
Instance Attribute Details
#content ⇒ Object (readonly)
The contents of the message.
18 19 20 |
# File 'lib/rubygpt/common/message.rb', line 18 def content @content end |
#name ⇒ Object (readonly)
Provides the model information to differentiate between participants of the same role.
21 22 23 |
# File 'lib/rubygpt/common/message.rb', line 21 def name @name end |
#role ⇒ Object (readonly)
The role of the author of this message. One of: user, assistant, system Default: system
15 16 17 |
# File 'lib/rubygpt/common/message.rb', line 15 def role @role end |
#tool_call_id ⇒ Object (readonly)
Tool call that this message is responding to. (tool msg only)
27 28 29 |
# File 'lib/rubygpt/common/message.rb', line 27 def tool_call_id @tool_call_id end |
#tool_calls ⇒ Object (readonly)
The tool calls generated by the model, such as function calls. (assistant msg only)
24 25 26 |
# File 'lib/rubygpt/common/message.rb', line 24 def tool_calls @tool_calls end |
Instance Method Details
#empty? ⇒ Boolean
46 47 48 |
# File 'lib/rubygpt/common/message.rb', line 46 def empty? content.nil? || content.empty? end |
#json? ⇒ Boolean
42 43 44 |
# File 'lib/rubygpt/common/message.rb', line 42 def json? !!@json_content end |
#to_h ⇒ Object
50 51 52 |
# File 'lib/rubygpt/common/message.rb', line 50 def to_h { role:, content:, name:, tool_calls:, tool_call_id: }.compact end |