Dips-1991 commited on
Commit
3fdee37
·
verified ·
1 Parent(s): 7c15eca

Update tools/final_answer.py

Browse files
Files changed (1) hide show
  1. 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 the final formatted response to the user."
11
- inputs = {
12
- 'answer': {'type': 'any', 'description': 'The final answer to the problem'},
13
- 'image': {'type': 'any', 'description': 'Optional image result to be displayed'}
14
- }
15
- output_type = "string"
16
 
17
- def forward(self, answer: Any = "", image: Any = None) -> str:
18
- # Handle AgentImage rendering
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
- super().__init__(*args, **kwargs)
 
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