Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -340,7 +340,7 @@ class RAGIndex:
|
|
| 340 |
|
| 341 |
output_ids = self.qa_model.generate(
|
| 342 |
**inputs,
|
| 343 |
-
max_new_tokens=
|
| 344 |
do_sample=False,
|
| 345 |
)
|
| 346 |
|
|
@@ -381,10 +381,12 @@ class RAGIndex:
|
|
| 381 |
|
| 382 |
for ctx, source, score in contexts:
|
| 383 |
used_sources.add(source)
|
| 384 |
-
|
|
|
|
| 385 |
|
| 386 |
combined_text = "\n\n".join(combined_context)
|
| 387 |
|
|
|
|
| 388 |
# Limit context length to keep it manageable
|
| 389 |
max_context_chars = 4000
|
| 390 |
if len(combined_text) > max_context_chars:
|
|
@@ -392,12 +394,14 @@ class RAGIndex:
|
|
| 392 |
|
| 393 |
# Prompt for the generative model
|
| 394 |
prompt = (
|
| 395 |
-
"You are an AI assistant that answers questions using only the provided context
|
| 396 |
-
"
|
|
|
|
|
|
|
| 397 |
"\"I don't know based on the provided documents.\"\n\n"
|
| 398 |
f"Context:\n{combined_text}\n\n"
|
| 399 |
f"Question: {question}\n\n"
|
| 400 |
-
"Answer:"
|
| 401 |
)
|
| 402 |
|
| 403 |
try:
|
|
@@ -539,7 +543,7 @@ with gr.Blocks(title=CONFIG["client"]["name"]) as demo:
|
|
| 539 |
txt = gr.Textbox(
|
| 540 |
show_label=False,
|
| 541 |
placeholder="Ask a question about your documents and press Enter to send...",
|
| 542 |
-
lines=
|
| 543 |
)
|
| 544 |
|
| 545 |
with gr.Row():
|
|
|
|
| 340 |
|
| 341 |
output_ids = self.qa_model.generate(
|
| 342 |
**inputs,
|
| 343 |
+
max_new_tokens=128,
|
| 344 |
do_sample=False,
|
| 345 |
)
|
| 346 |
|
|
|
|
| 381 |
|
| 382 |
for ctx, source, score in contexts:
|
| 383 |
used_sources.add(source)
|
| 384 |
+
# Only include the pure text as context
|
| 385 |
+
combined_context.append(ctx)
|
| 386 |
|
| 387 |
combined_text = "\n\n".join(combined_context)
|
| 388 |
|
| 389 |
+
|
| 390 |
# Limit context length to keep it manageable
|
| 391 |
max_context_chars = 4000
|
| 392 |
if len(combined_text) > max_context_chars:
|
|
|
|
| 394 |
|
| 395 |
# Prompt for the generative model
|
| 396 |
prompt = (
|
| 397 |
+
"You are an AI assistant that answers questions using only the provided context.\n"
|
| 398 |
+
"- Do NOT copy large passages from the context.\n"
|
| 399 |
+
"- Do NOT mention file names or sources in your answer.\n"
|
| 400 |
+
"- If the answer cannot be found in the context, reply exactly with: "
|
| 401 |
"\"I don't know based on the provided documents.\"\n\n"
|
| 402 |
f"Context:\n{combined_text}\n\n"
|
| 403 |
f"Question: {question}\n\n"
|
| 404 |
+
"Answer in 1–3 concise sentences:"
|
| 405 |
)
|
| 406 |
|
| 407 |
try:
|
|
|
|
| 543 |
txt = gr.Textbox(
|
| 544 |
show_label=False,
|
| 545 |
placeholder="Ask a question about your documents and press Enter to send...",
|
| 546 |
+
lines=1,
|
| 547 |
)
|
| 548 |
|
| 549 |
with gr.Row():
|