Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,7 +29,37 @@ class BasicAgent:
|
|
| 29 |
"get_files_task_id_tool": lambda task_id: get_files_task_id_tool(task_id),
|
| 30 |
"image_processing_tool": lambda file_content: image_processing_tool(file_content)
|
| 31 |
}
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def web_search_tool(search_terms: str) -> str:
|
| 34 |
"""
|
| 35 |
Retrieves information from the internet using DuckDuckGo Search and returns results in JSON format.
|
|
|
|
| 29 |
"get_files_task_id_tool": lambda task_id: get_files_task_id_tool(task_id),
|
| 30 |
"image_processing_tool": lambda file_content: image_processing_tool(file_content)
|
| 31 |
}
|
| 32 |
+
def __call__(self, question: dict) -> str:
|
| 33 |
+
print(f"Agent received question (first 50 chars): {str(question)[:50]}...")
|
| 34 |
+
task_id = question["task_id"]
|
| 35 |
+
question_text = question["question"]
|
| 36 |
+
conversation = [{"role": "system", "content": self.system_prompt},
|
| 37 |
+
{"role": "user", "content": question_text}]
|
| 38 |
+
while True:
|
| 39 |
+
prompt = "\n".join([msg["content"] for msg in conversation])
|
| 40 |
+
response = self._call_llm(prompt)
|
| 41 |
+
if response.startswith("ANSWER:"):
|
| 42 |
+
answer = response[len("ANSWER:"):].strip()
|
| 43 |
+
break
|
| 44 |
+
elif response.startswith("TOOL:"):
|
| 45 |
+
tool_call = response[len("TOOL:"):].strip()
|
| 46 |
+
try:
|
| 47 |
+
tool_name, args_str = tool_call.split("(", 1)
|
| 48 |
+
args_str = args_str.rstrip(")")
|
| 49 |
+
if tool_name == "get_files_task_id_tool":
|
| 50 |
+
observation = self.tools[tool_name](task_id)
|
| 51 |
+
else:
|
| 52 |
+
args = eval(args_str)
|
| 53 |
+
observation = self.tools[tool_name](args)
|
| 54 |
+
conversation.append({"role": "assistant", "content": response})
|
| 55 |
+
conversation.append({"role": "user", "content": f"Observation: {observation}"})
|
| 56 |
+
except Exception as e:
|
| 57 |
+
conversation.append({"role": "user", "content": f"Error executing tool: {e}"})
|
| 58 |
+
else:
|
| 59 |
+
conversation.append({"role": "user", "content": "Please provide a tool call or the final answer."})
|
| 60 |
+
print(f"Agent returning answer: {answer}")
|
| 61 |
+
return answer
|
| 62 |
+
|
| 63 |
def web_search_tool(search_terms: str) -> str:
|
| 64 |
"""
|
| 65 |
Retrieves information from the internet using DuckDuckGo Search and returns results in JSON format.
|