You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -29,7 +29,7 @@ To report an issue with the client library, or request additional features, plea
29
29
- Python 3.9 or later.
30
30
- An [Azure subscription][azure_sub].
31
31
- A [project in Azure AI Foundry](https://learn.microsoft.com/azure/ai-studio/how-to/create-projects).
32
-
- The project endpoint URL of the form `https://<your-ai-services-account-name>.services.ai.azure.com/api/projects/<your-project-name>`. It can be found in your Azure AI Foundry Project overview page. Below we will assume the environment variable `PROJECT_ENDPOINT` was defined to hold this value.
32
+
- The project endpoint URL of the form `https://your-ai-services-account-name.services.ai.azure.com/api/projects/your-project-name`. It can be found in your Azure AI Foundry Project overview page. Below we will assume the environment variable `PROJECT_ENDPOINT` was defined to hold this value.
33
33
- An Entra ID token for authentication. Your application needs an object that implements the [TokenCredential](https://learn.microsoft.com/python/api/azure-core/azure.core.credentials.tokencredential) interface. Code samples here use [DefaultAzureCredential](https://learn.microsoft.com/python/api/azure-identity/azure.identity.defaultazurecredential). To get that working, you will need:
34
34
* An appropriate role assignment. see [Role-based access control in Azure AI Foundry portal](https://learn.microsoft.com/azure/ai-foundry/concepts/rbac-ai-foundry). Role assigned can be done via the "Access Control (IAM)" tab of your Azure AI Project resource in the Azure portal.
@@ -41,6 +41,8 @@ To report an issue with the client library, or request additional features, plea
41
41
pip install azure-ai-projects
42
42
```
43
43
44
+
Note that the dependent package [azure-ai-agents](https://pypi.org/project/azure-ai-agents/) will be install as a result, if not already installed, to support `.agent` operations on the client.
45
+
44
46
## Key concepts
45
47
46
48
### Create and authenticate the client with Entra ID
@@ -66,29 +68,32 @@ To construct an asynchronous client, Install the additional package [aiohttp](ht
66
68
pip install aiohttp
67
69
```
68
70
69
-
and update the code above to import `asyncio`, and import `AIProjectClient` from the `azure.ai.projects.aio`namespace:
71
+
and update the code above to import `asyncio`, import `AIProjectClient` from the `azure.ai.projects.aio`package, and import `DefaultAzureCredential` from the `azure.identity.aio` package:
70
72
71
73
```python
72
74
import os
73
75
import asyncio
74
76
from azure.ai.projects.aio import AIProjectClient
75
-
from azure.core.credentialsimportAzureKeyCredential
77
+
from azure.identity.aioimportDefaultAzureCredential
**Note:** Support for project connection string and hub-based projects has been discontinued. We recommend creating a new Azure AI Foundry resource utilizing project endpoint. If this is not possible, please pin the version of or pin the version of `azure-ai-projects` to `1.0.0b10` or earlier.
85
+
**Note:** Support for project connection string and hub-based projects has been discontinued. We recommend creating a new Azure AI Foundry resource utilizing project endpoint. If this is not possible, please pin the version of `azure-ai-projects` to `1.0.0b10` or earlier.
84
86
85
87
## Examples
86
88
87
89
### Performing Agent operations
88
90
89
91
The `.agents` property on the `AIProjectsClient` gives you access to an authenticated `AgentsClient` from the `azure-ai-agents` package. Below we show how to create an Agent and delete it. To see what you can do with the Agent you created, see the [many samples](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/ai/azure-ai-agents/samples) and the [README.md](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/ai/azure-ai-agents) file of the dependent `azure-ai-agents` package.
90
92
91
-
The code below assumes `model_deployment_name` (a string) is defined. It's the deployment name of an AI model in your Foundry Project, as shown in the "Models + endpoints" tab, under the "Name" column.
93
+
The code below assumes the following:
94
+
95
+
*`model_deployment_name` (a string) is defined. It's the deployment name of an AI model in your Foundry Project, as shown in the "Models + endpoints" tab, under the "Name" column.
96
+
*`connection_name` (a string) is defined. It's the name of the connection to a resource of type "Azure OpenAI", as shown in the "Connected resources" tab, under the "Name" column, in the "Management Center" of your Foundry Project.
92
97
93
98
<!-- SNIPPET:sample_agents.agents_sample -->
94
99
@@ -111,17 +116,19 @@ print("Deleted agent")
111
116
112
117
### Get an authenticated AzureOpenAI client
113
118
114
-
Your Azure AI Foundry project may have one or more AI models deployed that support chat completions.
119
+
Your Azure AI Foundry project may have one or more AI models deployed that support chat completions or responses.
115
120
These could be OpenAI models, Microsoft models, or models from other providers.
116
121
Use the code below to get an authenticated [AzureOpenAI](https://github.com/openai/openai-python?tab=readme-ov-file#microsoft-azure-openai)
117
-
from the [openai](https://pypi.org/project/openai/) package, and execute a chat completions call.
122
+
from the [openai](https://pypi.org/project/openai/) package, and execute a chat completions or responses calls.
118
123
119
124
The code below assumes `model_deployment_name` (a string) is defined. It's the deployment name of an AI model in your
120
125
Foundry Project, or a connected Azure OpenAI resource. As shown in the "Models + endpoints" tab, under the "Name" column.
121
126
122
-
Update the `api_version` value with one found in the "Data plane - inference" row [in this table](https://learn.microsoft.com/azure/ai-services/openai/reference#api-specs).
127
+
Update the `api_version` value with one found in the "Data plane - inference" row [in this table](https://learn.microsoft.com/azure/ai-foundry/openai/reference#api-specs).
See the "inference" folder in the [package samples][samples] for additional samples.
208
+
166
209
### Deployments operations
167
210
168
211
The code below shows some Deployments operations, which allow you to enumerate the AI models deployed to your AI Foundry Projects. These models can be seen in the "Models + endpoints" tab in your AI Foundry Project. Full samples can be found under the "deployment" folder in the [package samples][samples].
@@ -393,7 +436,7 @@ By default logs redact the values of URL query strings, the values of some HTTP
Copy file name to clipboardExpand all lines: sdk/ai/azure-ai-projects/samples/inference/azure-ai-inference/sample_chat_completions_with_azure_ai_inference_client.py
Copy file name to clipboardExpand all lines: sdk/ai/azure-ai-projects/samples/inference/azure-ai-inference/sample_chat_completions_with_azure_ai_inference_client_and_azure_monitor_tracing.py
0 commit comments