afatuddin commited on
Commit
762fe5a
·
verified ·
1 Parent(s): a8740f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -35
app.py CHANGED
@@ -118,31 +118,22 @@ def get_conversational_chain():
118
  if model is None:
119
  return None
120
 
121
- system_prompt = """
122
- ### Role
123
- You are a strict and precise AI assistant dedicated to answering questions based solely on the provided document content.
124
-
125
- ### Context
126
- {context}
127
-
128
- ### Instructions
129
- 1. Analyze the user's query and cross-reference it strictly with the "Context" provided above.
130
- 2. If the answer to the query is explicitly found within the context, answer it clearly and concisely.
131
- 3. **CRITICAL RESTRICTION:** You must NOT use any outside knowledge, pre-trained data, or assumptions.
132
- 4. **FALLBACK:** If the answer is not contained in the context, or if the query is unrelated to the provided data, you must output EXACTLY the following sentence and nothing else:
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
- # The user's question will be passed here as the "human" message
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
- # # 4. Display Page Numbers (New Feature)
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():