Skip to content

Commit 6acd8d6

Browse files
committed
update
1 parent 6783725 commit 6acd8d6

File tree

1 file changed

+68
-27
lines changed

1 file changed

+68
-27
lines changed

articles/ai-services/openai/includes/chatgpt-python.md

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,93 @@ keywords:
3030

3131
Install the OpenAI Python client library with:
3232

33+
# [OpenAI Python 0.28.1](#tab/python)
34+
3335
```console
3436
pip install openai==0.28.1
3537
```
3638

39+
# [OpenAI Python 1.0](#tab/python-new)
40+
41+
```console
42+
pip install openai
43+
```
44+
45+
---
46+
3747
> [!NOTE]
3848
> This library is maintained by OpenAI and is currently in preview. Refer to the [release history](https://github.com/openai/openai-python/releases) or the [version.py commit history](https://github.com/openai/openai-python/commits/main/openai/version.py) to track the latest updates to the library.
3949
4050
[!INCLUDE [get-key-endpoint](get-key-endpoint.md)]
4151

4252
[!INCLUDE [environment-variables](environment-variables.md)]
4353

44-
4554
> [!div class="nextstepaction"]
4655
> [I ran into an issue with the setup.](https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=PYTHON&Pillar=AOAI&Product=Chatgpt&Page=quickstart&Section=Set-up)
4756
4857
## Create a new Python application
4958

5059
1. Create a new Python file called quickstart.py. Then open it up in your preferred editor or IDE.
5160

52-
2. Replace the contents of quickstart.py with the following code. You need to set the `engine` variable to the deployment name you chose when you deployed the GPT-35-Turbo or GPT-4 models. Entering the model name will result in an error unless you chose a deployment name that is identical to the underlying model name.
53-
54-
```python
55-
#Note: The openai-python library support for Azure OpenAI is in preview.
56-
import os
57-
import openai
58-
openai.api_type = "azure"
59-
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
60-
openai.api_version = "2023-05-15"
61-
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
62-
63-
response = openai.ChatCompletion.create(
64-
engine="gpt-35-turbo", # engine = "deployment_name".
65-
messages=[
66-
{"role": "system", "content": "You are a helpful assistant."},
67-
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
68-
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
69-
{"role": "user", "content": "Do other Azure AI services support this too?"}
70-
]
71-
)
72-
73-
print(response)
74-
print(response['choices'][0]['message']['content'])
75-
```
61+
2. Replace the contents of quickstart.py with the following code.
62+
63+
# [OpenAI Python 0.28.1](#tab/python)
64+
65+
You need to set the `engine` variable to the deployment name you chose when you deployed the GPT-3.5-Turbo or GPT-4 models. Entering the model name will result in an error unless you chose a deployment name that is identical to the underlying model name.
66+
67+
```python
68+
import os
69+
import openai
70+
openai.api_type = "azure"
71+
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
72+
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
73+
openai.api_version = "2023-05-15"
74+
75+
response = openai.ChatCompletion.create(
76+
engine="gpt-35-turbo", # engine = "deployment_name".
77+
messages=[
78+
{"role": "system", "content": "You are a helpful assistant."},
79+
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
80+
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
81+
{"role": "user", "content": "Do other Azure AI services support this too?"}
82+
]
83+
)
84+
85+
print(response)
86+
print(response['choices'][0]['message']['content'])
87+
```
88+
89+
# [OpenAI Python 1.0](#tab/python-new)
90+
91+
You need to set the `model` variable to the deployment name you chose when you deployed the GPT-3.5-Turbo or GPT-4 models. Entering the model name will result in an error unless you chose a deployment name that is identical to the underlying model name.
92+
93+
```python
94+
import os
95+
from openai import AzureOpenAI
96+
97+
client = AzureOpenAI(
98+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
99+
api_key=os.getenv("AZURE_OPENAI_KEY"),
100+
api_version="2023-05-15"
101+
)
102+
103+
response = client.chat.completions.create(
104+
model="gpt-35-turbo", # model = "deployment_name".
105+
messages=[
106+
{"role": "system", "content": "You are a helpful assistant."},
107+
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
108+
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
109+
{"role": "user", "content": "Do other Azure AI services support this too?"}
110+
]
111+
)
112+
113+
print(response.choices[0].message.content)
114+
```
115+
116+
---
76117

77-
> [!IMPORTANT]
78-
> For production, use a secure way of storing and accessing your credentials like [Azure Key Vault](../../../key-vault/general/overview.md). For more information about credential security, see the Azure AI services [security](../../security-features.md) article.
118+
> [!IMPORTANT]
119+
> For production, use a secure way of storing and accessing your credentials like [Azure Key Vault](../../../key-vault/general/overview.md). For more information about credential security, see the Azure AI services [security](../../security-features.md) article.
79120
80121
3. Run the application with the `python` command on your quickstart file:
81122

0 commit comments

Comments
 (0)