Skip to content

Commit 6783725

Browse files
committed
update
1 parent 893c571 commit 6783725

File tree

1 file changed

+40
-32
lines changed
  • articles/ai-services/openai/includes

1 file changed

+40
-32
lines changed

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

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,20 @@ keywords:
2929

3030
Install the OpenAI Python client library with:
3131

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

38+
# [OpenAI Python 1.0](#tab/python-new)
39+
40+
```console
41+
pip install openai
42+
```
43+
44+
---
45+
3646
> [!NOTE]
3747
> 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.
3848
@@ -64,48 +74,46 @@ Create and assign persistent environment variables for your key and endpoint.
6474

6575
2. Replace the contents of quickstart.py with the following code. Modify the code to add your key, endpoint, and deployment name:
6676

67-
# [Python 0.28.1](#tab/python)
77+
# [OpenAI Python 0.28.1](#tab/python)
6878

6979
```python
70-
import os
71-
import requests
72-
import json
73-
import openai
74-
75-
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
76-
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT") # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
77-
openai.api_type = 'azure'
78-
openai.api_version = '2023-05-15' # this may change in the future
79-
80-
deployment_name='REPLACE_WITH_YOUR_DEPLOYMENT_NAME' #This will correspond to the custom name you chose for your deployment when you deployed a model.
81-
82-
# Send a completion call to generate an answer
83-
print('Sending a test completion job')
84-
start_phrase = 'Write a tagline for an ice cream shop. '
85-
response = openai.Completion.create(engine=deployment_name, prompt=start_phrase, max_tokens=10)
86-
text = response['choices'][0]['text'].replace('\n', '').replace(' .', '.').strip()
87-
print(start_phrase+text)
80+
import os
81+
import openai
82+
83+
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
84+
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT") # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
85+
openai.api_type = 'azure'
86+
openai.api_version = '2023-05-15' # this may change in the future
87+
88+
deployment_name='REPLACE_WITH_YOUR_DEPLOYMENT_NAME' #This will correspond to the custom name you chose for your deployment when you deployed a model.
89+
90+
# Send a completion call to generate an answer
91+
print('Sending a test completion job')
92+
start_phrase = 'Write a tagline for an ice cream shop. '
93+
response = openai.Completion.create(engine=deployment_name, prompt=start_phrase, max_tokens=10)
94+
text = response['choices'][0]['text'].replace('\n', '').replace(' .', '.').strip()
95+
print(start_phrase+text)
8896
```
8997

90-
# [Python 1.0](#tab/python-new)
98+
# [OpenAI Python 1.0](#tab/python-new)
9199

92100
```python
93-
import os
94-
from openai import AzureOpenAI
101+
import os
102+
from openai import AzureOpenAI
95103

96-
client = AzureOpenAI(
97-
api_key=os.getenv("AZURE_OPENAI_KEY"),
98-
api_version="2023-10-01-preview",
99-
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
104+
client = AzureOpenAI(
105+
api_key=os.getenv("AZURE_OPENAI_KEY"),
106+
api_version="2023-10-01-preview",
107+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
100108
)
101109

102-
deployment_name='gpt-35-turbo-instruct' #This will correspond to the custom name you chose for your deployment when you deployed a model.
110+
deployment_name='REPLACE_WITH_YOUR_DEPLOYMENT_NAME' #This will correspond to the custom name you chose for your deployment when you deployed a model.
103111

104-
# Send a completion call to generate an answer
105-
print('Sending a test completion job')
106-
start_phrase = 'Write a tagline for an ice cream shop. '
107-
response = client.completions.create(model=deployment_name, prompt=start_phrase, max_tokens=10)
108-
print(response.choices[0].text)
112+
# Send a completion call to generate an answer
113+
print('Sending a test completion job')
114+
start_phrase = 'Write a tagline for an ice cream shop. '
115+
response = client.completions.create(model=deployment_name, prompt=start_phrase, max_tokens=10)
116+
print(response.choices[0].text)
109117
```
110118

111119
---

0 commit comments

Comments
 (0)