Spaces:
Runtime error
Runtime error
try to solve the riddles
Browse files
app.py
CHANGED
@@ -27,13 +27,38 @@ class BasicAgent:
|
|
27 |
to be put in the list is a number or a string.
|
28 |
"""
|
29 |
self.agent.prompt_templates["system_prompt"] = self.agent.prompt_templates["system_prompt"] + SYSTEM_PROMPT
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def __call__(self, question: str) -> str:
|
32 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
|
|
|
|
|
|
|
33 |
final_answer = self.agent.run(question)
|
34 |
print(f"Agent returning final answer: {final_answer}")
|
35 |
return final_answer
|
36 |
|
|
|
37 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
38 |
"""
|
39 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
27 |
to be put in the list is a number or a string.
|
28 |
"""
|
29 |
self.agent.prompt_templates["system_prompt"] = self.agent.prompt_templates["system_prompt"] + SYSTEM_PROMPT
|
30 |
+
|
31 |
+
def maybe_reversed(self, text: str) -> bool:
|
32 |
+
"""Heuristically checks if a sentence is reversed letter-by-letter."""
|
33 |
+
words = text.split()
|
34 |
+
reversed_ratio = sum(1 for word in words if word[::-1].lower() in {"if", "you", "understand", "this", "sentence", "write", "opposite", "of", "the", "word", "left", "answer"}) / len(words)
|
35 |
+
return reversed_ratio > 0.3 # adjustable threshold
|
36 |
+
|
37 |
+
def solve_riddle(self, question: str) -> str:
|
38 |
+
"""Handles reversed sentence logic riddles."""
|
39 |
+
reversed_text = question[::-1]
|
40 |
+
if "opposite of the word" in reversed_text:
|
41 |
+
import re
|
42 |
+
match = re.search(r"opposite of the word ['\"](\w+)['\"]", reversed_text)
|
43 |
+
if match:
|
44 |
+
word = match.group(1).lower()
|
45 |
+
opposites = {"left": "right", "up": "down", "hot": "cold", "true": "false", "yes": "no", "black": "white"}
|
46 |
+
opposite = opposites.get(word, f"UNKNOWN_OPPOSITE_OF_{word}")
|
47 |
+
return f"FINAL ANSWER: {opposite}"
|
48 |
+
return f"FINAL ANSWER: COULD_NOT_SOLVE"
|
49 |
+
|
50 |
def __call__(self, question: str) -> str:
|
51 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
52 |
+
|
53 |
+
if self.maybe_reversed(question):
|
54 |
+
print("Detected likely reversed text. Attempting riddle solving...")
|
55 |
+
return self.solve_riddle(question)
|
56 |
+
|
57 |
final_answer = self.agent.run(question)
|
58 |
print(f"Agent returning final answer: {final_answer}")
|
59 |
return final_answer
|
60 |
|
61 |
+
|
62 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
63 |
"""
|
64 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|