ianeksdi commited on
Commit
8c283a7
·
verified ·
1 Parent(s): 96eb0f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -12
app.py CHANGED
@@ -14,7 +14,7 @@ system_prompt = (
14
 
15
  def remove_code_snippets(text):
16
  """
17
- Removes code blocks, inline code, chain-of-thought, and debugging/step logs from the output.
18
  """
19
  # Remove triple-backtick code blocks.
20
  text = re.sub(r"```[\s\S]+?```", "", text, flags=re.DOTALL)
@@ -22,16 +22,34 @@ def remove_code_snippets(text):
22
  text = re.sub(r"`[^`]+`", "", text)
23
  # Remove any text between <think> and </think> tags.
24
  text = re.sub(r"<think>[\s\S]*?</think>", "", text, flags=re.DOTALL)
25
- # Remove debug/step log banners (e.g., "━━━━━ Step X ━━━━━")
26
- text = re.sub(r"━+.*Step \d+.*━+", "", text)
27
- # Remove any lines that start with "[Step" (which include duration and token info).
28
- text = re.sub(r"\[Step \d+: Duration .*", "", text)
29
- # Remove lines that mention code snippet instructions.
30
- text = re.sub(r"Make sure to include code with the correct pattern.*", "", text)
31
- # Finally, remove any remaining lines that seem to be debug logs.
32
  lines = text.splitlines()
33
- cleaned_lines = [line for line in lines if not re.search(r"Step \d+|Duration", line)]
34
- return "\n".join(cleaned_lines).strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  # Use only the final_answer tool.
37
  final_answer = FinalAnswerTool()
@@ -67,8 +85,8 @@ agent = CodeAgent(
67
 
68
  def run_agent(user_input):
69
  """
70
- Runs the agent, then removes any internal chain-of-thought, step logs, and code snippets
71
- before returning the final plain-text answer.
72
  """
73
  raw_response = agent.run(user_input)
74
  print("Raw Agent Response:", raw_response) # Debugging output (optional)
 
14
 
15
  def remove_code_snippets(text):
16
  """
17
+ Removes code blocks, inline code, chain-of-thought, error messages, and debugging/step logs from the output.
18
  """
19
  # Remove triple-backtick code blocks.
20
  text = re.sub(r"```[\s\S]+?```", "", text, flags=re.DOTALL)
 
22
  text = re.sub(r"`[^`]+`", "", text)
23
  # Remove any text between <think> and </think> tags.
24
  text = re.sub(r"<think>[\s\S]*?</think>", "", text, flags=re.DOTALL)
25
+ # Remove block from "Make sure to include code with the correct pattern" until "<end_code>"
26
+ text = re.sub(r"Make sure to include code with the correct pattern[\s\S]*?<end_code>", "", text, flags=re.DOTALL)
27
+
28
+ # Split the text into lines and filter out debug/error/step log lines.
 
 
 
29
  lines = text.splitlines()
30
+ filtered_lines = []
31
+ for line in lines:
32
+ # Skip lines that are clearly debug or error messages.
33
+ if re.search(r"Step \d+", line):
34
+ continue
35
+ if "Duration:" in line:
36
+ continue
37
+ if "Error in code parsing:" in line:
38
+ continue
39
+ if "💥 Error" in line:
40
+ continue
41
+ if "Reached max steps" in line:
42
+ continue
43
+ if "Make sure to provide correct code blobs" in line:
44
+ continue
45
+ if "Here is your code snippet:" in line:
46
+ continue
47
+ if "Code:" in line:
48
+ continue
49
+ filtered_lines.append(line)
50
+
51
+ cleaned_text = "\n".join(filtered_lines)
52
+ return cleaned_text.strip()
53
 
54
  # Use only the final_answer tool.
55
  final_answer = FinalAnswerTool()
 
85
 
86
  def run_agent(user_input):
87
  """
88
+ Runs the agent and then removes any internal chain-of-thought, error messages,
89
+ debug logs, and code snippet sections before returning the final plain-text answer.
90
  """
91
  raw_response = agent.run(user_input)
92
  print("Raw Agent Response:", raw_response) # Debugging output (optional)