|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from typing import Any |
|
from smolagents.tools import Tool |
|
|
|
class FinalAnswerTool(Tool): |
|
name = "final_answer" |
|
description = "Formats and presents final answers in a human-readable format." |
|
inputs = {'answer': {'type': 'any', 'description': 'The final answer, which could be job listings or a general response'}} |
|
output_type = "string" |
|
|
|
def forward(self, answer: Any) -> str: |
|
""" |
|
Determines the type of answer and formats it accordingly. |
|
""" |
|
|
|
if isinstance(answer, str): |
|
return f"📌 **Final Answer:**\n\n{answer}" |
|
|
|
|
|
elif isinstance(answer, list) and all(isinstance(job, dict) for job in answer): |
|
if not answer: |
|
return "⚠️ No job listings found." |
|
|
|
formatted_output = "**🔍 Job Listings Found**\n\n" |
|
|
|
for idx, job in enumerate(answer, start=1): |
|
title = job.get("Title", "Unknown Job Title") |
|
company = job.get("Company", "Unknown Company") |
|
location = job.get("Location", "Anywhere") |
|
|
|
formatted_output += ( |
|
f"**{idx}. {title}**\n" |
|
f" - **Company:** {company}\n" |
|
f" - **Location:** {location}\n\n" |
|
) |
|
return formatted_output.strip() |
|
|
|
|
|
else: |
|
return f"📌 **Final Answer:**\n\n```{str(answer)}```" |
|
|
|
|