You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Make sure you never destroy existing functionality when adding new functionality, unless it is a replacement or the old functionality is no longer needed.
1
3
- Never forget to update the conda environment config file when you update the requirements.txt
2
4
- Make sure there are concise and up to date docstrings that document usage.
3
5
- Debug information belongs into the command line logs, not in the app UI/UX.
6
+
- Always develop a generic solution, do not use content from specific examples in the code
7
+
- Never include content from example documents in the source code. Never leak content from provided examples into test code!
st.warning("⚠️ **Chat Disabled**: No valid document content available. Please upload a PDF document with readable text to start chatting.")
316
+
st.info("The document may have failed to process, or the extracted text may be empty. Try uploading a different PDF file.")
317
+
318
+
288
319
289
320
defgenerate_ai_response(prompt, document_text):
290
321
"""Generate AI response using Ollama with reasoning support"""
291
-
system_prompt=f"""Answer questions based on this document:
322
+
323
+
# Check if document text is empty or None
324
+
ifnotdocument_textornotdocument_text.strip():
325
+
return"I apologize, but I cannot answer your question because the document could not be processed or contains no readable text. Please try uploading a different PDF document."
326
+
327
+
system_prompt=f"""You are a document analysis assistant. You MUST ONLY answer questions that can be directly supported with citations from the provided document.
292
328
329
+
DOCUMENT CONTENT:
293
330
{document_text}
294
331
332
+
CRITICAL INSTRUCTIONS:
333
+
1. ALWAYS respond in the same language as the user's question, regardless of the document language
334
+
2. You may reason about and analyze the information in the document, but ALL reasoning must be grounded in content that can be cited from the document
335
+
3. Every factual claim in your answer MUST be supported by at least one verbatim citation from the document
336
+
4. You may draw logical conclusions and make inferences, but only based on information explicitly present in the document
337
+
5. NEVER use your training data, general knowledge, or external information - base all reasoning solely on the document content
338
+
339
+
RESPONSE LOGIC - CHOOSE ONE PATH:
340
+
PATH A - ANSWER WITH CITATIONS:
341
+
- If you can find information in the document to answer the question, provide a complete answer
342
+
- Support every factual claim with exact citations from the document
343
+
- Use the required citation format shown below
344
+
345
+
PATH B - DECLINE TO ANSWER:
346
+
- If you cannot find sufficient information in the document to answer the question, decline to answer
347
+
- Explain that the information is not available in the provided document
348
+
- Do NOT include any citations when declining to answer
349
+
- Do NOT reference any specific text from the document when declining
350
+
351
+
CRITICAL: Never mix these paths. Either answer with full citations OR decline without any citations. Never decline while providing citations - this is contradictory.
352
+
353
+
MANDATORY CITATION REQUIREMENT:
354
+
- Every factual claim in your answer MUST be backed by a verbatim citation from the document
355
+
- You may reason and analyze, but the underlying facts must be cited exactly as they appear in the document
356
+
- If you cannot provide verbatim citations to support your reasoning, do NOT provide the answer
357
+
- Citations must be exact quotes from the document, not paraphrases or interpretations
358
+
295
359
CRITICAL CITATION FORMAT:
296
360
You MUST use citations in this EXACT format for text highlighting to work:
Question: Does he have experience in the medical field?
307
-
Answer: Yes, Christian Staudt has experience in the medical field. [1] [2]
371
+
Answer: Yes, the document shows he has experience in medical applications. [1]
372
+
373
+
[1] "project development for AI applications: medical data mining & AI"
374
+
375
+
EXAMPLE OF PATH B - DECLINE TO ANSWER:
376
+
Question: What is his favorite programming language?
377
+
Answer: I cannot answer this question based on the information provided in the document. The document does not contain information about programming language preferences.
308
378
309
-
[1] "project development for AI applications: medical data mining & AI, AI for renewable energy control"
310
-
[2] "developing a prototype for data-driven measurement of global marketing campaign performance across channels"
379
+
INVALID EXAMPLE (DO NOT DO THIS):
380
+
Question: What are his hobbies?
381
+
Answer: I cannot answer this question based on the document. [1]
382
+
[1] "some text from document"
383
+
^ This is WRONG - never decline while providing citations!
311
384
312
-
RULES:
385
+
CITATION RULES:
313
386
- Citations MUST start at the beginning of a line
314
387
- Citations MUST use the format [number] "quote"
315
-
- Use exact quotes from the document, not paraphrases
388
+
- Use exact quotes from the document in their ORIGINAL language - NEVER translate citations
316
389
- Each citation on its own line
317
390
- Do NOT use colons, "Exact quote:", or other text before the quote
318
-
- IMPORTANT: Quote only the SPECIFIC text that directly answers the question, not entire sentences or paragraphs
319
-
- For time/date questions, quote only the relevant time/date, not the entire schedule line
320
-
- For specific facts, quote only the relevant fact, not surrounding context
321
-
- Keep quotes focused and precise to ensure accurate highlighting"""
391
+
- IMPORTANT: Quote meaningful phrases with context, not isolated words or numbers
392
+
- Always include descriptive context around numbers, percentages, or measurements
393
+
- Avoid quoting standalone numbers - always include the surrounding descriptive words
394
+
- Keep quotes focused but meaningful - aim for 3-8 words that capture the complete idea
395
+
- Prioritize phrases that directly answer the user's question with sufficient context for highlighting
396
+
397
+
LANGUAGE RULES:
398
+
- Respond to the user in the same language as their question
399
+
- Your explanatory text, reasoning, and analysis should be in the user's language
400
+
- Citations must remain in the original document language - do NOT translate them
401
+
- Example: If user asks in English about a German document, respond in English but keep German citations
402
+
403
+
STRICT RULES:
404
+
- If you cannot provide citations from the document for your answer, you MUST decline to answer
405
+
- Do NOT provide any information from your training data
406
+
- NEVER mix declining to answer with providing citations - this is contradictory
407
+
- Either answer with citations OR decline without citations - never both"""
0 commit comments