Hanokh commited on
Commit
05180a6
·
verified ·
1 Parent(s): dd8708a

Update app.py

Browse files

okay - more basic stuff

Files changed (1) hide show
  1. app.py +25 -74
app.py CHANGED
@@ -15,80 +15,31 @@ class BasicAgent:
15
  print("BasicAgent initialized.")
16
 
17
  def __call__(self, question: str) -> str:
18
- print(f"Agent received question (first 50 chars): {question[:50]}...")
19
-
20
- # --- Addition ---
21
- if match := re.match(r".*what is (\d+) \+ (\d+).*", question, re.IGNORECASE):
22
- return str(int(match.group(1)) + int(match.group(2)))
23
-
24
- # --- Multiplication ---
25
- if match := re.match(r".*what is (\d+) \* (\d+).*", question, re.IGNORECASE):
26
- return str(int(match.group(1)) * int(match.group(2)))
27
-
28
- # --- Subtraction ---
29
- if match := re.match(r".*what is (\d+) - (\d+).*", question, re.IGNORECASE):
30
- return str(int(match.group(1)) - int(match.group(2)))
31
-
32
- # --- Division ---
33
- if match := re.match(r".*what is (\d+) / (\d+).*", question, re.IGNORECASE):
34
- a, b = int(match.group(1)), int(match.group(2))
35
- return str(a / b if b != 0 else "undefined")
36
-
37
- # --- Factorial ---
38
- if match := re.match(r".*factorial of (\d+).*", question, re.IGNORECASE):
39
- return str(math.factorial(int(match.group(1))))
40
-
41
- # --- Fibonacci ---
42
- if match := re.match(r".*fibonacci of (\d+).*", question, re.IGNORECASE):
43
- n = int(match.group(1))
44
- def fib(n):
45
- a, b = 0, 1
46
- for _ in range(n):
47
- a, b = b, a + b
48
- return a
49
- return str(fib(n))
50
-
51
- # --- Prime check ---
52
- if match := re.match(r".*is (\d+) prime.*", question, re.IGNORECASE):
53
- n = int(match.group(1))
54
- if n < 2:
55
- return "no"
56
- for i in range(2, int(math.sqrt(n)) + 1):
57
- if n % i == 0:
58
- return "no"
59
- return "yes"
60
-
61
- # --- Reverse string ---
62
- if match := re.match(r".*reverse (?:the string )?'(.*)'.*", question, re.IGNORECASE):
63
- return match.group(1)[::-1]
64
-
65
- # --- Uppercase ---
66
- if match := re.match(r".*uppercase of '(.*)'.*", question, re.IGNORECASE):
67
- return match.group(1).upper()
68
-
69
- # --- Lowercase ---
70
- if match := re.match(r".*lowercase of '(.*)'.*", question, re.IGNORECASE):
71
- return match.group(1).lower()
72
-
73
- # --- Count words ---
74
- if match := re.match(r".*count words in '(.*)'.*", question, re.IGNORECASE):
75
- return str(len(match.group(1).split()))
76
-
77
- # --- Count letters ---
78
- if match := re.match(r".*count letters in '(.*)'.*", question, re.IGNORECASE):
79
- return str(len(match.group(1)))
80
-
81
- # --- Sort numbers ---
82
- if match := re.match(r".*sort numbers (.*)", question, re.IGNORECASE):
83
- numbers = re.findall(r"-?\d+", match.group(1))
84
- sorted_nums = sorted(map(int, numbers))
85
- return " ".join(map(str, sorted_nums))
86
-
87
- # --- Default fallback ---
88
- fixed_answer = "I don't know yet."
89
- print(f"Agent returning fallback answer: {fixed_answer}")
90
- return fixed_answer
91
-
92
  def run_and_submit_all( profile: gr.OAuthProfile | None):
93
  """
94
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
15
  print("BasicAgent initialized.")
16
 
17
  def __call__(self, question: str) -> str:
18
+ # Agent's reasoning process (thoughts)
19
+ thoughts = self.reason(question)
20
+ final_answer = self.extract_answer(thoughts)
21
+ response = (
22
+ f"THOUGHTS: {thoughts}\n"
23
+ f"FINAL ANSWER: {final_answer}"
24
+ )
25
+ print(f"Agent response:\n{response[:150]}...")
26
+ return response
27
+
28
+ def reason(self, question: str) -> str:
29
+ # Put chain-of-thought reasoning here,
30
+ # e.g., use LLM or heuristics to break down the problem.
31
+ # Example placeholder for demonstration:
32
+ return "Analyzing the problem step by step, considering all constraints, and isolating the answer format. Selected the most direct solution."
33
+
34
+ def extract_answer(self, thoughts: str) -> str:
35
+ # Normally, use selected answer from reasoning.
36
+ # For now, this placeholder returns demo result.
37
+ # Replace demo logic with answer extraction, format as per rules:
38
+ # - if a number is needed, just plain digits (no commas or units unless specified)
39
+ # - if string, no articles or abbreviations, digits written out unless specified
40
+ # - if list, elements comma separated, each following corresponding rules
41
+ return "42"
42
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  def run_and_submit_all( profile: gr.OAuthProfile | None):
44
  """
45
  Fetches all questions, runs the BasicAgent on them, submits all answers,