Class: Legion::Extensions::Llm::AzureFoundry::Provider

Inherits:
Provider
  • Object
show all
Extended by:
ProviderClassMethods
Includes:
ProviderCapabilityHelpers, ProviderDispatchMethods, ProviderOfferingHelpers, Provider::OpenAICompatible
Defined in:
lib/legion/extensions/llm/azure_foundry/provider.rb

Overview

Azure AI Foundry and Azure OpenAI hosted provider surface.

Constant Summary collapse

DEFAULT_API_VERSION =
'2024-05-01-preview'
MODEL_INFERENCE_SURFACE =
:model_inference
OPENAI_V1_SURFACE =
:openai_v1

Instance Method Summary collapse

Methods included from ProviderClassMethods

capabilities, configuration_options, configuration_requirements, default_tier, default_transport, deployment_config, normalize_deployments, registry_publisher, resolve_model_id, slug

Methods included from ProviderDispatchMethods

#chat, #count_tokens, #embed, #stream

Instance Method Details

#api_baseObject



410
411
412
413
414
415
416
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 410

def api_base
  endpoint = config.azure_foundry_endpoint.to_s.sub(%r{/*\z}, '')
  return "#{endpoint}/openai/v1" if surface == OPENAI_V1_SURFACE && !endpoint.end_with?('/openai/v1')
  return endpoint.delete_suffix('/models') if surface == MODEL_INFERENCE_SURFACE

  endpoint
end

#chat_urlObject



424
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 424

def chat_url = completion_url

#completion_urlObject



423
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 423

def completion_url = path_for('chat/completions')

#embedding_urlObject



427
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 427

def embedding_url(**) = path_for('embeddings')

#headersObject



418
419
420
421
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 418

def headers
  identity_headers.merge({ 'api-key' => config.azure_foundry_api_key,
                           'Authorization' => bearer_header }.compact)
end

#health(live: false) ⇒ Object



430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 430

def health(live: false)
  log.info { "checking health live=#{live} at #{api_base}" }
  baseline = health_baseline(live)
  return baseline.merge(checked: false) unless live

  response = connection.get(health_url)
  baseline.merge(checked: true, ready: true, status: 'healthy', raw: response.body)
rescue StandardError => e
  handle_exception(e, level: :warn, handled: true, operation: 'azure_foundry.health')
  baseline.merge(checked: true, ready: false, status: 'unhealthy',
                 error: e.class.name, message: e.message)
end

#health_urlObject



428
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 428

def health_url = models_url

#list_modelsObject



448
449
450
451
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 448

def list_models
  log.info { "listing configured deployment models from #{api_base}" }
  discover_offerings(live: false).map { |offering| model_info_from_offering(offering) }
end

#models_urlObject



426
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 426

def models_url = surface == MODEL_INFERENCE_SURFACE ? path_for('info') : path_for('models')

#readiness(live: false) ⇒ Object



443
444
445
446
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 443

def readiness(live: false)
  log.info { "checking readiness live=#{live} at #{api_base}" }
  health(live: live).merge(local: false, remote: true, endpoints: endpoint_manifest)
end

#stream_urlObject



425
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 425

def stream_url = completion_url

#stream_usage_supported?Boolean

Returns:

  • (Boolean)


408
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 408

def stream_usage_supported? = true