Maia Pelletier commited on
Commit ·
54f1b53
1
Parent(s): 8338e22
change model to Mistral 7B
Browse files
app.py
CHANGED
|
@@ -91,7 +91,7 @@ class RAGChatbot:
|
|
| 91 |
"""Chatbot with RAG capabilities."""
|
| 92 |
|
| 93 |
# Default and fallback models (try in order until one is supported by your Inference API providers)
|
| 94 |
-
DEFAULT_CHAT_MODEL = "
|
| 95 |
FALLBACK_CHAT_MODELS = [
|
| 96 |
"ServiceNow-AI/Apriel-1.6-15b-Thinker:together",
|
| 97 |
"microsoft/phi-2",
|
|
@@ -237,7 +237,6 @@ Do not reveal your internal reasoning. Provide only the final answer.
|
|
| 237 |
Structure your answer in the following format:
|
| 238 |
Summary — A brief, high‑level answer.
|
| 239 |
Supporting Details — Explain using information only from the provided context. When citing, use the Source label shown for that context (e.g. the document title or name in parentheses after [Context N]).
|
| 240 |
-
Context References — List each reference with the exact Source shown for that context (e.g. "CAN/CGSB-32.312-2018" or the document title). Include section name or page when that information appears in the context text. Format: document/source, section or location if available, and a short quote or paraphrase. Do not use only "Context 1" or "Context 5" as the reference; always include the document title/source.
|
| 241 |
|
| 242 |
Context:
|
| 243 |
{context}
|
|
@@ -267,19 +266,21 @@ Answer:"""
|
|
| 267 |
f"[Context {i}]",
|
| 268 |
f"({source_label})",
|
| 269 |
)
|
| 270 |
-
#
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
| 283 |
return response_text
|
| 284 |
raise ValueError("Empty response from model")
|
| 285 |
except Exception as api_error:
|
|
|
|
| 91 |
"""Chatbot with RAG capabilities."""
|
| 92 |
|
| 93 |
# Default and fallback models (try in order until one is supported by your Inference API providers)
|
| 94 |
+
DEFAULT_CHAT_MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
|
| 95 |
FALLBACK_CHAT_MODELS = [
|
| 96 |
"ServiceNow-AI/Apriel-1.6-15b-Thinker:together",
|
| 97 |
"microsoft/phi-2",
|
|
|
|
| 237 |
Structure your answer in the following format:
|
| 238 |
Summary — A brief, high‑level answer.
|
| 239 |
Supporting Details — Explain using information only from the provided context. When citing, use the Source label shown for that context (e.g. the document title or name in parentheses after [Context N]).
|
|
|
|
| 240 |
|
| 241 |
Context:
|
| 242 |
{context}
|
|
|
|
| 266 |
f"[Context {i}]",
|
| 267 |
f"({source_label})",
|
| 268 |
)
|
| 269 |
+
# Only append references when the model actually answered
|
| 270 |
+
no_answer_phrase = "The provided context does not contain enough information to answer this question."
|
| 271 |
+
if no_answer_phrase not in response_text:
|
| 272 |
+
ref_lines = [
|
| 273 |
+
"",
|
| 274 |
+
"---",
|
| 275 |
+
"**References**",
|
| 276 |
+
]
|
| 277 |
+
for i, source_label in context_index_to_source.items():
|
| 278 |
+
url = context_index_to_url.get(i)
|
| 279 |
+
if url:
|
| 280 |
+
ref_lines.append(f"{i}. [{source_label}]({url})")
|
| 281 |
+
else:
|
| 282 |
+
ref_lines.append(f"{i}. {source_label}")
|
| 283 |
+
response_text = response_text.rstrip() + "\n\n" + "\n".join(ref_lines)
|
| 284 |
return response_text
|
| 285 |
raise ValueError("Empty response from model")
|
| 286 |
except Exception as api_error:
|