Category: praisonai

  • 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

  • Exa Search Tool

    from exa_py import Exa
    from praisonai_tools import BaseTool
    
    class ExaSearchTool:
        name: str = "ExaSearchTool"
        description: str = "Perform a search using Exa and retrieve contents with specified options"
    
        def __init__(self, api_key: str):
            self.exa = Exa(api_key="Enter your key here")
    
        def _run(self, query: str):
            results = self.exa.search_and_contents(
                query,
                text={"include_html_tags": True, "max_characters": 1000},
            )
            return results
    # Example usage
    if __name__ == "__main__":
        api_key = "ExaSearchTool"
        tool = ExaSearchTool(api_key=api_key)
        search_query = "recent midjourney news"
        results = tool._run(search_query)
        print(results)