VictorHueni's picture
rollback to hfapimodel
a527724 verified
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel, Tool, tool, VisitWebpageTool, GradioUI
# --- Your Custom Tools ---
@tool
def get_planet_weather(planet_name: str) -> str:
"""Returns the current environmental conditions of a given planet.
Args:
planet_name: The name of the planet."""
conditions = {"mars": "Chilly -60°C.", "tatooine": "Double suns reaching 45°C."}
return conditions.get(planet_name.lower(), "Unknown atmospheric conditions.")
@tool
def interstellar_transport_finder(destination: str) -> str:
"""Finds the best spaceship company for a destination.
Args:
destination: The planet or system you are traveling to."""
return f"The best way to reach {destination} is via Corellian Engineering (4.9 stars)."
class GalacticActivityGenerator(Tool):
name = "galactic_activity_generator"
description = "Suggests unique activities based on a vibe."
inputs = {"vibe": {"type": "string", "description": "The vibe (e.g., 'extreme adventure')"}}
output_type = "string"
def forward(self, vibe: str):
activities = {"extreme adventure": "Kessel Run Racing."}
return activities.get(vibe.lower(), "No specific activity found.")
# --- Agent Initialization ---
agent = CodeAgent(
tools=[
DuckDuckGoSearchTool(),
VisitWebpageTool(),
get_planet_weather,
interstellar_transport_finder,
GalacticActivityGenerator(),
FinalAnswerTool()
],
model=HfApiModel(),
max_steps=10
)
# --- Launch Gradio UI ---
# This class is specifically built to handle smolagents streaming and thought display
GradioUI(agent).launch()