Spaces:
Sleeping
Sleeping
Edited final_answer
Browse files
tools/.ipynb_checkpoints/final_answer-checkpoint.py
CHANGED
|
@@ -1,14 +1,54 @@
|
|
| 1 |
-
from typing import Any, Optional
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from smolagents.tools import Tool
|
| 3 |
|
| 4 |
class FinalAnswerTool(Tool):
|
| 5 |
name = "final_answer"
|
| 6 |
-
description = "
|
| 7 |
-
inputs = {'answer': {'type': 'any', 'description': 'The final answer
|
| 8 |
-
output_type = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
| 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
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
from typing import Any
|
| 18 |
from smolagents.tools import Tool
|
| 19 |
|
| 20 |
class FinalAnswerTool(Tool):
|
| 21 |
name = "final_answer"
|
| 22 |
+
description = "Formats and presents final answers in a human-readable format."
|
| 23 |
+
inputs = {'answer': {'type': 'any', 'description': 'The final answer, which could be job listings or a general response'}}
|
| 24 |
+
output_type = "string"
|
| 25 |
+
|
| 26 |
+
def forward(self, answer: Any) -> str:
|
| 27 |
+
"""
|
| 28 |
+
Determines the type of answer and formats it accordingly.
|
| 29 |
+
"""
|
| 30 |
+
# Case 1: If the answer is a string, return it as is
|
| 31 |
+
if isinstance(answer, str):
|
| 32 |
+
return f"📌 **Final Answer:**\n\n{answer}"
|
| 33 |
+
|
| 34 |
+
# Case 2: If the answer is a list of job listings, format them properly
|
| 35 |
+
elif isinstance(answer, list) and all(isinstance(job, dict) for job in answer):
|
| 36 |
+
formatted_output = "**🔍 Remote Data Science Jobs in Europe**\n\n"
|
| 37 |
+
|
| 38 |
+
for idx, job in enumerate(answer, start=1):
|
| 39 |
+
title = job.get("Title", "N/A")
|
| 40 |
+
company = job.get("Company", "N/A")
|
| 41 |
+
location = job.get("Location", "Anywhere")
|
| 42 |
+
link = job.get("Link", "#") # Provide a default link if missing
|
| 43 |
|
| 44 |
+
formatted_output += (
|
| 45 |
+
f"**{idx}. {title}**\n"
|
| 46 |
+
f" - **Company:** {company}\n"
|
| 47 |
+
f" - **Location:** {location}\n"
|
| 48 |
+
f" - **🔗 [Apply Here]({link})**\n\n"
|
| 49 |
+
)
|
| 50 |
+
return formatted_output
|
| 51 |
|
| 52 |
+
# Case 3: If it's an unknown format (list, dict, etc.), return it as a formatted string
|
| 53 |
+
else:
|
| 54 |
+
return f"📌 **Final Answer:**\n\n```{str(answer)}```"
|
tools/final_answer.py
CHANGED
|
@@ -1,14 +1,54 @@
|
|
| 1 |
-
from typing import Any, Optional
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from smolagents.tools import Tool
|
| 3 |
|
| 4 |
class FinalAnswerTool(Tool):
|
| 5 |
name = "final_answer"
|
| 6 |
-
description = "
|
| 7 |
-
inputs = {'answer': {'type': 'any', 'description': 'The final answer
|
| 8 |
-
output_type = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
| 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
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
from typing import Any
|
| 18 |
from smolagents.tools import Tool
|
| 19 |
|
| 20 |
class FinalAnswerTool(Tool):
|
| 21 |
name = "final_answer"
|
| 22 |
+
description = "Formats and presents final answers in a human-readable format."
|
| 23 |
+
inputs = {'answer': {'type': 'any', 'description': 'The final answer, which could be job listings or a general response'}}
|
| 24 |
+
output_type = "string"
|
| 25 |
+
|
| 26 |
+
def forward(self, answer: Any) -> str:
|
| 27 |
+
"""
|
| 28 |
+
Determines the type of answer and formats it accordingly.
|
| 29 |
+
"""
|
| 30 |
+
# Case 1: If the answer is a string, return it as is
|
| 31 |
+
if isinstance(answer, str):
|
| 32 |
+
return f"📌 **Final Answer:**\n\n{answer}"
|
| 33 |
+
|
| 34 |
+
# Case 2: If the answer is a list of job listings, format them properly
|
| 35 |
+
elif isinstance(answer, list) and all(isinstance(job, dict) for job in answer):
|
| 36 |
+
formatted_output = "**🔍 Remote Data Science Jobs in Europe**\n\n"
|
| 37 |
+
|
| 38 |
+
for idx, job in enumerate(answer, start=1):
|
| 39 |
+
title = job.get("Title", "N/A")
|
| 40 |
+
company = job.get("Company", "N/A")
|
| 41 |
+
location = job.get("Location", "Anywhere")
|
| 42 |
+
link = job.get("Link", "#") # Provide a default link if missing
|
| 43 |
|
| 44 |
+
formatted_output += (
|
| 45 |
+
f"**{idx}. {title}**\n"
|
| 46 |
+
f" - **Company:** {company}\n"
|
| 47 |
+
f" - **Location:** {location}\n"
|
| 48 |
+
f" - **🔗 [Apply Here]({link})**\n\n"
|
| 49 |
+
)
|
| 50 |
+
return formatted_output
|
| 51 |
|
| 52 |
+
# Case 3: If it's an unknown format (list, dict, etc.), return it as a formatted string
|
| 53 |
+
else:
|
| 54 |
+
return f"📌 **Final Answer:**\n\n```{str(answer)}```"
|