Class: GTE::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/gte/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Model

Returns a new instance of Model.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
# File 'lib/gte/model.rb', line 7

def initialize(config)
  raise ArgumentError, 'config must be a GTE::Config::Text' unless config.is_a?(Config::Text)

  @config = config
  @embedder = GTE::Embedder.from_config(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/gte/model.rb', line 5

def config
  @config
end

Instance Method Details

#[](input) ⇒ Object



20
21
22
23
24
25
# File 'lib/gte/model.rb', line 20

def [](input)
  case input
  when String then embed(input).row(0)
  when Array then embed(input)
  end
end

#embed(texts) ⇒ Object



14
15
16
17
18
# File 'lib/gte/model.rb', line 14

def embed(texts)
  return @embedder.embed_one(texts) if texts.is_a?(String)

  @embedder.embed(Array(texts))
end