Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/.env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Microsoft Foundry
# Project endpoint used by FoundryChatClient and OpenAI deployments in FoundryEmbeddingClient
FOUNDRY_PROJECT_ENDPOINT=""
# Model used for FoundryChatClient
FOUNDRY_MODEL=""
# Foundry Agents (prompt or hosted agents)
FOUNDRY_AGENT_NAME=""
FOUNDRY_AGENT_VERSION=""
# Microsoft Foundry Models endpoint, used by embeddings
# Microsoft Foundry Models inference endpoint, used by image and non-project embeddings
FOUNDRY_MODELS_ENDPOINT=""
FOUNDRY_MODELS_API_KEY=""
# Model used by FoundryEmbeddingClient
FOUNDRY_EMBEDDING_MODEL=""
FOUNDRY_IMAGE_EMBEDDING_MODEL=""
# Bing connection for web search (optional, used by samples with web search)
Expand Down
33 changes: 33 additions & 0 deletions python/packages/foundry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,39 @@ This package supports `azure-ai-projects>=2.2.0,<2.7.0`. Projects 2.5 and later
`openai>=3.0.0`, so `agent-framework-foundry` requires `agent-framework-openai>=1.14.2`,
which supports both OpenAI 2.x and 3.x.

## Embeddings

`FoundryEmbeddingClient` supports OpenAI text embedding deployments exposed through a Microsoft Foundry project.
Pass an existing `AIProjectClient`, or provide the project endpoint and an async Azure credential:

```python
import os

from agent_framework.foundry import FoundryEmbeddingClient
from azure.identity.aio import AzureCliCredential

async with AzureCliCredential() as credential:
async with FoundryEmbeddingClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model=os.environ["FOUNDRY_EMBEDDING_MODEL"],
credential=credential,
) as client:
result = await client.get_embeddings(["Hello, world!"])
print(result[0].dimensions)
```

Set `FOUNDRY_PROJECT_ENDPOINT` to the project endpoint and `FOUNDRY_EMBEDDING_MODEL` to the embedding deployment
name. When an `AIProjectClient` is already available, pass it as `project_client` and omit the endpoint and
credential.

The client uses the project for authentication and converts a
`https://<resource>.services.ai.azure.com/api/projects/<project>` endpoint to the documented resource-scoped
`https://<resource>.openai.azure.com/openai/v1/` model route. The existing `FOUNDRY_MODELS_ENDPOINT` and
`FOUNDRY_MODELS_API_KEY` configuration remains available for Foundry Models inference endpoints. A Models endpoint is
required for image embedding models. If both project and Models endpoints are configured only through environment
variables, the Models endpoint is retained for backward compatibility; pass `project_endpoint` explicitly to select
the project OpenAI deployment.

## Evaluations

`FoundryEvals` implements the provider-neutral `Evaluator` protocol with
Expand Down
345 changes: 270 additions & 75 deletions python/packages/foundry/agent_framework_foundry/_embedding_client.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FeatureIndex(IntEnum):

_FOUNDRY_ORIGIN_SUFFIXES = (
"inference.ai.azure.com",
"openai.azure.com",
"services.ai.azure.com",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ class OutputStruct(BaseModel):
weather: str | None = None


def test_foundry_feature_usage_policy_refreshes_user_agent() -> None:
@pytest.mark.parametrize(
"url",
[
"https://project.services.ai.azure.com/api/projects/test",
"https://project.openai.azure.com/openai/v1/embeddings",
],
)
def test_foundry_feature_usage_policy_refreshes_user_agent(url: str) -> None:
with telemetry._feature_mask_lock:
telemetry._feature_mask = 0
mark_feature_used(FeatureIndex.FOUNDRY_CHAT_CLIENT)
request = MagicMock()
request.http_request.url = "https://project.services.ai.azure.com/api/projects/test"
request.http_request.url = url
request.http_request.headers = {"User-Agent": "azsdk-python-ai-projects/1.0 agent-framework-python/1.0"}
FeatureUsagePolicy().on_request(request)

Expand Down
Loading
Loading