Class: Kward::PluginTurnRequest
- Inherits:
-
Object
- Object
- Kward::PluginTurnRequest
- Defined in:
- lib/kward/plugins/turn_request.rb
Overview
Immutable, host-dispatched system instructions for one session turn. Historical records retain the instructions for display, not model replay.
Constant Summary collapse
- MAX_SYSTEM_BYTES =
65_536
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#plugin_id ⇒ Object
readonly
Returns the value of attribute plugin_id.
-
#system ⇒ Object
readonly
Returns the value of attribute system.
Instance Method Summary collapse
- #history_message ⇒ Object
-
#initialize(system:, command:, plugin_id: nil, id: SecureRandom.uuid) ⇒ PluginTurnRequest
constructor
A new instance of PluginTurnRequest.
- #to_s ⇒ Object
Constructor Details
#initialize(system:, command:, plugin_id: nil, id: SecureRandom.uuid) ⇒ PluginTurnRequest
Returns a new instance of PluginTurnRequest.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kward/plugins/turn_request.rb', line 11 def initialize(system:, command:, plugin_id: nil, id: SecureRandom.uuid) unless system.is_a?(String) && system.valid_encoding? && !system.strip.empty? && system.bytesize <= MAX_SYSTEM_BYTES raise ArgumentError, "System instructions must be nonblank text of at most #{MAX_SYSTEM_BYTES} bytes" end @system = system.dup.freeze @command = command.to_s.dup.freeze @plugin_id = plugin_id&.to_s&.dup&.freeze @id = id.to_s.dup.freeze freeze end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
9 10 11 |
# File 'lib/kward/plugins/turn_request.rb', line 9 def command @command end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/kward/plugins/turn_request.rb', line 9 def id @id end |
#plugin_id ⇒ Object (readonly)
Returns the value of attribute plugin_id.
9 10 11 |
# File 'lib/kward/plugins/turn_request.rb', line 9 def plugin_id @plugin_id end |
#system ⇒ Object (readonly)
Returns the value of attribute system.
9 10 11 |
# File 'lib/kward/plugins/turn_request.rb', line 9 def system @system end |
Instance Method Details
#history_message ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/kward/plugins/turn_request.rb', line 27 def { role: "user", content: "A plugin requested a system-instruction turn. Those instructions are not active in later turns.", display_content: to_s, plugin_system_turn: { id: id, command: command, plugin_id: plugin_id, system: system, scope: "turn" } } end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/kward/plugins/turn_request.rb', line 23 def to_s "/#{command} #{system}" end |