Spaces:
Running
Running
Upload 4 files
Browse files
app/core/prompts/evaluator_prompt.py
CHANGED
|
@@ -1,37 +1,70 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# # evaluator_prompt.py
|
| 2 |
+
|
| 3 |
+
# from langchain_core.prompts import PromptTemplate
|
| 4 |
+
|
| 5 |
+
# evaluator_prompt = PromptTemplate(
|
| 6 |
+
# input_variables=["query", "answer", "context"],
|
| 7 |
+
# template="""
|
| 8 |
+
# Evaluate the AI response.
|
| 9 |
+
|
| 10 |
+
# Rules:
|
| 11 |
+
# - Be strict
|
| 12 |
+
# - Output ONLY valid JSON
|
| 13 |
+
# - No explanation
|
| 14 |
+
|
| 15 |
+
# Query:
|
| 16 |
+
# {query}
|
| 17 |
+
|
| 18 |
+
# Answer:
|
| 19 |
+
# {answer}
|
| 20 |
+
|
| 21 |
+
# Context:
|
| 22 |
+
# {context}
|
| 23 |
+
|
| 24 |
+
# Return:
|
| 25 |
+
# {
|
| 26 |
+
# "relevance_score": number (0 to 1),
|
| 27 |
+
# "context_usage": number (0 to 1),
|
| 28 |
+
# "hallucination": true/false
|
| 29 |
+
# }
|
| 30 |
+
# """
|
| 31 |
+
# )
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# You are an evaluation system.
|
| 46 |
+
|
| 47 |
+
# Evaluate the AI response strictly based on the given context.
|
| 48 |
+
|
| 49 |
+
from langchain_core.prompts import PromptTemplate
|
| 50 |
+
|
| 51 |
+
evaluator_prompt = PromptTemplate(
|
| 52 |
+
input_variables=["query", "answer", "context"],
|
| 53 |
+
template="""You are a JSON-only evaluator. Output a single JSON object. No other text.
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Query: {query}
|
| 57 |
+
Answer: {answer}
|
| 58 |
+
Context (first 600 chars): {context}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Score these three fields:
|
| 62 |
+
- hallucination (bool): true if answer contains facts NOT in context
|
| 63 |
+
- context_usage (float 0-1): how much the answer uses the context
|
| 64 |
+
- relevance_score (float 0-1): how well the answer addresses the query
|
| 65 |
+
|
| 66 |
+
JSON:
|
| 67 |
+
""")
|
| 68 |
+
|
| 69 |
+
# Output this exact JSON and nothing else:
|
| 70 |
+
# {{"relevance_score": 0.0, "context_usage": 0.0, "hallucination": false}}
|
app/core/prompts/rag_prompt.py
CHANGED
|
@@ -5,17 +5,15 @@ from langchain_core.prompts import PromptTemplate
|
|
| 5 |
rag_prompt = PromptTemplate(
|
| 6 |
input_variables=["context", "query"],
|
| 7 |
template=(
|
| 8 |
-
"You are a document
|
| 9 |
-
"
|
| 10 |
-
"
|
| 11 |
-
|
| 12 |
-
"
|
| 13 |
-
"
|
| 14 |
-
"-
|
| 15 |
-
"-
|
| 16 |
-
|
| 17 |
-
"Avoid repeating the question.\n\n"
|
| 18 |
-
|
| 19 |
"Context:\n{context}\n\n"
|
| 20 |
"Question:\n{query}\n\n"
|
| 21 |
"Answer:"
|
|
|
|
| 5 |
rag_prompt = PromptTemplate(
|
| 6 |
input_variables=["context", "query"],
|
| 7 |
template=(
|
| 8 |
+
"You are a precise document assistant.\n"
|
| 9 |
+
"Your ONLY source of truth is the context below.\n"
|
| 10 |
+
"STRICT RULES:\n"
|
| 11 |
+
"- Never use outside knowledge\n"
|
| 12 |
+
"- If the answer is not in the context, respond EXACTLY: "
|
| 13 |
+
"'The document does not contain information about this.'\n"
|
| 14 |
+
"- Do not guess, infer, or expand beyond what is written\n"
|
| 15 |
+
"- Be concise: short explanation + bullet points if helpful\n\n"
|
| 16 |
+
"Conversation History:\n{history}\n\n" # ✅ added history here
|
|
|
|
|
|
|
| 17 |
"Context:\n{context}\n\n"
|
| 18 |
"Question:\n{query}\n\n"
|
| 19 |
"Answer:"
|