Spaces:
Runtime error
Runtime error
Update rag_pipeline.py
Browse files- rag_pipeline.py +20 -17
rag_pipeline.py
CHANGED
|
@@ -493,7 +493,7 @@ class LLMJudge:
|
|
| 493 |
temperature: float = 0.1) -> str:
|
| 494 |
try:
|
| 495 |
r = self.client.chat_completion(
|
| 496 |
-
messages=[{"role": "user", "content": prompt}],
|
| 497 |
max_tokens=max_tokens,
|
| 498 |
temperature=temperature,
|
| 499 |
)
|
|
@@ -551,7 +551,7 @@ class LLMJudge:
|
|
| 551 |
"صرف ایک لفظ میں جواب دیں: \"ہاں\" یا \"نہیں\"\n\n"
|
| 552 |
f"متن:\n{context[:1800]}\n\nدعویٰ: {claim}\n\nجواب:"
|
| 553 |
)
|
| 554 |
-
raw = self._judge_call(prompt, max_tokens=
|
| 555 |
dbg("verify_claim raw response:", repr(raw))
|
| 556 |
|
| 557 |
if not raw:
|
|
@@ -643,15 +643,14 @@ class LLMJudge:
|
|
| 643 |
|
| 644 |
def generate_questions_from_answer(self, answer: str) -> List[str]:
|
| 645 |
prompt = (
|
| 646 |
-
"
|
| 647 |
-
"
|
| 648 |
-
"
|
| 649 |
-
"
|
| 650 |
)
|
| 651 |
-
raw = self._judge_call(prompt, max_tokens=
|
| 652 |
-
dbg("generate_questions raw response:", repr(raw))
|
| 653 |
-
|
| 654 |
-
# Try JSON parse first
|
| 655 |
try:
|
| 656 |
match = re.search(r'\[.*?\]', raw, re.DOTALL)
|
| 657 |
if match:
|
|
@@ -659,15 +658,19 @@ class LLMJudge:
|
|
| 659 |
return [q.strip() for q in questions if isinstance(q, str) and len(q.strip()) > 5][:3]
|
| 660 |
except (json.JSONDecodeError, ValueError):
|
| 661 |
pass
|
| 662 |
-
|
| 663 |
-
#
|
| 664 |
-
questions = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
for line in raw.split("\n"):
|
| 666 |
-
clean = re.sub(r
|
| 667 |
-
clean = clean.strip('"').strip("'").strip()
|
| 668 |
if clean and len(clean) > 5:
|
| 669 |
-
|
| 670 |
-
return
|
| 671 |
|
| 672 |
|
| 673 |
|
|
|
|
| 493 |
temperature: float = 0.1) -> str:
|
| 494 |
try:
|
| 495 |
r = self.client.chat_completion(
|
| 496 |
+
messages=[ {"role": "system", "content": "/no_think"},{"role": "user", "content": prompt}],
|
| 497 |
max_tokens=max_tokens,
|
| 498 |
temperature=temperature,
|
| 499 |
)
|
|
|
|
| 551 |
"صرف ایک لفظ میں جواب دیں: \"ہاں\" یا \"نہیں\"\n\n"
|
| 552 |
f"متن:\n{context[:1800]}\n\nدعویٰ: {claim}\n\nجواب:"
|
| 553 |
)
|
| 554 |
+
raw = self._judge_call(prompt, max_tokens=500, temperature=0.4).lower().strip() # ← 20 → 100
|
| 555 |
dbg("verify_claim raw response:", repr(raw))
|
| 556 |
|
| 557 |
if not raw:
|
|
|
|
| 643 |
|
| 644 |
def generate_questions_from_answer(self, answer: str) -> List[str]:
|
| 645 |
prompt = (
|
| 646 |
+
"صرف JSON array میں تین سوالات لکھیں۔ کوئی وضاحت نہ کریں۔\n"
|
| 647 |
+
"فارمیٹ بالکل ایسا ہو: [\"سوال\", \"سوال\", \"سوال\"]\n\n"
|
| 648 |
+
"جواب: " + answer + "\n\n"
|
| 649 |
+
"JSON array:"
|
| 650 |
)
|
| 651 |
+
raw = self._judge_call(prompt, max_tokens=500, temperature=0.4)
|
| 652 |
+
dbg("generate_questions raw response:", repr(raw))
|
| 653 |
+
|
|
|
|
| 654 |
try:
|
| 655 |
match = re.search(r'\[.*?\]', raw, re.DOTALL)
|
| 656 |
if match:
|
|
|
|
| 658 |
return [q.strip() for q in questions if isinstance(q, str) and len(q.strip()) > 5][:3]
|
| 659 |
except (json.JSONDecodeError, ValueError):
|
| 660 |
pass
|
| 661 |
+
|
| 662 |
+
# Handle truncated JSON
|
| 663 |
+
questions = re.findall(r'"([^"]{6,})"', raw)
|
| 664 |
+
if questions:
|
| 665 |
+
return questions[:3]
|
| 666 |
+
|
| 667 |
+
# Last resort line-by-line
|
| 668 |
+
result = []
|
| 669 |
for line in raw.split("\n"):
|
| 670 |
+
clean = re.sub(r'^[\d\.\)\-\[\]"\']+\s*', "", line.strip()).strip().strip('"')
|
|
|
|
| 671 |
if clean and len(clean) > 5:
|
| 672 |
+
result.append(clean)
|
| 673 |
+
return result[:3]
|
| 674 |
|
| 675 |
|
| 676 |
|