Spaces:
Sleeping
Sleeping
Update src/RAGSample.py
Browse files- src/RAGSample.py +15 -12
src/RAGSample.py
CHANGED
@@ -355,25 +355,28 @@ def setup_rag_chain() -> Runnable:
|
|
355 |
"""Sets up the RAG chain with a prompt template and an LLM."""
|
356 |
# Define the prompt template for the LLM
|
357 |
prompt = PromptTemplate(
|
358 |
-
|
359 |
-
|
|
|
|
|
360 |
Instructions:
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
- This information is for educational purposes only
|
369 |
|
370 |
-
Question: {question}
|
371 |
Documents: {documents}
|
372 |
|
373 |
-
|
|
|
|
|
374 |
input_variables=["question", "documents"],
|
375 |
)
|
376 |
|
|
|
377 |
try:
|
378 |
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
|
379 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
355 |
"""Sets up the RAG chain with a prompt template and an LLM."""
|
356 |
# Define the prompt template for the LLM
|
357 |
prompt = PromptTemplate(
|
358 |
+
template="""Context: You are a medical information assistant that answers health questions using verified medical documents.
|
359 |
+
|
360 |
+
Primary Task: Answer the medical question using ONLY the provided documents.
|
361 |
+
|
362 |
Instructions:
|
363 |
+
1. For medical questions: Provide a clear, accurate answer based solely on the document content
|
364 |
+
2. If documents lack sufficient information: "I don't have enough information in the provided documents to answer this question"
|
365 |
+
3. For non-medical questions: "I specialize in medical information. Please ask a health-related question."
|
366 |
+
4. For identity questions: "I am a medical information assistant designed to help answer health-related questions based on verified medical documents."
|
367 |
+
5. Always use patient-friendly language
|
368 |
+
6. Keep responses 2-4 sentences maximum
|
369 |
+
7. For serious symptoms, recommend consulting healthcare professionals
|
|
|
370 |
|
|
|
371 |
Documents: {documents}
|
372 |
|
373 |
+
Question: {question}
|
374 |
+
|
375 |
+
Medical Answer:""",
|
376 |
input_variables=["question", "documents"],
|
377 |
)
|
378 |
|
379 |
+
|
380 |
try:
|
381 |
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
|
382 |
model = AutoModelForCausalLM.from_pretrained(
|