Update app.py
Browse files
app.py
CHANGED
|
@@ -151,7 +151,12 @@ prompt = ChatPromptTemplate.from_messages(
|
|
| 151 |
# Build the chain that will combine documents with the prompt.
|
| 152 |
question_answer_chain = create_stuff_documents_chain(ChatOpenAI(model_name="gpt-4o-mini", temperature=0), prompt)
|
| 153 |
rag_chain = create_retrieval_chain(retriever, question_answer_chain)
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
# -------------------------------
|
| 156 |
# Gradio Interface and Conversation Handling
|
| 157 |
# -------------------------------
|
|
@@ -207,7 +212,11 @@ def message_and_history(message, history):
|
|
| 207 |
conversation_context = "\n".join(
|
| 208 |
[f"{msg['role']}: {msg['content'].replace('<b>LA2050 Navigator:</b><br>', '')}" for msg in history[-3:]]
|
| 209 |
)
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
chain_input = {"input": conversation_context}
|
| 212 |
|
| 213 |
try:
|
|
|
|
| 151 |
# Build the chain that will combine documents with the prompt.
|
| 152 |
question_answer_chain = create_stuff_documents_chain(ChatOpenAI(model_name="gpt-4o-mini", temperature=0), prompt)
|
| 153 |
rag_chain = create_retrieval_chain(retriever, question_answer_chain)
|
| 154 |
+
def debug_retrieved_docs(user_input):
|
| 155 |
+
retrieved_docs = retriever.get_relevant_documents(user_input)
|
| 156 |
+
print(f"DEBUG: Retrieved {len(retrieved_docs)} documents.")
|
| 157 |
+
for i, doc in enumerate(retrieved_docs):
|
| 158 |
+
print(f"Doc {i+1}: {doc.metadata}")
|
| 159 |
+
return retrieved_docs
|
| 160 |
# -------------------------------
|
| 161 |
# Gradio Interface and Conversation Handling
|
| 162 |
# -------------------------------
|
|
|
|
| 212 |
conversation_context = "\n".join(
|
| 213 |
[f"{msg['role']}: {msg['content'].replace('<b>LA2050 Navigator:</b><br>', '')}" for msg in history[-3:]]
|
| 214 |
)
|
| 215 |
+
retrieved_docs = retriever.get_relevant_documents(conversation_context)
|
| 216 |
+
print(f"DEBUG: Retrieved {len(retrieved_docs)} documents.")
|
| 217 |
+
for i, doc in enumerate(retrieved_docs):
|
| 218 |
+
# Print out key metadata fields to verify correctness.
|
| 219 |
+
print(f"Doc {i+1} Metadata: {doc.metadata}")
|
| 220 |
chain_input = {"input": conversation_context}
|
| 221 |
|
| 222 |
try:
|