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
Currently, access to this service is granted only by application. You can apply for access to Azure OpenAI by completing the form at <ahref="https://aka.ms/oai/access"target="_blank">https://aka.ms/oai/access</a>. Open an issue on this repo to contact us if you have an issue.
21
21
- <ahref="https://www.python.org/"target="_blank">Python 3.8 or later version</a>
22
-
- The following Python libraries: os, json, openai (Version 1.x is required)
23
-
-[Jupyter Notebooks](https://jupyter.org/)
22
+
- The following Python libraries: os, openai (Version 1.x is required)
23
+
-[Azure CLI](/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
24
24
- Azure OpenAI Assistants are currently available in Sweden Central, East US 2, and Australia East. For more information about model availability in those regions, see the [models guide](../concepts/models.md).
25
25
- We recommend reviewing the [Responsible AI transparency note](/legal/cognitive-services/openai/transparency-note?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext&tabs=text) and other [Responsible AI resources](/legal/cognitive-services/openai/overview?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext) to familiarize yourself with the capabilities and limitations of the Azure OpenAI Service.
26
26
- An Azure OpenAI resource with the `gpt-4 (1106-preview)` model deployed was used testing this example.
27
27
28
+
## Passwordless authentication is recommended
29
+
30
+
For passwordless authentication, you need to
31
+
32
+
1. Use the [azure-identity](https://pypi.org/project/azure-identity/) package.
33
+
2. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal under **Access control (IAM)** > **Add role assignment**.
34
+
3. Sign in with the Azure CLI such as `az login`.
35
+
28
36
## Set up
29
37
30
-
Install the OpenAI Python client library with:
38
+
1. Install the OpenAI Python client library with:
39
+
40
+
```console
41
+
pip install openai
42
+
```
43
+
44
+
2. For the **recommended** passwordless authentication:
@@ -71,26 +85,29 @@ In our code we are going to specify the following values:
71
85
72
86
An individual assistant can access up to 128 tools including `code interpreter`, as well as any custom tools you create via [functions](../how-to/assistant-functions.md).
73
87
74
-
Create and run an assistant with the following:
88
+
### Create the Python app
89
+
90
+
Sign in to Azure with `az login` then create and run an assistant with the following **recommended** passwordless Python example:
75
91
76
92
```python
77
93
import os
78
-
import time
79
-
import json
94
+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
In this example we create an assistant with code interpreter enabled. When we ask the assistant a math question it translates the question into python code and executes the code in sandboxed environment in order to determine the answer to the question. The code the model creates and tests to arrive at an answer is:
189
239
190
240
```python
191
-
from sympy import symbols, Eq, solve
192
-
193
-
# Define the variable
194
-
x = symbols('x')
195
-
196
-
# Define the equation
197
-
equation = Eq(3*x +11, 14)
198
-
199
-
# Solve the equation
200
-
solution = solve(equation, x)
201
-
solution
241
+
from sympy import symbols, Eq, solve
242
+
243
+
# Define the variable
244
+
x = symbols('x')
245
+
246
+
# Define the equation
247
+
equation = Eq(3*x +11, 14)
248
+
249
+
# Solve the equation
250
+
solution = solve(equation, x)
251
+
solution
202
252
```
203
253
204
254
It is important to remember that while code interpreter gives the model the capability to respond to more complex queries by converting the questions into code and running that code iteratively in the Python sandbox until it reaches a solution, you still need to validate the response to confirm that the model correctly translated your question into a valid representation in code.
0 commit comments