Class: OmniAI::Context
- Inherits:
-
Object
- Object
- OmniAI::Context
- Defined in:
- lib/omniai/context.rb
Overview
Used to handle the setup of serializer / deserializer required per provide (e.g. Anthropic / Google / etc).
Usage:
OmniAI::Context.build do |context|
context.serializers[:prompt] = (prompt, context:) -> { ... }
context.serializers[:message] = (prompt, context:) -> { ... }
context.serializers[:file] = (prompt, context:) -> { ... }
context.serializers[:text] = (prompt, context:) -> { ... }
context.serializers[:url] = (prompt, context:) -> { ... }
context.deserializers[:prompt] = (data, context:) -> { Prompt.new(...) }
context.deserializers[:message] = (data, context:) -> { Message.new(...) }
context.deserializers[:file] = (data, context:) -> { File.new(...) }
context.deserializers[:text] = (data, context:) -> { Text.new(...) }
context.deserializers[:url] = (data, context:) -> { URL.new(...) }
end
Instance Attribute Summary collapse
- #deserializers ⇒ Hash readonly
- #serializers ⇒ Hash
Class Method Summary collapse
Instance Method Summary collapse
Constructor Details
#initialize ⇒ Context
38 39 40 41 |
# File 'lib/omniai/context.rb', line 38 def initialize @serializers = {} @deserializers = {} end |
Instance Attribute Details
#deserializers ⇒ Hash (readonly)
25 26 27 |
# File 'lib/omniai/context.rb', line 25 def deserializers @deserializers end |
#serializers ⇒ Hash
22 23 24 |
# File 'lib/omniai/context.rb', line 22 def serializers @serializers end |
Class Method Details
.build {|context| ... } ⇒ Context
31 32 33 34 35 |
# File 'lib/omniai/context.rb', line 31 def self.build(&block) new.tap do |context| block&.call(context) end end |
Instance Method Details
#deserializer(name) ⇒ Proc?
51 52 53 |
# File 'lib/omniai/context.rb', line 51 def deserializer(name) @deserializers[name] end |
#serializer(name) ⇒ Proc?
45 46 47 |
# File 'lib/omniai/context.rb', line 45 def serializer(name) @serializers[name] end |