Category: llama_index

  • Open Weather Tool

    pip install llama-index-tools-weather
    pip install pyowm
    from llama_index.tools.weather import OpenWeatherMapToolSpec  # Adjusted for possible correct path
    from llama_index.agent.openai import OpenAIAgent
    
    # Create the tool specification with your API key
    tool_spec = OpenWeatherMapToolSpec(key="Enter your key here")
    
    # Initialize the OpenAIAgent with the tool specification
    agent = OpenAIAgent.from_tools(tool_spec.to_tool_list())
    
    # Query the agent about the weather
    response = agent.chat("What is the temperature like in London?")
    print(response)

    Adding weather to praisonai using llama_index

    pip install praisonai

    tools.py file

    from llama_index.tools.weather import OpenWeatherMapToolSpec
    from praisonai_tools import BaseTool
    from llama_index.agent.openai import OpenAIAgent
    import os
    
    class WeatherTool(BaseTool):
        name: str = "Weather Tool"
        description: str = "Get the current weather information for a specified location"
    
        def _run(self, location: str):
            # Use your API key from the environment variable
    
            api_key = os.getenv("OPENWEATHERMAP_API_KEY")
            tool_spec = OpenWeatherMapToolSpec(key=api_key)
            agent = OpenAIAgent.from_tools(tool_spec.to_tool_list())
            response = agent.chat(f"What is the temperature like in {location}?")
            return response
    praisonai --init What is the weather in Paris tomorrow

    the above command creates the agents.yaml file
    Open the agents.yaml file and add the tool eg: tool – WeatherTool