Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -262,48 +262,53 @@ def page1():
|
|
262 |
query = "Was bedeutet die Vorhaltefinanzierung?"
|
263 |
|
264 |
if query:
|
265 |
-
# Display the type of 'query'
|
266 |
st.text(f"Type of query: {type(query)}")
|
267 |
-
|
268 |
-
standard_prompt = ("Schreibe immer höflich und auf antworte immer in der Sprache, "
|
269 |
"in der der User auch schreibt. Formuliere immer ganze freundliche "
|
270 |
-
"
|
271 |
"(aber nicht mehr als 1 Satz mehr). Wenn der User sehr vage schreibt, "
|
272 |
"frage nach - gerade wenn es um Jahre geht, frage nur nach Jahren, "
|
273 |
"wenn du zu dem Thema auch Daten zu bestimmten Jahren hast.")
|
274 |
full_query = standard_prompt + " " + query
|
275 |
-
|
276 |
combined_query = combine_history_with_query(full_query, st.session_state['chat_history_page1'])
|
277 |
-
|
278 |
with st.spinner('Bot is thinking...'):
|
279 |
chain = load_chatbot()
|
280 |
docs = VectorStore.similarity_search(query=combined_query, k=5)
|
281 |
with get_openai_callback() as cb:
|
282 |
response = chain.run(input_documents=docs, question=combined_query)
|
283 |
response = handle_no_answer(response)
|
284 |
-
|
285 |
-
# Update chat history after the bot's response
|
286 |
st.session_state['chat_history_page1'].append(("User", query))
|
287 |
st.session_state['chat_history_page1'].append(("Bot", response))
|
288 |
-
|
|
|
|
|
|
|
289 |
# Display new messages at the bottom
|
290 |
new_messages = st.session_state['chat_history_page1'][-2:]
|
291 |
for chat in new_messages:
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
query = ""
|
297 |
-
|
298 |
-
# Mark all messages as old after displaying
|
299 |
-
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
300 |
-
|
301 |
|
|
|
302 |
except Exception as e:
|
303 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
304 |
-
# [Rest des Codes bleibt unverändert]
|
305 |
|
306 |
-
|
307 |
|
308 |
|
309 |
|
|
|
262 |
query = "Was bedeutet die Vorhaltefinanzierung?"
|
263 |
|
264 |
if query:
|
|
|
265 |
st.text(f"Type of query: {type(query)}")
|
266 |
+
standard_prompt = ("Schreibe immer höflich und antworte immer in der Sprache, "
|
|
|
267 |
"in der der User auch schreibt. Formuliere immer ganze freundliche "
|
268 |
+
"Sätze und biete, wenn möglich, auch mehr Informationen "
|
269 |
"(aber nicht mehr als 1 Satz mehr). Wenn der User sehr vage schreibt, "
|
270 |
"frage nach - gerade wenn es um Jahre geht, frage nur nach Jahren, "
|
271 |
"wenn du zu dem Thema auch Daten zu bestimmten Jahren hast.")
|
272 |
full_query = standard_prompt + " " + query
|
|
|
273 |
combined_query = combine_history_with_query(full_query, st.session_state['chat_history_page1'])
|
274 |
+
|
275 |
with st.spinner('Bot is thinking...'):
|
276 |
chain = load_chatbot()
|
277 |
docs = VectorStore.similarity_search(query=combined_query, k=5)
|
278 |
with get_openai_callback() as cb:
|
279 |
response = chain.run(input_documents=docs, question=combined_query)
|
280 |
response = handle_no_answer(response)
|
|
|
|
|
281 |
st.session_state['chat_history_page1'].append(("User", query))
|
282 |
st.session_state['chat_history_page1'].append(("Bot", response))
|
283 |
+
|
284 |
+
# Diagnostic print: Display the entire chat history
|
285 |
+
st.text(f"Current chat history: {st.session_state['chat_history_page1']}")
|
286 |
+
|
287 |
# Display new messages at the bottom
|
288 |
new_messages = st.session_state['chat_history_page1'][-2:]
|
289 |
for chat in new_messages:
|
290 |
+
try:
|
291 |
+
# Diagnostic print: Display each chat entry
|
292 |
+
st.text(f"Chat entry: {chat}")
|
293 |
+
|
294 |
+
# Ensure tuple has two elements
|
295 |
+
if len(chat) != 2:
|
296 |
+
raise ValueError(f"Invalid chat tuple: {chat}")
|
297 |
+
|
298 |
+
speaker, message = chat
|
299 |
+
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if speaker == "User" else "#ffeecf"
|
300 |
+
new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{speaker}: {message}</div>", unsafe_allow_html=True)
|
301 |
+
except IndexError as e:
|
302 |
+
st.error(f"Error processing chat entry: {e}")
|
303 |
+
except Exception as e:
|
304 |
+
st.error(f"Unexpected error: {e}")
|
305 |
+
|
306 |
query = ""
|
|
|
|
|
|
|
|
|
307 |
|
308 |
+
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
309 |
except Exception as e:
|
310 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
|
|
311 |
|
|
|
312 |
|
313 |
|
314 |
|