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..eb0357ec2395 --- /dev/null +++ b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments.py @@ -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) \ 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..83f94a431e5b --- /dev/null +++ b/sdk/ai/azure-ai-projects-dp1/samples/deployments/sample_deployments_async.py @@ -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()) \ No newline at end of file