From c13611ed96064a8820b192124d1f388a1ea85312 Mon Sep 17 00:00:00 2001 From: Darren Cohen <39422044+dargilco@users.noreply.github.com> Date: Fri, 21 Mar 2025 13:16:55 -0700 Subject: [PATCH 1/3] deployment samples --- .../samples/datasets/sample_datasets.py | 2 +- .../samples/datasets/sample_datasets_async.py | 2 +- .../samples/deployments/sample_deployments.py | 45 +++++++++++++++ .../deployments/sample_deployments_async.py | 56 +++++++++++++++++++ 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py create mode 100644 sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py diff --git a/sdk/ai/azure-ai-projects-dp1/samples/datasets/sample_datasets.py b/sdk/ai/azure-ai-projects-dp1/samples/datasets/sample_datasets.py index 9bb57c5ed79f..3d5fb9b50fb2 100644 --- a/sdk/ai/azure-ai-projects-dp1/samples/datasets/sample_datasets.py +++ b/sdk/ai/azure-ai-projects-dp1/samples/datasets/sample_datasets.py @@ -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: diff --git a/sdk/ai/azure-ai-projects-dp1/samples/datasets/sample_datasets_async.py b/sdk/ai/azure-ai-projects-dp1/samples/datasets/sample_datasets_async.py index a4c8ff0bd5df..eb4bc7a156df 100644 --- a/sdk/ai/azure-ai-projects-dp1/samples/datasets/sample_datasets_async.py +++ b/sdk/ai/azure-ai-projects-dp1/samples/datasets/sample_datasets_async.py @@ -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: diff --git a/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py new file mode 100644 index 000000000000..fd7b79a79379 --- /dev/null +++ b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py @@ -0,0 +1,45 @@ + +# ------------------------------------ +# 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. +""" + +import os +from azure.identity import DefaultAzureCredential +from azure.ai.projects.dp1 import AIProjectClient + +endpoint = os.environ["PROJECT_ENDPOINT"] + +project_client = AIProjectClient( + endpoint=endpoint, + credential=DefaultAzureCredential(), +) + +print("Get a single deployment by its name:") +deployment = project_client.deployments.get("gpt-4o-mini") +print(deployment) + +print("List all deployments:") +for deployment in project_client.deployments.list(): + print(deployment) + +print("List all deployments by publisher `OpenAI`:") +for deployment in project_client.deployments.list(model_publisher="OpenAI"): + print(deployment) \ No newline at end of file diff --git a/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py new file mode 100644 index 000000000000..63e821d7425b --- /dev/null +++ b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py @@ -0,0 +1,56 @@ + +# ------------------------------------ +# 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.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. +""" + +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"] + + project_client = AIProjectClient( + endpoint=endpoint, + credential=DefaultAzureCredential(), + ) + + print("Get a single deployment by its name:") + deployment = await project_client.deployments.get("gpt-4o-mini") + print(deployment) + + print("List all deployments:") + async for deployment in project_client.deployments.list(): + print(deployment) + + print("List all deployments by publisher `OpenAI`:") + async for deployment in project_client.deployments.list(model_publisher="OpenAI"): + print(deployment) + + +async def main(): + await sample_deployments_async() + + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file From ece4a3577f793f9dfb563326958eca5feb2e7d27 Mon Sep 17 00:00:00 2001 From: Darren Cohen <39422044+dargilco@users.noreply.github.com> Date: Fri, 21 Mar 2025 13:23:36 -0700 Subject: [PATCH 2/3] Fixes --- .../samples/deployments/sample_deployments_async.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py index 63e821d7425b..8829cdb81ffb 100644 --- a/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py +++ b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py @@ -10,11 +10,11 @@ `.deployments` methods to enumerate AI models deployed to your AI Foundry Project. USAGE: - python sample_deployments.py + python sample_deployments_async.py Before running the sample: - pip install azure-ai-projects azure-identity + 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 From 8f1027a5eae452fee2359955e71ec257532c0c4c Mon Sep 17 00:00:00 2001 From: Darren Cohen <39422044+dargilco@users.noreply.github.com> Date: Mon, 24 Mar 2025 07:28:56 -0700 Subject: [PATCH 3/3] Use more env variables --- .../samples/deployments/sample_deployments.py | 16 ++++++++++------ .../deployments/sample_deployments_async.py | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py index fd7b79a79379..eb0357ec2395 100644 --- a/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py +++ b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py @@ -19,6 +19,8 @@ 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 @@ -26,20 +28,22 @@ 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("Get a single deployment by its name:") -deployment = project_client.deployments.get("gpt-4o-mini") -print(deployment) - print("List all deployments:") for deployment in project_client.deployments.list(): print(deployment) -print("List all deployments by publisher `OpenAI`:") -for deployment in project_client.deployments.list(model_publisher="OpenAI"): +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) \ No newline at end of file diff --git a/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py index 8829cdb81ffb..83f94a431e5b 100644 --- a/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py +++ b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py @@ -19,6 +19,8 @@ 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 @@ -29,22 +31,24 @@ 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("Get a single deployment by its name:") - deployment = await project_client.deployments.get("gpt-4o-mini") - print(deployment) - print("List all deployments:") async for deployment in project_client.deployments.list(): print(deployment) - print("List all deployments by publisher `OpenAI`:") - async for deployment in project_client.deployments.list(model_publisher="OpenAI"): + 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)