Class: LlmOptimizer::EmbeddingClient

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_optimizer/embedding_client.rb

Constant Summary collapse

OPENAI_ENDPOINT =
"https://api.openai.com/v1/embeddings"

Instance Method Summary collapse

Constructor Details

#initialize(model:, timeout_seconds:, embedding_caller: nil) ⇒ EmbeddingClient

Returns a new instance of EmbeddingClient.



11
12
13
14
15
# File 'lib/llm_optimizer/embedding_client.rb', line 11

def initialize(model:, timeout_seconds:, embedding_caller: nil)
  @model            = model
  @timeout_seconds  = timeout_seconds
  @embedding_caller = embedding_caller
end

Instance Method Details

#embed(text) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/llm_optimizer/embedding_client.rb', line 17

def embed(text)
  if @embedding_caller
    @embedding_caller.call(text)
  else
    embed_via_openai(text)
  end
rescue EmbeddingError
  raise
rescue StandardError => e
  raise EmbeddingError, "Embedding request failed: #{e.message}"
end