Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,31 +118,22 @@ def get_conversational_chain():
|
|
| 118 |
if model is None:
|
| 119 |
return None
|
| 120 |
|
| 121 |
-
system_prompt = """
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
"This topic or this question does not contain the data that you uploaded."
|
| 134 |
-
|
| 135 |
-
### Constraints
|
| 136 |
-
- Do not apologize (e.g., "I'm sorry, but...").
|
| 137 |
-
- Do not provide partial answers.
|
| 138 |
-
- Do not explain why the information is missing.
|
| 139 |
-
- Only output the fallback sentence if the data is missing.
|
| 140 |
-
"""
|
| 141 |
|
| 142 |
prompt = ChatPromptTemplate.from_messages([
|
| 143 |
("system", system_prompt),
|
| 144 |
-
|
| 145 |
-
("human", "Question: {input}")
|
| 146 |
])
|
| 147 |
|
| 148 |
# Create a simple chain using the pipe operator (|)
|
|
@@ -184,23 +175,13 @@ def user_input(user_question, db):
|
|
| 184 |
# Try to get string representation
|
| 185 |
st.write(str(response))
|
| 186 |
|
| 187 |
-
#
|
| 188 |
-
# st.markdown("---")
|
| 189 |
-
# st.markdown("#### 📄 Source Pages:")
|
| 190 |
|
| 191 |
-
# # Use a set to avoid duplicate page numbers
|
| 192 |
-
# unique_sources = set()
|
| 193 |
-
# for doc in docs:
|
| 194 |
-
# page_num = doc.metadata.get("page", "Unknown")
|
| 195 |
-
# file_name = doc.metadata.get("source", "Unknown")
|
| 196 |
-
# unique_sources.add(f"{file_name} (Page {page_num})")
|
| 197 |
-
|
| 198 |
-
# # Display sources cleanly
|
| 199 |
-
# for source in unique_sources:
|
| 200 |
-
# st.markdown(f"- {source}")
|
| 201 |
|
| 202 |
except Exception as e:
|
| 203 |
st.error(f"Error: {e}")
|
|
|
|
|
|
|
| 204 |
|
| 205 |
# --- Main App ---
|
| 206 |
def main():
|
|
|
|
| 118 |
if model is None:
|
| 119 |
return None
|
| 120 |
|
| 121 |
+
system_prompt = """You are a helpful AI assistant that answers questions based on the provided document content.
|
| 122 |
+
|
| 123 |
+
### Context from Documents:
|
| 124 |
+
{context}
|
| 125 |
+
|
| 126 |
+
### Instructions:
|
| 127 |
+
1. Read the context carefully and extract relevant information to answer the user's question.
|
| 128 |
+
2. Base your answer ONLY on the information provided in the context above.
|
| 129 |
+
3. If the information needed to answer the question is not in the context, respond with: "I couldn't find this information in the provided documents. Please upload documents that contain the relevant information."
|
| 130 |
+
4. Be concise and direct in your answers.
|
| 131 |
+
5. If asking for clarification helps, you can ask follow-up questions.
|
| 132 |
+
6. Always cite which page or section your information comes from when possible."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
prompt = ChatPromptTemplate.from_messages([
|
| 135 |
("system", system_prompt),
|
| 136 |
+
("human", "{input}")
|
|
|
|
| 137 |
])
|
| 138 |
|
| 139 |
# Create a simple chain using the pipe operator (|)
|
|
|
|
| 175 |
# Try to get string representation
|
| 176 |
st.write(str(response))
|
| 177 |
|
| 178 |
+
# 4. Display Retrieved Documents (Debug Info)
|
|
|
|
|
|
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
except Exception as e:
|
| 182 |
st.error(f"Error: {e}")
|
| 183 |
+
import traceback
|
| 184 |
+
st.error(traceback.format_exc())
|
| 185 |
|
| 186 |
# --- Main App ---
|
| 187 |
def main():
|