Skip to content

Commit f1bbd42

Browse files
Merge pull request #257933 from mrbullwinkle/mrb_11_07_2023_oai_migration
[Azure OpenAI] add async example
2 parents be5e55d + 72bef93 commit f1bbd42

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

articles/ai-services/openai/how-to/migration.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,23 @@ Additional examples including how to handle semantic text search without `embedd
206206

207207
---
208208

209+
## Async
210+
211+
OpenAI doesn't support calling asynchronous methods in the module-level client, instead you should instantiate an async client.
212+
213+
```python
214+
from openai import AsyncAzureOpenAI
215+
216+
client = AsyncAzureOpenAI(
217+
api_key = os.getenv("AZURE_OPENAI_KEY"),
218+
api_version = "2023-10-01-preview",
219+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
220+
)
221+
response = await client.chat.completions.create(model="gpt-35-turbo", messages=[{"role": "user", "content": "Hello world"}])
222+
223+
print(response.model_dump_json(indent=2))
224+
```
225+
209226
## Authentication
210227

211228
```python

0 commit comments

Comments
 (0)