Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,7 +93,7 @@ if prompt := st.chat_input("Message..."):
|
|
| 93 |
if not api_key:
|
| 94 |
st.error("API key required")
|
| 95 |
st.stop()
|
| 96 |
-
|
| 97 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 98 |
with st.chat_message("user", avatar=USER_PFP):
|
| 99 |
st.markdown(prompt)
|
|
@@ -101,10 +101,18 @@ if prompt := st.chat_input("Message..."):
|
|
| 101 |
try:
|
| 102 |
co = cohere.ClientV2(api_key)
|
| 103 |
with st.chat_message("assistant", avatar=AI_PFP):
|
| 104 |
-
response = co.chat(
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
st.markdown(reply)
|
|
|
|
| 107 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
| 108 |
-
|
| 109 |
except Exception as e:
|
| 110 |
-
st.error(f"Error: {str(e)}")
|
|
|
|
| 93 |
if not api_key:
|
| 94 |
st.error("API key required")
|
| 95 |
st.stop()
|
| 96 |
+
|
| 97 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 98 |
with st.chat_message("user", avatar=USER_PFP):
|
| 99 |
st.markdown(prompt)
|
|
|
|
| 101 |
try:
|
| 102 |
co = cohere.ClientV2(api_key)
|
| 103 |
with st.chat_message("assistant", avatar=AI_PFP):
|
| 104 |
+
response = co.chat(
|
| 105 |
+
model=selected_model,
|
| 106 |
+
messages=st.session_state.messages
|
| 107 |
+
)
|
| 108 |
+
if hasattr(response, "message") and hasattr(response.message, "content") and hasattr(response.message.content, "text"):
|
| 109 |
+
reply = response.message.content.text
|
| 110 |
+
else:
|
| 111 |
+
st.write(response)
|
| 112 |
+
reply = "❗️Couldn't find response.message.content.text in the Cohere response."
|
| 113 |
st.markdown(reply)
|
| 114 |
+
|
| 115 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
| 116 |
+
|
| 117 |
except Exception as e:
|
| 118 |
+
st.error(f"Error: {str(e)}")
|