Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -62,16 +62,18 @@ def conversation(qa_chain, message, history):
|
|
62 |
if not message.strip():
|
63 |
return qa_chain, [{"role": "system", "content": "Bitte eine Frage eingeben!"}], history
|
64 |
try:
|
65 |
-
history = history[-5:] #
|
66 |
response = qa_chain.invoke({"question": message, "chat_history": history})
|
67 |
response_text = response["answer"]
|
68 |
sources = [doc.metadata["source"] for doc in response["source_documents"]]
|
69 |
sources_text = "\n".join(sources) if sources else "Keine Quellen verfügbar"
|
70 |
-
|
|
|
|
|
71 |
{"role": "user", "content": message},
|
72 |
{"role": "assistant", "content": f"{response_text}\n\n**Quellen:**\n{sources_text}"}
|
73 |
]
|
74 |
-
return qa_chain, formatted_response,
|
75 |
except Exception as e:
|
76 |
return qa_chain, [{"role": "system", "content": f"Fehler: {str(e)}"}], history
|
77 |
|
|
|
62 |
if not message.strip():
|
63 |
return qa_chain, [{"role": "system", "content": "Bitte eine Frage eingeben!"}], history
|
64 |
try:
|
65 |
+
history = history[-5:] # Beschränke den Verlauf auf die letzten 5 Nachrichten
|
66 |
response = qa_chain.invoke({"question": message, "chat_history": history})
|
67 |
response_text = response["answer"]
|
68 |
sources = [doc.metadata["source"] for doc in response["source_documents"]]
|
69 |
sources_text = "\n".join(sources) if sources else "Keine Quellen verfügbar"
|
70 |
+
|
71 |
+
# Strukturierte Rückgabe an `gr.Chatbot`
|
72 |
+
formatted_response = history + [
|
73 |
{"role": "user", "content": message},
|
74 |
{"role": "assistant", "content": f"{response_text}\n\n**Quellen:**\n{sources_text}"}
|
75 |
]
|
76 |
+
return qa_chain, formatted_response, formatted_response
|
77 |
except Exception as e:
|
78 |
return qa_chain, [{"role": "system", "content": f"Fehler: {str(e)}"}], history
|
79 |
|