Module: Legion::Extensions::AzureAi::Runners::Embeddings

Extended by:
Helpers::Client
Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/azure_ai/runners/embeddings.rb

Instance Method Summary collapse

Methods included from Helpers::Client

client, content_safety_client

Instance Method Details

#create(deployment:, input:, api_key:, endpoint:, api_version: '2024-10-21') ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/azure_ai/runners/embeddings.rb', line 12

def create(deployment:, input:, api_key:, endpoint:, api_version: '2024-10-21', **)
  body = { input: input }
  path = "/openai/deployments/#{deployment}/embeddings?api-version=#{api_version}"
  response = client(api_key: api_key, endpoint: endpoint, api_version: api_version).post(path, body)
  {
    result: response.body,
    usage:  {
      input_tokens:       response.body.dig('usage', 'prompt_tokens') || 0,
      output_tokens:      response.body.dig('usage', 'completion_tokens') || 0,
      cache_read_tokens:  response.body.dig('usage', 'prompt_tokens_details', 'cached_tokens') || 0,
      cache_write_tokens: 0
    }
  }
end