Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add one simple sync & async samples for the Deployment methods #40186

Merged
merged 3 commits into from
Mar 24, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
DESCRIPTION:
Given an AIProjectClient, this sample demonstrates how to use the synchronous
datasets methods to upload files, create datasets that reference those files,
`.datasets` methods to upload files, create datasets that reference those files,
list datasets and delete datasets.

USAGE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
DESCRIPTION:
Given an AIProjectClient, this sample demonstrates how to use the asynchronous
datasets methods to upload files, create datasets that reference those files,
`.datasets` methods to upload files, create datasets that reference those files,
list datasets and delete datasets.

USAGE:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

"""
DESCRIPTION:
Given an AIProjectClient, this sample demonstrates how to use the synchronous
`.deployments` methods to enumerate AI models deployed to your AI Foundry Project.

USAGE:
python sample_deployments.py

Before running the sample:

pip install azure-ai-projects azure-identity

Set these environment variables with your own values:
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
Azure AI Foundry project.
2) DEPLOYMENT_NAME - Required. The name of the deployment to retrieve.
3) MODEL_PUBLISHER - Required. The publisher of the model to filter by.
"""

import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects.dp1 import AIProjectClient

endpoint = os.environ["PROJECT_ENDPOINT"]
deployment_name = os.environ["DEPLOYMENT_NAME"]
model_publisher = os.environ["MODEL_PUBLISHER"]

project_client = AIProjectClient(
endpoint=endpoint,
credential=DefaultAzureCredential(),
)

print("List all deployments:")
for deployment in project_client.deployments.list():
print(deployment)

print("Get a single deployment named `f{deployment_name}`:")
deployment = project_client.deployments.get(deployment_name)
print(deployment)

print(f"List all deployments by the model publisher `{model_publisher}`:")
for deployment in project_client.deployments.list(model_publisher=model_publisher):
print(deployment)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

"""
DESCRIPTION:
Given an AIProjectClient, this sample demonstrates how to use the asynchronous
`.deployments` methods to enumerate AI models deployed to your AI Foundry Project.

USAGE:
python sample_deployments_async.py

Before running the sample:

pip install azure-ai-projects azure-identity aiohttp

Set these environment variables with your own values:
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
Azure AI Foundry project.
2) DEPLOYMENT_NAME - Required. The name of the deployment to retrieve.
3) MODEL_PUBLISHER - Required. The publisher of the model to filter by.
"""

import asyncio
import os
from azure.identity.aio import DefaultAzureCredential
from azure.ai.projects.dp1.aio import AIProjectClient

async def sample_deployments_async() -> None:

endpoint = os.environ["PROJECT_ENDPOINT"]
deployment_name = os.environ["DEPLOYMENT_NAME"]
model_publisher = os.environ["MODEL_PUBLISHER"]

project_client = AIProjectClient(
endpoint=endpoint,
credential=DefaultAzureCredential(),
)

print("List all deployments:")
async for deployment in project_client.deployments.list():
print(deployment)

print("Get a single deployment named `f{deployment_name}`:")
deployment = await project_client.deployments.get(deployment_name)
print(deployment)

print(f"List all deployments by the model publisher `{model_publisher}`:")
async for deployment in project_client.deployments.list(model_publisher=model_publisher):
print(deployment)


async def main():
await sample_deployments_async()


if __name__ == "__main__":
asyncio.run(main())
Loading