osrforge.providers.foundry
The Azure AI Foundry adapter — the only module allowed to import openai/azure.identity.
Minimal but real: the recorded capability probes drive it live and double as
its integration test. The probes pinned the two service-behavior choices —
the AzureOpenAI client's api-version dialect, and native JSON-schema
response format, which the deployment honors — and the validate-and-retry
loop keeps the adapter correct even where a service's behavior shifts: the
provider owns schema enforcement, and the pipeline never sees invalid data.
FoundryProvider
FoundryProvider(settings: FoundrySettings, client: OpenAI | None = None, sleep: Callable[[float], None] = sleep)
Azure AI Foundry, over the OpenAI-compatible chat surface.
The constructor performs no I/O. Transport policy: bounded exponential
backoff on 429/5xx and connection failures, honoring Retry-After; auth
and other 4xx failures raise immediately. Images ship as base64 PNG data
URLs.
Bind to a deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
FoundrySettings
|
The connection settings. |
required |
client
|
OpenAI | None
|
An injectable OpenAI-compatible client, for tests. When
omitted, a real |
None
|
sleep
|
Callable[[float], None]
|
The backoff sleeper, injectable for tests. |
sleep
|
generate
generate(request: ModelRequest) -> ModelResponse
Run one structured-output completion against the deployment.
Native JSON-schema response format is requested, and the reply is
validated against request.schema regardless; an invalid reply is
re-prompted with the validation errors appended, at most twice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ModelRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
ModelResponse
|
The parsed, schema-validated response. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
On transport, auth, or rate-limit exhaustion. |
SchemaValidationError
|
If no schema-valid reply was obtained within three attempts. |
FoundrySettings
Bases: BaseModel
Connection settings for an Azure AI Foundry deployment.
Auth mode is inferred: a key present means key auth; absent means Entra ID
via DefaultAzureCredential (which needs the osr-forge[entra] extra).
from_env
classmethod
from_env() -> FoundrySettings
Build settings from the OSRFORGE_FOUNDRY_* environment variables.
The OSRFORGE_ prefix (not AZURE_OPENAI_*) avoids colliding with
other tools' env conventions; the README documents the mapping.
Returns:
| Type | Description |
|---|---|
FoundrySettings
|
Settings from |
FoundrySettings
|
|
FoundrySettings
|
|
Raises:
| Type | Description |
|---|---|
ProviderError
|
If a required variable is missing or empty. |