NLPGenius commited on
Commit
c2d4cf1
Β·
verified Β·
1 Parent(s): cb617d4

Update flask_app.py

Browse files
Files changed (1) hide show
  1. flask_app.py +3 -5
flask_app.py CHANGED
@@ -127,9 +127,9 @@ def model_inference(retriever, question, llm):
127
  # Extract context
128
  context = "\n\n".join([doc.page_content for doc in retrieved_docs]).strip()
129
 
130
- # **New: Check if the retrieved context is relevant to the question**
131
- if not is_context_relevant(context, question):
132
- return "Answer:\n The answer is not found in the context provided.\nReferences: No references found."
133
 
134
  # Define prompt template
135
  prompt = PromptTemplate(
@@ -140,8 +140,6 @@ def model_inference(retriever, question, llm):
140
  1. **Use Only the Provided Context** – Base your answer strictly on the given context. Do not infer or generate extra details.
141
  2. **Reject Invalid or Unrelated Questions** – If the question does not relate to the context, respond with: "The answer is not found in the context provided."
142
  3. **Ensure Context Relevance** – Answer only if the exact information exists in the context.
143
- 4. **No Hallucination** – Do not assume, summarize, or infer beyond what is explicitly stated.
144
- 5. **Concise and Relevant Answers** – Avoid redundancy. Provide only the most accurate response.
145
 
146
  Context:
147
  {context}
 
127
  # Extract context
128
  context = "\n\n".join([doc.page_content for doc in retrieved_docs]).strip()
129
 
130
+ # # **New: Check if the retrieved context is relevant to the question**
131
+ # if not is_context_relevant(context, question):
132
+ # return "Answer:\n The answer is not found in the context provided.\nReferences: No references found."
133
 
134
  # Define prompt template
135
  prompt = PromptTemplate(
 
140
  1. **Use Only the Provided Context** – Base your answer strictly on the given context. Do not infer or generate extra details.
141
  2. **Reject Invalid or Unrelated Questions** – If the question does not relate to the context, respond with: "The answer is not found in the context provided."
142
  3. **Ensure Context Relevance** – Answer only if the exact information exists in the context.
 
 
143
 
144
  Context:
145
  {context}