Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	example adding tool
Browse files
    	
        app.py
    CHANGED
    
    | @@ -39,6 +39,22 @@ final_answer = FinalAnswerTool() | |
| 39 | 
             
            # 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:
         | 
| 40 | 
             
            # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 
         | 
| 41 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 42 | 
             
            model = HfApiModel(
         | 
| 43 | 
             
            max_tokens=2096,
         | 
| 44 | 
             
            temperature=0.5,
         | 
| @@ -55,7 +71,7 @@ with open("prompts.yaml", 'r') as stream: | |
| 55 |  | 
| 56 | 
             
            agent = CodeAgent(
         | 
| 57 | 
             
                model=model,
         | 
| 58 | 
            -
                tools=[ | 
| 59 | 
             
                max_steps=6,
         | 
| 60 | 
             
                verbosity_level=1,
         | 
| 61 | 
             
                grammar=None,
         | 
| @@ -65,5 +81,7 @@ agent = CodeAgent( | |
| 65 | 
             
                prompt_templates=prompt_templates
         | 
| 66 | 
             
            )
         | 
| 67 |  | 
|  | |
|  | |
| 68 |  | 
| 69 | 
             
            GradioUI(agent).launch()
         | 
|  | |
| 39 | 
             
            # 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:
         | 
| 40 | 
             
            # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 
         | 
| 41 |  | 
| 42 | 
            +
            @tool
         | 
| 43 | 
            +
            def get_weather_pereira() -> str:
         | 
| 44 | 
            +
                """Fetch the current weather in Pereira, Colombia."""
         | 
| 45 | 
            +
                try:
         | 
| 46 | 
            +
                    # Pereira coordinates (approx)
         | 
| 47 | 
            +
                    lat, lon = 4.8143, -75.6946
         | 
| 48 | 
            +
                    url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t_weather=true"
         | 
| 49 | 
            +
                    response = requests.get(url)
         | 
| 50 | 
            +
                    data = response.json()
         | 
| 51 | 
            +
                    temp = data["current_weather"]["temperature"]
         | 
| 52 | 
            +
                    wind = data["current_weather"]["windspeed"]
         | 
| 53 | 
            +
                    return f"The current temperature in Pereira is {temp}°C with wind speed {wind} km/h."
         | 
| 54 | 
            +
                except Exception as e:
         | 
| 55 | 
            +
                    return f"Failed to fetch weather: {e}"
         | 
| 56 | 
            +
             | 
| 57 | 
            +
             | 
| 58 | 
             
            model = HfApiModel(
         | 
| 59 | 
             
            max_tokens=2096,
         | 
| 60 | 
             
            temperature=0.5,
         | 
|  | |
| 71 |  | 
| 72 | 
             
            agent = CodeAgent(
         | 
| 73 | 
             
                model=model,
         | 
| 74 | 
            +
                tools=[get_weather_pereira], ## add your tools here (don't remove final answer)
         | 
| 75 | 
             
                max_steps=6,
         | 
| 76 | 
             
                verbosity_level=1,
         | 
| 77 | 
             
                grammar=None,
         | 
|  | |
| 81 | 
             
                prompt_templates=prompt_templates
         | 
| 82 | 
             
            )
         | 
| 83 |  | 
| 84 | 
            +
            print(agent.run("Write the weather in Pereira right now."))
         | 
| 85 | 
            +
             | 
| 86 |  | 
| 87 | 
             
            GradioUI(agent).launch()
         | 
