Spaces:
Runtime error
Runtime error
Update app.py
Browse files163 unmodified lines1641651661671681691701711721731741751761771783 unmodified lines182183184185186187188189163 unmodified linescollected_messages = []key = os.getenv('OPENAI_API_KEY')client.api_key = keyfor 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 responsechunk_message = chunk['choices'][0]['delta'] # extract the messagecollected_messages.append(chunk_message) # save the messagecontent=chunk["choices"][0].get("delta",{}).get("content")try:3 unmodified linesres_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)163 unmodified lines1641651661671681691701711721731741751761771783 unmodified lines182183184185186187188189190191192193194195196197198199200201202203204205206207208209163 unmodified linescollected_messages = []key = os.getenv('OPENAI_API_KEY')client.api_key = keyclient = 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 messagecontent=chunk["choices"][0].get("delta",{}).get("content")try:3 unmodified linesres_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