WaelDahech's picture
Auto commit 2025-06-29 10:40:42
bd6cd9e
from smolagents import CodeAgent,DuckDuckGoSearchTool, InferenceClientModel,load_tool,tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
from smolagents import Tool
from Gradio_UI import GradioUI
# Below is an example of a tool that does nothing. Amaze us with your creativity !
final_answer = FinalAnswerTool()
system_promot = """
You are a helpful assistant tasked with answering questions using a set of tools.
Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
FINAL ANSWER: [YOUR FINAL ANSWER].
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
"""
# Import tool from Hub
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
# === Tool Definitions ===
TOOL_REGISTRY = [
Tool(name="wikipedia_search", entry_point="mytools.wikipedia_search.call"),
Tool(name="youtube_transcript", entry_point="mytools.youtube_transcript.call"),
Tool(name="video_frame_analyzer", entry_point="mytools.video_frame_analyzer.call"),
Tool(name="string_manipulator", entry_point="mytools.string_manipulator.call"),
Tool(name="vision_chess_engine", entry_point="mytools.vision_chess_engine.call"),
Tool(name="table_parser", entry_point="mytools.table_parser.call"),
Tool(name="libretext_fetcher", entry_point="mytools.libretext_fetcher.call"),
Tool(name="audio_transcriber", entry_point="mytools.audio_transcriber.call"),
Tool(name="botanical_classifier", entry_point="mytools.botanical_classifier.call"),
Tool(name="imdb_lookup", entry_point="mytools.imdb_lookup.call"),
Tool(name="excel_reader", entry_point="mytools.excel_reader.call"),
Tool(name="competition_db", entry_point="mytools.competition_db.call"),
Tool(name="japanese_baseball_api", entry_point="mytools.japanese_baseball_api.call"),
]
model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
agent = CodeAgent(
model= InferenceClientModel(model_id=model_id),
tools=[final_answer, *TOOL_REGISTRY], ## add your tools here (don't remove final answer)
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch(share=False)