Skip to content

Commit 3eef5da

Browse files
committed
update
1 parent b369621 commit 3eef5da

File tree

1 file changed

+29
-4
lines changed
  • articles/ai-services/openai/includes

1 file changed

+29
-4
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ Create and assign persistent environment variables for your key and endpoint.
6464

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

67-
```python
67+
# [Python 0.28.1](#tab/python)
68+
69+
```python
6870
import os
6971
import requests
7072
import json
@@ -83,10 +85,33 @@ Create and assign persistent environment variables for your key and endpoint.
8385
response = openai.Completion.create(engine=deployment_name, prompt=start_phrase, max_tokens=10)
8486
text = response['choices'][0]['text'].replace('\n', '').replace(' .', '.').strip()
8587
print(start_phrase+text)
86-
```
88+
```
89+
90+
# [Python 1.0](#tab/python-new)
91+
92+
```python
93+
import os
94+
from openai import AzureOpenAI
95+
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")
100+
)
101+
102+
deployment_name='gpt-35-turbo-instruct' #This will correspond to the custom name you chose for your deployment when you deployed a model.
103+
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)
109+
```
110+
111+
---
87112

88-
> [!IMPORTANT]
89-
> 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.
113+
> [!IMPORTANT]
114+
> 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.
90115
91116
1. Run the application with the `python` command on your quickstart file:
92117

0 commit comments

Comments
 (0)