Spaces:
Runtime error
Runtime error
Update flask_app.py
Browse files- 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 |
-
|
| 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}
|