Class: Raix::MessageAdapters::Base
- Inherits:
-
Object
- Object
- Raix::MessageAdapters::Base
- Defined in:
- lib/raix/message_adapters/base.rb
Overview
Transforms messages into the format expected by the OpenAI API
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(context) ⇒ Base
constructor
A new instance of Base.
- #transform(message) ⇒ Object
Constructor Details
#initialize(context) ⇒ Base
13 14 15 |
# File 'lib/raix/message_adapters/base.rb', line 13 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
9 10 11 |
# File 'lib/raix/message_adapters/base.rb', line 9 def context @context end |
Instance Method Details
#transform(message) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/raix/message_adapters/base.rb', line 17 def transform() return if [:role].present? if [:function].present? { role: "assistant", name: .dig(:function, :name), content: .dig(:function, :arguments).to_json } elsif [:result].present? { role: "function", name: [:name], content: [:result] } else content() end end |