File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
articles/ai-services/openai/how-to Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -211,16 +211,21 @@ Additional examples including how to handle semantic text search without `embedd
211
211
OpenAI doesn't support calling asynchronous methods in the module-level client, instead you should instantiate an async client.
212
212
213
213
``` python
214
+ import os
215
+ import asyncio
214
216
from openai import AsyncAzureOpenAI
215
217
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" }])
218
+ async def main ():
219
+ client = AsyncAzureOpenAI(
220
+ api_key = os.getenv(" AZURE_OPENAI_KEY" ),
221
+ api_version = " 2023-10-01-preview" ,
222
+ azure_endpoint = os.getenv(" AZURE_OPENAI_ENDPOINT" )
223
+ )
224
+ response = await client.chat.completions.create(model = " gpt-35-turbo" , messages = [{" role" : " user" , " content" : " Hello world" }])
222
225
223
- print (response.model_dump_json(indent = 2 ))
226
+ print (response.model_dump_json(indent = 2 ))
227
+
228
+ asyncio.run(main())
224
229
```
225
230
226
231
## Authentication
You can’t perform that action at this time.
0 commit comments