feat(models): add Azure AI Foundry to unified model provider setup#13924
feat(models): add Azure AI Foundry to unified model provider setup#13924pareek-ml wants to merge 2 commits into
Conversation
Adds Azure AI Foundry as a first-class model provider in Langflow's unified model system, enabling centralized configuration via Settings → Model Providers. - Register "Azure AI Foundry" in MODEL_PROVIDER_METADATA with AZURE_AI_FOUNDRY_API_KEY (required, secret, langchain_param=credential) and AZURE_AI_FOUNDRY_ENDPOINT (required, non-secret, langchain_param=endpoint) - Add AzureAIOpenAIApiChatModel to the lazy-import class registry (langchain-azure-ai package, with install hint) - Add seed model catalog (gpt-4o, gpt-4o-mini, gpt-4.1, o3-mini, Mistral-Large-3) with capability flags to _STATIC_MODELS_DETAILED - Extend validate_model_provider_key with an Azure AI Foundry branch that constructs AzureAIOpenAIApiChatModel and invokes a test call; returns early when api_key, endpoint, or model_name is absent - Extend get_llm with an Azure AI Foundry branch that resolves AZURE_AI_FOUNDRY_ENDPOINT from provider vars or env and raises ValueError with an actionable message when missing - Register both env vars in VARIABLES_TO_GET_FROM_ENVIRONMENT for automatic environment import - Add langchain-azure-ai to flow requirements map so flows using this provider include the package in generated requirements.txt Tests (12 total, full coverage of new paths): - Provider registry presence and metadata shape - Parameter mapping resolution (model_class, api_key_param) - Env var registration and requirements generation - Credential validation: success path and all three early-return paths (missing model, missing api_key, missing endpoint) - get_llm: endpoint + credential wiring and missing-endpoint error Supersedes langflow-ai#13912 with docstrings on all test functions (fixing CodeRabbit's docstring-coverage warning) and tests for the three credential validation early-return paths (fixing Codecov's credentials.py partial-coverage report).
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR adds Azure AI Foundry as a unified model provider in lfx. It introduces model catalog metadata, provider configuration, a lazy-import class registry entry, credential validation logic, LLM instantiation wiring (endpoint resolution with gated env fallback), requirement-package fallback mapping, environment variable registration, and accompanying unit tests. ChangesAzure AI Foundry provider integration
Sequence Diagram(s)sequenceDiagram
participant Flow
participant get_llm
participant _env_if_allowed
participant AzureAIOpenAIApiChatModel
Flow->>get_llm: request LLM("Azure AI Foundry", model_name)
get_llm->>get_llm: resolve AZURE_AI_FOUNDRY_ENDPOINT (component/db)
get_llm->>_env_if_allowed: check env fallback if not found
_env_if_allowed-->>get_llm: endpoint value or None
alt endpoint missing
get_llm-->>Flow: raise ValueError("Azure AI Foundry endpoint is required")
else endpoint resolved
get_llm->>AzureAIOpenAIApiChatModel: construct(credential, endpoint, model)
AzureAIOpenAIApiChatModel-->>get_llm: chat model instance
get_llm-->>Flow: return LLM instance
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 8 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (8 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing in favour of the cleaner bundle approach. After looking at how #13916 works, this PR is doing exactly what #13916 was built to prevent — touching Most of those core edits are already handled generically by the registry:
The one genuine gap is The right fix is a small extension to models: list[dict] = field(default_factory=list)…and a corresponding append to I'll open a PR against cc @erichare |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py (1)
150-169: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winEarly-return tests don't guard against a real network call on regression.
Unlike the success test, these tests don't mock
langchain_azure_ai/AzureAIOpenAIApiChatModel, yetmodel_name="gpt-4o"is supplied. If the early-return guard incredentials.pyever regresses, these tests would attempt a real import/network call to Azure instead of failing with a clear assertion — making CI flaky/slow instead of deterministically red.🧪 Suggested fix: mock the model and assert it wasn't called
def test_validate_model_provider_key_azure_ai_foundry_returns_early_without_api_key(): """validate_model_provider_key must return without error when API key is absent.""" from lfx.base.models.unified_models import validate_model_provider_key - validate_model_provider_key( - "Azure AI Foundry", - {"AZURE_AI_FOUNDRY_ENDPOINT": "https://example.services.ai.azure.com/openai/v1"}, - model_name="gpt-4o", - ) + calls = [] + + class FakeFoundryChatModel: + def __init__(self, **kwargs): + calls.append(kwargs) + + fake_chat_models = SimpleNamespace(AzureAIOpenAIApiChatModel=FakeFoundryChatModel) + with patch.dict( + "sys.modules", + {"langchain_azure_ai.chat_models": fake_chat_models}, + ): + validate_model_provider_key( + "Azure AI Foundry", + {"AZURE_AI_FOUNDRY_ENDPOINT": "https://example.services.ai.azure.com/openai/v1"}, + model_name="gpt-4o", + ) + assert calls == []Same applies to
test_validate_model_provider_key_azure_ai_foundry_returns_early_without_endpoint(Lines 161-169).As per coding guidelines, "verify the tests actually cover the new or changed behavior rather than acting as placeholders."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py` around lines 150 - 169, The Azure AI Foundry early-return tests in test_validate_model_provider_key_azure_ai_foundry_returns_early_without_api_key and test_validate_model_provider_key_azure_ai_foundry_returns_early_without_endpoint should also mock the underlying langchain_azure_ai / AzureAIOpenAIApiChatModel path so they fail deterministically if the guard in validate_model_provider_key (from unified_models/credentials logic) regresses. Update both tests to patch the model import/construction and assert it is not called when either the API key or endpoint is missing, instead of relying only on the absence of an exception.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py`:
- Around line 150-169: The Azure AI Foundry early-return tests in
test_validate_model_provider_key_azure_ai_foundry_returns_early_without_api_key
and
test_validate_model_provider_key_azure_ai_foundry_returns_early_without_endpoint
should also mock the underlying langchain_azure_ai / AzureAIOpenAIApiChatModel
path so they fail deterministically if the guard in validate_model_provider_key
(from unified_models/credentials logic) regresses. Update both tests to patch
the model import/construction and assert it is not called when either the API
key or endpoint is missing, instead of relying only on the absence of an
exception.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3ef7e3ed-bcca-474e-bfbc-bfd3cb20aba4
📒 Files selected for processing (9)
src/lfx/src/lfx/base/models/azure_ai_foundry_constants.pysrc/lfx/src/lfx/base/models/model_metadata.pysrc/lfx/src/lfx/base/models/unified_models/class_registry.pysrc/lfx/src/lfx/base/models/unified_models/credentials.pysrc/lfx/src/lfx/base/models/unified_models/instantiation.pysrc/lfx/src/lfx/base/models/unified_models/provider_queries.pysrc/lfx/src/lfx/services/settings/constants.pysrc/lfx/src/lfx/utils/flow_requirements.pysrc/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py
…ai-foundry bundle Part 1 — registry extension (provider_registry.py, manifest.py, loader): Adds a `models: list[dict]` field to ProviderSpec so a bundle can seed a static model catalog without editing core files. register_provider() appends the list to _STATIC_MODELS_DETAILED in-place; clear() reverses it. The extension.json schema gains a matching `models[]` array; the loader passes it through to ProviderSpec. Zero behavior change when no bundle is loaded. Part 2 — lfx-azure-ai-foundry bundle (src/bundles/azure-ai-foundry/): Ships Azure AI Foundry as a provider-only Extension Bundle with zero core edits, superseding the core-edit approach in langflow-ai#13912 and langflow-ai#13924. - extension.json: declares provider metadata (AZURE_AI_FOUNDRY_API_KEY + AZURE_AI_FOUNDRY_ENDPOINT), AzureAIOpenAIApiChatModel lazy import, dotted- path validator, and a seed catalog (gpt-4o, gpt-4o-mini, gpt-4.1, o3-mini, Mistral-Large-3) via the new models[] field. - validator.py: constructs AzureAIOpenAIApiChatModel and calls invoke(); early- returns when api_key, endpoint, or model_name is absent. Tests (10): - models[] injection into _STATIC_MODELS_DETAILED and clear() reversal. - End-to-end load through the real extension loader: provider appears in get_model_providers() and seed models in get_models_detailed(). - Validator: early-return paths (missing model, key, endpoint), success, and ValueError on invoke() failure. Refs langflow-ai#13912, closes langflow-ai#13924
What & why
Adds Azure AI Foundry as a first-class model provider in Langflow's unified model system (Settings → Model Providers), enabling centralized configuration of endpoint and API key — identical to how OpenAI, Anthropic, and Ollama work today.
Supersedes #13912 by @HimavarshaVS with two fixes applied:
missing model_name,missing api_key,missing endpoint) are now tested (fixes Codecov'scredentials.pypartial-coverage report)How
azure_ai_foundry_constants.pygpt-4o,gpt-4o-mini,gpt-4.1,o3-mini,Mistral-Large-3with capability flagsmodel_metadata.py"Azure AI Foundry"entry:AZURE_AI_FOUNDRY_API_KEY(credential) +AZURE_AI_FOUNDRY_ENDPOINT(endpoint),AzureAIOpenAIApiChatModelmappingclass_registry.pyAzureAIOpenAIApiChatModelfromlangchain-azure-aiprovider_queries.py_STATIC_MODELS_DETAILEDcredentials.pymax_tokens=1, invokes test call; early-returns when any required field is absentinstantiation.pyget_llmbranch: resolvesAZURE_AI_FOUNDRY_ENDPOINTfrom provider vars or env; raisesValueErrorwith actionable message when missingsettings/constants.pyVARIABLES_TO_GET_FROM_ENVIRONMENTflow_requirements.py"Azure AI Foundry": {"langchain-azure-ai"}Tests
12 tests in
test_azure_ai_foundry_provider.pycovering:get_llm: endpoint + credential wiring and missing-endpointValueErrorTest plan
gpt-4o)Refs #13912
Summary by CodeRabbit
New Features
Bug Fixes
Tests