import openai import streamlit as st # YOU MUST HAVE USER ENV VARAIABLE SET FOR "OPENAI_API_KEY" placeholder_response_user_input = st.empty() user_input = placeholder_response_user_input.text_input("Enter your question here", key= "user_input") print("app started") # streaming_response = [] completion_text = '' placeholder_response = st.empty() # put a button to submit the text input if user_input: placeholder_response.text("Waiting for response...") print('getting response') response = openai.Completion.create( model='text-davinci-003', prompt=user_input, max_tokens=50, temperature=0, stream=True, # HERE WE SET STREAMING TO TRUE ) for r in response: r_text = r['choices'][0]['text'] completion_text += r_text # write the text to the web app placeholder_response.markdown(completion_text) print("end") # print(f"Full text received: {completion_text}")