Class: OmniAI::Context

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext



38
39
40
41
# File 'lib/omniai/context.rb', line 38

def initialize
  @serializers = {}
  @deserializers = {}
end

Instance Attribute Details

#deserializersHash (readonly)

Returns:

  • (Hash)


25
26
27
# File 'lib/omniai/context.rb', line 25

def deserializers
  @deserializers
end

#serializersHash

Returns:

  • (Hash)


22
23
24
# File 'lib/omniai/context.rb', line 22

def serializers
  @serializers
end

Class Method Details

.build {|context| ... } ⇒ Context

Yields:

  • (context)

Yield Parameters:

Returns:



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?

Parameters:

  • name (Symbol)

Returns:

  • (Proc, nil)


51
52
53
# File 'lib/omniai/context.rb', line 51

def deserializer(name)
  @deserializers[name]
end

#serializer(name) ⇒ Proc?

Parameters:

  • name (Symbol)

Returns:

  • (Proc, nil)


45
46
47
# File 'lib/omniai/context.rb', line 45

def serializer(name)
  @serializers[name]
end