Spaces:
Runtime error
Runtime error
Update app.py
Browse files163 unmodified lines1641651661671681691701711721731741751671681691701711721731741751761771783 unmodified lines182183184185185186187188189190191192193194195196197198199200201202203204205206207208209163 unmodified lines collected_messages = [] key = os.getenv('OPENAI_API_KEY') client.api_key = key for chunk in client.chat.completions.create( model='gpt-3.5-turbo', messages=conversation, temperature=0.5, stream=True ): collected_chunks.append(chunk) # save the event response chunk_message = chunk['choices'][0]['delta'] # extract the message
client = AsyncOpenAI() stream = await 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: chunk_message = (part.choices[0].delta.content or "") collected_messages.append(chunk_message) # save the message content=chunk["choices"][0].get("delta",{}).get("content") try:3 unmodified lines res_box.markdown(f'*{result}*') except: st.write(' ') full_reply_content = ''.join([m.get('content', '') for m in collected_messages])
#for chunk in client.chat.completions.create( # model='gpt-3.5-turbo', # messages=conversation, # temperature=0.5, # stream=True #): # collected_chunks.append(chunk) # save the event response # chunk_message = chunk['choices'][0]['delta'] # extract the message # collected_messages.append(chunk_message) # save the message # content=chunk["choices"][0].get("delta",{}).get("content") # try: # report.append(content) # if len(content) > 0: # result = "".join(report).strip() # res_box.markdown(f'*{result}*') # except: # st.write(' ') # full_reply_content = ''.join([m.get('content', '') for m in collected_messages]) st.write("Elapsed time:") st.write(time.time() - start_time) readitaloud(full_reply_content)app.py+30-10