gpt-playground / app.py
keisuke-tada's picture
Update app.py
37e3916
raw
history blame
734 Bytes
import os
import openai
import streamlit as st
openai.api_key = os.getenv("OPENAI_API_KEY")
temperature = 0
input = st.text_input("Input")
if st.button("Submit", type="primary"):
st.markdown("----")
res_box = st.empty()
content = []
for chunk in openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=temperature,
messages=[{"role": "user", "content": input}],
stream=True,
):
chunk_content = chunk["choices"][0].get("delta", {}).get("content")
if chunk_content is not None:
content.append(chunk_content)
result = "".join(content).strip()
result = result.replace("\n", "")
res_box.markdown(result)
st.markdown("----")