Spaces:
Sleeping
Sleeping
Update tools/final_answer.py
Browse files- tools/final_answer.py +7 -26
tools/final_answer.py
CHANGED
|
@@ -1,33 +1,14 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
from typing import Any
|
| 6 |
from smolagents.tools import Tool
|
| 7 |
|
| 8 |
class FinalAnswerTool(Tool):
|
| 9 |
name = "final_answer"
|
| 10 |
-
description = "Provides
|
| 11 |
-
inputs = {
|
| 12 |
-
|
| 13 |
-
'image': {'type': 'any', 'description': 'Optional image result to be displayed'}
|
| 14 |
-
}
|
| 15 |
-
output_type = "string"
|
| 16 |
|
| 17 |
-
def forward(self, answer: Any
|
| 18 |
-
|
| 19 |
-
if isinstance(image):
|
| 20 |
-
try:
|
| 21 |
-
image_html = image.display() # or image.to_html()
|
| 22 |
-
except:
|
| 23 |
-
image_html = "[Image could not be displayed]"
|
| 24 |
-
# Combine text + image if both are provided
|
| 25 |
-
if answer:
|
| 26 |
-
return f"{answer}\n\n{image_html}"
|
| 27 |
-
else:
|
| 28 |
-
return image_html
|
| 29 |
-
else:
|
| 30 |
-
return str(answer)
|
| 31 |
|
| 32 |
def __init__(self, *args, **kwargs):
|
| 33 |
-
|
|
|
|
| 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."
|
| 7 |
+
inputs = {'answer': {'type': 'any', 'description': 'The final answer to the problem'}}
|
| 8 |
+
output_type = "any"
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def forward(self, answer: Any) -> Any:
|
| 11 |
+
return answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def __init__(self, *args, **kwargs):
|
| 14 |
+
self.is_initialized = False
|