pluto90 commited on
Commit
f383d3f
·
verified ·
1 Parent(s): 763faab

Upload 4 files

Browse files
app/core/prompts/evaluator_prompt.py CHANGED
@@ -1,37 +1,70 @@
1
- # evaluator_prompt.py# # evaluator_prompt.py
2
-
3
-
4
- from langchain_core.prompts import PromptTemplate
5
-
6
- evaluator_prompt = PromptTemplate(
7
- input_variables=["query", "answer", "context"],
8
- template="""
9
- You are an evaluation system.
10
-
11
- Evaluate the AI response strictly based on the given context.
12
-
13
- Rules:
14
- - Be strict
15
- - Output ONLY valid JSON
16
- - No explanation
17
- - No markdown
18
- - No text before or after JSON
19
-
20
- Query:
21
- {query}
22
-
23
- Answer:
24
- {answer}
25
-
26
- Context:
27
- {context}
28
-
29
- Return ONLY this JSON:
30
-
31
- {{
32
- "relevance_score": 0.0,
33
- "context_usage": 0.0,
34
- "hallucination": false
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 intelligence system.\n"
9
- "Answer ONLY using the provided context.\n"
10
- "If answer is not present, say: 'Not in document'.\n\n"
11
-
12
- "Keep response concise:\n"
13
- "- Short explanation\n"
14
- "- Bullet points if useful\n"
15
- "- Max 120 words\n\n"
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:"