@@ -23,7 +23,10 @@ import asyncio
2323from openai import AsyncOpenAI
2424
2525# gets API Key from environment variable OPENAI_API_KEY
26- client = AsyncOpenAI(base_url = " http://localhost:3928/v1/" , api_key = " sk-xxx" )
26+ client = AsyncOpenAI(
27+ base_url = " http://localhost:3928/v1/" ,
28+ api_key = " sk-xxx"
29+ )
2730
2831
2932async def main () -> None :
@@ -75,22 +78,16 @@ asyncio.run(main())
7578``` python
7679from openai import AzureOpenAI
7780
78- openai.api_key = ' ...' # Default is environment variable AZURE_OPENAI_API_KEY
81+ openai.api_key = ' ...' # Default is AZURE_OPENAI_API_KEY
7982
8083stream = AzureOpenAI(
8184 api_version = api_version,
82- # https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource
8385 azure_endpoint = " https://example-endpoint.openai.azure.com" ,
8486)
8587
8688completion = client.chat.completions.create(
8789 model = " deployment-name" , # e.g. gpt-35-instant
88- messages = [
89- {
90- " role" : " user" ,
91- " content" : " How do I output all files in a directory using Python?" ,
92- },
93- ],
90+ messages = [{" role" : " user" , " content" : " Say this is a test" }],
9491 stream = True ,
9592)
9693for part in stream:
@@ -116,11 +113,15 @@ import asyncio
116113from openai import AsyncOpenAI
117114
118115# gets API Key from environment variable OPENAI_API_KEY
119- client = AsyncOpenAI(base_url = " http://localhost:3928/v1/" , api_key = " sk-xxx" )
116+ client = AsyncOpenAI(base_url = " http://localhost:3928/v1/" ,
117+ api_key = " sk-xxx" )
120118
121119
122120async def main () -> None :
123- embedding = await client.embeddings.create(input = ' Hello How are you?' , model = ' text-embedding-ada-002' )
121+ embedding = await client.embeddings.create(
122+ input = ' Hello How are you?' ,
123+ model = ' text-embedding-ada-002'
124+ )
124125 print (embedding)
125126
126127asyncio.run(main())
@@ -141,7 +142,10 @@ client = AsyncOpenAI(api_key="sk-xxx")
141142
142143
143144async def main () -> None :
144- embedding = await client.embeddings.create(input = ' Hello How are you?' , model = ' text-embedding-ada-002' )
145+ embedding = await client.embeddings.create(
146+ input = ' Hello How are you?' ,
147+ model = ' text-embedding-ada-002'
148+ )
145149 print (embedding)
146150
147151asyncio.run(main())
0 commit comments