Spaces:
Runtime error
Runtime error
Update app.py
Browse files17 unmodified lines181920212223212223242525262728136 unmodified lines16516616716816916816917017117217317417417517617717 unmodified lines
import httpx # add 11/13/23import asyncio#from openai import OpenAIfrom openai import AsyncOpenAIclient = AsyncOpenAI(from openai import OpenAI#from openai import AsyncOpenAIclient = OpenAI( # defaults to os.environ.get("OPENAI_API_KEY") # api_key="My API Key", api_key= os.getenv('OPENAI_API_KEY'))
136 unmodified lines key = os.getenv('OPENAI_API_KEY') client.api_key = key
client = AsyncOpenAI() stream = await client.chat.completions.create( client = OpenAI() stream = client.chat.completions.create( prompt="Say this is a test", messages=[{"role": "user", "content": "Say this is a test"}], stream=True, ) async for part in stream: for part in stream: chunk_message = (part.choices[0].delta.content or "") collected_messages.append(chunk_message) # save the message content=chunk["choices"][0].get("delta",{}).get("content")app.py+7-7