Commit ·
da071bf
1
Parent(s): 356d8dd
Prompt
Browse files
app.py
CHANGED
|
@@ -31,25 +31,29 @@ class BasicAgent:
|
|
| 31 |
python_tool = PythonInterpreterTool()
|
| 32 |
visit_tool = VisitWebpageTool()
|
| 33 |
|
|
|
|
| 34 |
|
| 35 |
self.agent = CodeAgent(
|
| 36 |
model=self.model,
|
| 37 |
tools=[search_tool, wiki_tool, python_tool, visit_tool],
|
| 38 |
)
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
print("BasicAgent initialized.")
|
| 41 |
|
| 42 |
def __call__(self, question: str) -> str:
|
| 43 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
answer = " ".join(str(a) for a in answer)
|
| 53 |
return answer
|
| 54 |
|
| 55 |
|
|
|
|
| 31 |
python_tool = PythonInterpreterTool()
|
| 32 |
visit_tool = VisitWebpageTool()
|
| 33 |
|
| 34 |
+
|
| 35 |
|
| 36 |
self.agent = CodeAgent(
|
| 37 |
model=self.model,
|
| 38 |
tools=[search_tool, wiki_tool, python_tool, visit_tool],
|
| 39 |
)
|
| 40 |
+
|
| 41 |
+
self.agent.PromptTemplates["final_answer"]["post_messages"] = (
|
| 42 |
+
code_agent.prompt_templates["final_answer"]["post_messages"] + prompts["system"]
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
print("BasicAgent initialized.")
|
| 46 |
|
| 47 |
def __call__(self, question: str) -> str:
|
| 48 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 49 |
+
|
| 50 |
+
answer = self.agent.run(question)
|
| 51 |
+
|
| 52 |
+
if isinstance(answer, str) and "Final Answer" in answer:
|
| 53 |
+
# Extract everything after "Final Answer"
|
| 54 |
+
idx = answer.find("Final Answer")
|
| 55 |
+
# Remove "Final Answer" and any colon or dash after it, then strip whitespace
|
| 56 |
+
answer = answer[idx + len("Final Answer"):].lstrip(": -").strip()
|
|
|
|
| 57 |
return answer
|
| 58 |
|
| 59 |
|