Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,12 +5,9 @@ import os # Import the os module
|
|
| 5 |
# Fetch the API key from an environment variable
|
| 6 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
|
| 8 |
-
st.title("💬
|
| 9 |
st.caption("")
|
| 10 |
|
| 11 |
-
# Select model using a dropdown
|
| 12 |
-
model_choice = st.selectbox('Choose a model:', ['gpt-3.5-turbo', 'gpt-4-turbo'])
|
| 13 |
-
|
| 14 |
# Initialize session state for storing messages if it doesn't already exist
|
| 15 |
if "messages" not in st.session_state:
|
| 16 |
st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
|
|
@@ -19,7 +16,6 @@ if "messages" not in st.session_state:
|
|
| 19 |
for msg in st.session_state.messages:
|
| 20 |
st.chat_message(msg["role"]).write(msg["content"])
|
| 21 |
|
| 22 |
-
|
| 23 |
# Input for new prompts
|
| 24 |
prompt = st.chat_input("Enter your question:")
|
| 25 |
if prompt:
|
|
@@ -34,11 +30,9 @@ if prompt:
|
|
| 34 |
# Use a spinner to indicate that the model is generating a response
|
| 35 |
with st.spinner('Thinking...'):
|
| 36 |
client = OpenAI(api_key=openai_api_key)
|
| 37 |
-
response = client.chat.completions.create(model=
|
| 38 |
msg = response.choices[0].message.content
|
| 39 |
|
| 40 |
# Append and display the assistant's response
|
| 41 |
st.session_state.messages.append({"role": "assistant", "content": msg})
|
| 42 |
st.chat_message("assistant").write(msg)
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 5 |
# Fetch the API key from an environment variable
|
| 6 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
|
| 8 |
+
st.title("💬 Chatbot")
|
| 9 |
st.caption("")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# Initialize session state for storing messages if it doesn't already exist
|
| 12 |
if "messages" not in st.session_state:
|
| 13 |
st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
|
|
|
|
| 16 |
for msg in st.session_state.messages:
|
| 17 |
st.chat_message(msg["role"]).write(msg["content"])
|
| 18 |
|
|
|
|
| 19 |
# Input for new prompts
|
| 20 |
prompt = st.chat_input("Enter your question:")
|
| 21 |
if prompt:
|
|
|
|
| 30 |
# Use a spinner to indicate that the model is generating a response
|
| 31 |
with st.spinner('Thinking...'):
|
| 32 |
client = OpenAI(api_key=openai_api_key)
|
| 33 |
+
response = client.chat.completions.create(model="gpt-3.5-turbo", messages=st.session_state.messages)
|
| 34 |
msg = response.choices[0].message.content
|
| 35 |
|
| 36 |
# Append and display the assistant's response
|
| 37 |
st.session_state.messages.append({"role": "assistant", "content": msg})
|
| 38 |
st.chat_message("assistant").write(msg)
|
|
|
|
|
|