Spaces:
Sleeping
Sleeping
Update tools/final_answer.py
Browse files- tools/final_answer.py +5 -0
tools/final_answer.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from typing import Any, Optional
|
| 2 |
from smolagents.tools import Tool
|
| 3 |
|
|
|
|
|
|
|
| 4 |
class FinalAnswerTool(Tool):
|
| 5 |
name = "final_answer"
|
| 6 |
description = "Provides a final answer to the given problem."
|
|
@@ -8,6 +10,9 @@ class FinalAnswerTool(Tool):
|
|
| 8 |
output_type = "any"
|
| 9 |
|
| 10 |
def forward(self, answer: Any) -> Any:
|
|
|
|
|
|
|
|
|
|
| 11 |
return answer
|
| 12 |
|
| 13 |
def __init__(self, *args, **kwargs):
|
|
|
|
| 1 |
from typing import Any, Optional
|
| 2 |
from smolagents.tools import Tool
|
| 3 |
|
| 4 |
+
from smolagents.agent_types import AgentImage
|
| 5 |
+
|
| 6 |
class FinalAnswerTool(Tool):
|
| 7 |
name = "final_answer"
|
| 8 |
description = "Provides a final answer to the given problem."
|
|
|
|
| 10 |
output_type = "any"
|
| 11 |
|
| 12 |
def forward(self, answer: Any) -> Any:
|
| 13 |
+
# unwrap AgentImage to raw PIL image
|
| 14 |
+
if isinstance(answer, AgentImage):
|
| 15 |
+
return answer.image
|
| 16 |
return answer
|
| 17 |
|
| 18 |
def __init__(self, *args, **kwargs):
|