OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: correct Azure AI Foundry resource health checks (#2514)
Edwin Josee02cda2801e0
diff --git a/docs/docs/reference/configuration.mdx b/docs/docs/reference/configuration.mdxindex 5b12adb69..26daa07b9 100644--- a/docs/docs/reference/configuration.mdx+++ b/docs/docs/reference/configuration.mdx@@ -190,6 +190,19 @@ today — are entered in **Settings** through a form built from the provider's ocredential fields. Configuring one needs no code change beyond its row in thisfile.+#### Azure AI Foundry health checks {#azure-ai-foundry-health}++For `azure_ai`, a resource endpoint such as+`https://<resource>.services.ai.azure.com/` or its `/models` form uses the+legacy Foundry inference route. Keep that endpoint if inference is already+working; the periodic health check uses the resource's separate+`/openai/v1/models` listing, not `GET /models`.++Explicit `/openai/v1` endpoints, including project-scoped endpoints, keep their+configured prefix when listing models. These lightweight checks do not run+inference or consume model tokens, and a successful listing does not prove that+a particular deployment supports chat or tool calling.+#### Add a custom OpenAI-compatible provider {#custom-openai-compatible-provider}To offer a self-hosted OpenAI-compatible endpoint — vLLM, LM Studio, or andiff --git a/enhancements/providers/azure/foundry.py b/enhancements/providers/azure/foundry.pyindex a266b7129..7d38fb69d 100644--- a/enhancements/providers/azure/foundry.py+++ b/enhancements/providers/azure/foundry.py@@ -240,14 +240,10 @@ CREDENTIAL_FIELDS: list[dict[str, Any]] = [{"key": "api_base","label": "Endpoint",- "placeholder": "https://<resource>.services.ai.azure.com/openai/v1",+ "placeholder": "https://<resource>.services.ai.azure.com/","tooltip": (- "The resource endpoint, not a per-deployment Target URI. Copy the "- "'Azure AI Foundry' endpoint from your resource's Overview page and keep "- "the /openai/v1 suffix. A Target URI that names one deployment "- "(.../openai/deployments/<name>/chat/completions) pins every model you "- "select to that one deployment. The older /models endpoint is still "- "accepted for deployments already using it."+ "Copy the resource endpoint from Azure's Keys and Endpoint page. "+ "Do not use a deployment-specific Target URI."),"required": True,"field_type": "text",@@ -269,9 +265,8 @@ CREDENTIAL_FIELDS: list[dict[str, Any]] = ["label": "API version","placeholder": "2024-05-01-preview","tooltip": (- "Only for the older /models endpoint, which dates its API. Leave blank "- "for /openai/v1, which is versionless — sending one there is at best "- "ignored."+ "For a resource root or /models endpoint, enter the API version used by "+ "your deployment. Leave blank for /openai/v1, which is versionless."),"required": False,"field_type": "text",@@ -514,9 +509,8 @@ def litellm_credentials(stored: Mapping[str, Any], *, kind: CallKind = "chat") -#: Read-only listing used to check credentials. It needs no deployment and-#: bills nothing, which is what makes it a check the provider can pass before-#: anything has been selected in Settings. Both surfaces expose it directly-#: under the endpoint.+#: bills nothing. Even a resource using the legacy `/models` inference surface+#: lists models through `/openai/v1/models`, not `GET /models`.MODELS_PATH = "/models"#: A human is waiting on the pre-save check, so it fails fast.@@ -526,15 +520,15 @@ HEALTH_TIMEOUT_SECONDS = 15.0def models_url(api_base: str) -> str:"""The deployment/model listing URL for an endpoint.- On the v1 surface this is `…/openai/v1/models`. On the legacy route the- endpoint *is* `…/models`, and the listing hangs off the resource root- instead, so the suffix is not doubled.+ Both a resource root and its legacy `/models` inference base use the+ resource's `/openai/v1/models` listing. Explicit v1 bases retain their+ path, including a project prefix when present."""base = normalized_api_base(api_base)if endpoint_profile(base) == "legacy_models":- return (- base if base.rstrip("/").endswith(MODELS_PATH) else f"{base.rstrip('/')}{MODELS_PATH}"- )+ if base.lower().endswith(MODELS_PATH):+ base = base[: -len(MODELS_PATH)]+ base = f"{base}{_V1_SUFFIX}"return f"{base.rstrip('/')}{MODELS_PATH}"diff --git a/tests/unit/enhancements/providers/azure/test_foundry.py b/tests/unit/enhancements/providers/azure/test_foundry.pyindex 6d0175f13..5ab2a2de3 100644--- a/tests/unit/enhancements/providers/azure/test_foundry.py+++ b/tests/unit/enhancements/providers/azure/test_foundry.py@@ -374,18 +374,6 @@ class TestCredentialForm:assert "api_key" in secret_field_keys("azure_ai")- def test_the_form_replaces_litellms_deployment_pinning_placeholder(self) -> None:- """LiteLLM's own `api_base` placeholder is a per-deployment Target URI.-- Following it produces a provider that serves exactly one deployment:- every model selected resolves to the one baked into the URL.- """- from services.model_catalog import credential_fields-- api_base = next(f for f in credential_fields("azure_ai") if f["key"] == "api_base")- assert "/openai/v1" in (api_base["placeholder"] or "")- assert "deployments/" not in (api_base["placeholder"] or "")-def test_the_form_asks_only_for_what_this_release_consumes(self) -> None:"""No field is offered that nothing reads.@@ -401,19 +389,6 @@ class TestCredentialForm:class TestModelsUrl:- @pytest.mark.parametrize(- "api_base, expected",- [- (f"{RESOURCE}/openai/v1", f"{RESOURCE}/openai/v1/models"),- (f"{RESOURCE}/api/projects/p/openai/v1", f"{RESOURCE}/api/projects/p/openai/v1/models"),- # The legacy endpoint already *is* the listing path.- (f"{RESOURCE}/models", f"{RESOURCE}/models"),- (RESOURCE, f"{RESOURCE}/models"),- ],- )- def test_the_listing_path_is_not_doubled(self, api_base, expected) -> None:- assert foundry.models_url(api_base) == expected-def test_both_auth_header_styles_are_sent(self) -> None:"""litellm itself disagrees with itself here.@@ -432,6 +407,55 @@ class TestModelsUrl:class TestLightweightHealthCheck:"""The pre-save probe: authenticated, read-only, and never billed."""+ @pytest.mark.asyncio+ @pytest.mark.parametrize(+ "api_base, listing_path",+ [+ (RESOURCE, "/openai/v1/models"),+ (f"{RESOURCE}/models/", "/openai/v1/models"),+ (f"{RESOURCE}/openai/v1", "/openai/v1/models"),+ (+ f"{RESOURCE}/api/projects/p/openai/v1",+ "/api/projects/p/openai/v1/models",+ ),+ ],+ )+ async def test_polling_uses_the_listing_api_not_the_inference_base(+ self, monkeypatch, api_base, listing_path+ ) -> None:+ import httpx++ from api.provider_validation import validate_provider_setup++ def serve(request: httpx.Request) -> httpx.Response:+ if (+ request.method == "GET"+ and request.url.path == listing_path+ and request.headers.get("api-key") == "k"+ and not request.url.query+ ):+ return httpx.Response(200, json={"object": "list", "data": []})+ return httpx.Response(+ 404, json={"error": {"code": "404", "message": "Resource not found"}}+ )++ client_type = httpx.AsyncClient+ monkeypatch.setattr(+ httpx,+ "AsyncClient",+ lambda **kwargs: client_type(transport=httpx.MockTransport(serve), **kwargs),+ )+ credentials = {"api_base": api_base, "api_key": "k", "api_version": "2024-05-01-preview"}++ result = await validate_provider_setup(+ provider="azure_ai",+ llm_model="working-deployment",+ credentials=foundry.litellm_credentials(credentials),+ stored_credentials=credentials,+ )++ assert not result.model_probed+@pytest.mark.asyncioasync def test_a_good_endpoint_and_key_pass_without_an_inference_call(self, monkeypatch