CoolFace
Apppublic

b3dev/First_Agent_Get_Recipe

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py64 linesDownload Raw Back to root
1from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool2import datetime3import requests4import pytz5import yaml6 7from tools.final_answer import FinalAnswerTool8 9from Gradio_UI import GradioUI10 11# Below is an example of a tool that does nothing. Amaze us with your creativity !12@tool13def get_recipe (food:str)-> str: #it's import to specify the return type14    #Keep this format for the description / args / args description but feel free to modify the tool15    """A tool gets recipes from a search16    Args:17        food: The type of food the user would like a recipe for.18 19    Returns: 20        str: A recipe response21    """22 23    try:24        recipe = DuckDuckGoSearchTool(food)25        26        print (f"What type of recipe would you like?")27        return f"Here is a possible recipe for {food}. {recipe}"28    except Exception as e:29        return f"Error searching for recipe"30 31 32final_answer = FinalAnswerTool()33 34# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:35# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' first model:Qwen/Qwen2.5-Coder-32B-Instruct36 37model = HfApiModel(38max_tokens=2096,39temperature=0.5,40model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded41custom_role_conversions=None,42)43 44 45# Import tool from Hub46image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)47 48with open("prompts.yaml", 'r') as stream:49    prompt_templates = yaml.safe_load(stream)50    51agent = CodeAgent(52    model=model,53    tools=[final_answer, get_recipe], ## add your tools here (don't remove final answer)54    max_steps=6,55    verbosity_level=1,56    grammar=None,57    planning_interval=None,58    name=None,59    description=None,60    prompt_templates=prompt_templates61)62 63 64GradioUI(agent).launch()