Spaces:
Sleeping
Sleeping
final final attempt
Browse files
app.py
CHANGED
|
@@ -128,11 +128,7 @@ class SlpMultiAgent:
|
|
| 128 |
)
|
| 129 |
|
| 130 |
manager_agent = CodeAgent(
|
| 131 |
-
model=
|
| 132 |
-
model_id="gpt-3.5-turbo",
|
| 133 |
-
temperature=0.0,
|
| 134 |
-
max_tokens=500
|
| 135 |
-
),
|
| 136 |
tools=[KnowledgeBaseTool(), WikipediaSearchTool(), DuckDuckGoSearchTool()], # Pass all retrieval tools
|
| 137 |
managed_agents=[research_agent, solver_agent], # Only 2 agents
|
| 138 |
name="ManagerAgent",
|
|
@@ -140,8 +136,11 @@ class SlpMultiAgent:
|
|
| 140 |
"Efficient manager for quick problem solving. "
|
| 141 |
"Uses Wikipedia and DuckDuckGo for factual questions. "
|
| 142 |
"IMPORTANT: Only output a single code block in this format: "
|
| 143 |
-
"<code
|
| 144 |
-
"Do not
|
|
|
|
|
|
|
|
|
|
| 145 |
),
|
| 146 |
additional_authorized_imports=["re", "math"],
|
| 147 |
planning_interval=1, # Faster planning
|
|
@@ -200,17 +199,17 @@ class SlpMultiAgent:
|
|
| 200 |
final_answer_match = re.search(r'final_answer\(["\']([^"\']*)["\']\)', result)
|
| 201 |
if final_answer_match:
|
| 202 |
clean_answer = final_answer_match.group(1).strip()
|
|
|
|
|
|
|
|
|
|
| 203 |
# Post-process: remove code blocks, explanations, and keep only the direct answer
|
| 204 |
clean_answer = clean_answer.strip('`').strip()
|
| 205 |
-
# Remove common prefixes
|
| 206 |
for prefix in ["The answer is", "Based on", "According to", "Answer:"]:
|
| 207 |
if clean_answer.lower().startswith(prefix.lower()):
|
| 208 |
clean_answer = clean_answer[len(prefix):].strip(' :,.')
|
| 209 |
-
# If answer is a list, keep it comma separated and clean
|
| 210 |
if '\n' in clean_answer and ',' not in clean_answer:
|
| 211 |
items = [x.strip() for x in clean_answer.split('\n') if x.strip()]
|
| 212 |
clean_answer = ', '.join(items)
|
| 213 |
-
# If answer is a code block, extract the value
|
| 214 |
code_match = re.search(r'([A-Za-z0-9 ,.+-]+)', clean_answer)
|
| 215 |
if code_match:
|
| 216 |
clean_answer = code_match.group(1).strip()
|
|
@@ -220,7 +219,6 @@ class SlpMultiAgent:
|
|
| 220 |
for line in reversed(lines):
|
| 221 |
line = line.strip('`').strip()
|
| 222 |
if line and not line.startswith('#') and not line.startswith('###') and len(line) < 200:
|
| 223 |
-
# Remove common prefixes
|
| 224 |
for prefix in ["The answer is", "Based on", "According to", "Answer:"]:
|
| 225 |
if line.lower().startswith(prefix.lower()):
|
| 226 |
line = line[len(prefix):].strip(' :,.')
|
|
|
|
| 128 |
)
|
| 129 |
|
| 130 |
manager_agent = CodeAgent(
|
| 131 |
+
model=model,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
tools=[KnowledgeBaseTool(), WikipediaSearchTool(), DuckDuckGoSearchTool()], # Pass all retrieval tools
|
| 133 |
managed_agents=[research_agent, solver_agent], # Only 2 agents
|
| 134 |
name="ManagerAgent",
|
|
|
|
| 136 |
"Efficient manager for quick problem solving. "
|
| 137 |
"Uses Wikipedia and DuckDuckGo for factual questions. "
|
| 138 |
"IMPORTANT: Only output a single code block in this format: "
|
| 139 |
+
"<code>\\nfinal_answer(\"your direct, simple answer\")\\n</code> "
|
| 140 |
+
"Do not use variables or function calls as the answer. "
|
| 141 |
+
"Do not include any other code, comments, or explanations. "
|
| 142 |
+
"For example, output: <code>\\nfinal_answer(\"5\")\\n</code> "
|
| 143 |
+
"NOT: <code>\\nfinal_answer(total_sales_usd)\\n</code>"
|
| 144 |
),
|
| 145 |
additional_authorized_imports=["re", "math"],
|
| 146 |
planning_interval=1, # Faster planning
|
|
|
|
| 199 |
final_answer_match = re.search(r'final_answer\(["\']([^"\']*)["\']\)', result)
|
| 200 |
if final_answer_match:
|
| 201 |
clean_answer = final_answer_match.group(1).strip()
|
| 202 |
+
# If the answer looks like a variable name, return "Not available"
|
| 203 |
+
if re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', clean_answer):
|
| 204 |
+
return "Not available"
|
| 205 |
# Post-process: remove code blocks, explanations, and keep only the direct answer
|
| 206 |
clean_answer = clean_answer.strip('`').strip()
|
|
|
|
| 207 |
for prefix in ["The answer is", "Based on", "According to", "Answer:"]:
|
| 208 |
if clean_answer.lower().startswith(prefix.lower()):
|
| 209 |
clean_answer = clean_answer[len(prefix):].strip(' :,.')
|
|
|
|
| 210 |
if '\n' in clean_answer and ',' not in clean_answer:
|
| 211 |
items = [x.strip() for x in clean_answer.split('\n') if x.strip()]
|
| 212 |
clean_answer = ', '.join(items)
|
|
|
|
| 213 |
code_match = re.search(r'([A-Za-z0-9 ,.+-]+)', clean_answer)
|
| 214 |
if code_match:
|
| 215 |
clean_answer = code_match.group(1).strip()
|
|
|
|
| 219 |
for line in reversed(lines):
|
| 220 |
line = line.strip('`').strip()
|
| 221 |
if line and not line.startswith('#') and not line.startswith('###') and len(line) < 200:
|
|
|
|
| 222 |
for prefix in ["The answer is", "Based on", "According to", "Answer:"]:
|
| 223 |
if line.lower().startswith(prefix.lower()):
|
| 224 |
line = line[len(prefix):].strip(' :,.')
|