import streamlit as st
import pycafe
reason = """We need an OpenAI API key to generate text.
Go to [OpenAI](https://platform.openai.com/account/api-keys) to get one.
Or read [this](https://www.rebelmouse.com/openai-account-set-up) article for
more information.
Or read more [about secrets on PyCafe](/docs/secrets)
"""
api_key = pycafe.get_secret("OPENAI_API_KEY", reason=reason)
from openai import OpenAI
client = OpenAI(api_key=api_key)
question = "How cool would it be if we could run streamlit and dash in the browser?"
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a concise and friendly assistant."},
{
"role": "user",
"content": question,
}
]
)
st.markdown(f"**{question}**")
with st.spinner():
st.write(completion.choices[0].message.content)