Class: Legion::Extensions::Llm::AzureFoundry::Provider
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
capabilities, configuration_options, configuration_requirements, default_tier, default_transport, deployment_config, normalize_deployments, registry_publisher, resolve_model_id, slug
#chat, #count_tokens, #embed, #stream
Instance Method Details
#api_base ⇒ Object
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_url ⇒ Object
424
|
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 424
def chat_url = completion_url
|
#completion_url ⇒ Object
423
|
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 423
def completion_url = path_for('chat/completions')
|
#embedding_url ⇒ Object
427
|
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 427
def embedding_url(**) = path_for('embeddings')
|
418
419
420
421
|
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 418
def
.merge({ 'api-key' => config.azure_foundry_api_key,
'Authorization' => }.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_url ⇒ Object
428
|
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 428
def health_url = models_url
|
#list_models ⇒ Object
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_url ⇒ Object
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_url ⇒ Object
425
|
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 425
def stream_url = completion_url
|
#stream_usage_supported? ⇒ Boolean
408
|
# File 'lib/legion/extensions/llm/azure_foundry/provider.rb', line 408
def stream_usage_supported? = true
|