Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -262,21 +262,47 @@ def page1():
|
|
| 262 |
query = "Was bedeutet die Vorhaltefinanzierung?"
|
| 263 |
|
| 264 |
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
|
| 282 |
#if query:
|
|
|
|
| 262 |
query = "Was bedeutet die Vorhaltefinanzierung?"
|
| 263 |
|
| 264 |
|
| 265 |
+
if query:
|
| 266 |
+
# Generiere das 'full_query' direkt ohne separate Funktion
|
| 267 |
+
standard_prompt = ("Schreibe immer höflich und auf antworte immer in der Sprache, "
|
| 268 |
+
"in der der User auch schreibt. Formuliere immer ganze freundliche "
|
| 269 |
+
"ganze Sätze und biete, wenn möglich, auch mehr Informationen "
|
| 270 |
+
"(aber nicht mehr als 1 Satz mehr). Wenn der User sehr vage schreibt, "
|
| 271 |
+
"frage nach - gerade wenn es um Jahre geht, frage nur nach Jahren, "
|
| 272 |
+
"wenn du zu dem Thema auch Daten zu bestimmten Jahren hast.")
|
| 273 |
+
full_query = standard_prompt + " " + query
|
| 274 |
+
|
| 275 |
+
# Kombiniere die gesamte Session-Historie mit der aktuellen Anfrage
|
| 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 |
+
# Aktualisiere die Chat-Historie nach der Antwort des Bots
|
| 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 |
+
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
| 293 |
+
new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
|
| 294 |
+
|
| 295 |
+
# Clear the input field after the query is made
|
| 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 |
+
except Exception as e:
|
| 302 |
+
st.error(f"Upsi, an unexpected error occurred: {e}")
|
| 303 |
+
# [Rest des Codes bleibt unverändert]
|
| 304 |
+
|
| 305 |
+
|
| 306 |
|
| 307 |
|
| 308 |
#if query:
|