Class: LightGptProxy::SchemaDefaultsApplier
- Inherits:
-
Object
- Object
- LightGptProxy::SchemaDefaultsApplier
- Defined in:
- lib/light_gpt_proxy/schema_defaults_applier.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
-
.ensure_system_presence(messages, defaults) ⇒ Object
helper method to ensure that the system message is present in the messages array only for completions endpoint.
Instance Method Summary collapse
-
#initialize(schema) ⇒ SchemaDefaultsApplier
constructor
A new instance of SchemaDefaultsApplier.
- #perform(payload) ⇒ Object (also: #[])
Constructor Details
#initialize(schema) ⇒ SchemaDefaultsApplier
Returns a new instance of SchemaDefaultsApplier.
7 8 9 |
# File 'lib/light_gpt_proxy/schema_defaults_applier.rb', line 7 def initialize(schema) @schema = schema end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/light_gpt_proxy/schema_defaults_applier.rb', line 5 def payload @payload end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/light_gpt_proxy/schema_defaults_applier.rb', line 5 def schema @schema end |
Class Method Details
.ensure_system_presence(messages, defaults) ⇒ Object
helper method to ensure that the system message is present in the messages array only for completions endpoint
20 21 22 23 24 25 26 27 28 |
# File 'lib/light_gpt_proxy/schema_defaults_applier.rb', line 20 def self.ensure_system_presence(, defaults) raise TypeError, "messages cannot be #{.class.name}" unless .is_a?(Array) return if defaults.nil? raise TypeError, "defaults cannot be #{defaults.class.name}" unless defaults.is_a?(Hash) return if .any? { || ['role'] == 'system' } .unshift(defaults) end |
Instance Method Details
#perform(payload) ⇒ Object Also known as: []
11 12 13 14 15 |
# File 'lib/light_gpt_proxy/schema_defaults_applier.rb', line 11 def perform(payload) @payload = payload fill_defaults_recursive(schema, payload) payload end |