|
| 1 | +# Create Custom Tools |
| 2 | + |
| 3 | +Sure! Let's go through the steps to install and set up the PraisonAI tool. |
| 4 | + |
| 5 | +## Step 1: Install the `praisonai` Package |
| 6 | + |
| 7 | +First, you need to install the `praisonai` package. Open your terminal and run the following command: |
| 8 | + |
| 9 | +```bash |
| 10 | +pip install praisonai |
| 11 | +``` |
| 12 | + |
| 13 | +## Step 2: Create the `InternetSearchTool` |
| 14 | + |
| 15 | +Next, create a file named `tools.py` and add the following code to define the `InternetSearchTool`: |
| 16 | + |
| 17 | +```python |
| 18 | +from duckduckgo_search import DDGS |
| 19 | +from praisonai_tools import BaseTool |
| 20 | + |
| 21 | +class InternetSearchTool(BaseTool): |
| 22 | + name: str = "Internet Search Tool" |
| 23 | + description: str = "Search Internet for relevant information based on a query or latest news" |
| 24 | + |
| 25 | + def _run(self, query: str): |
| 26 | + ddgs = DDGS() |
| 27 | + results = ddgs.text(keywords=query, region='wt-wt', safesearch='moderate', max_results=5) |
| 28 | + return results |
| 29 | +``` |
| 30 | + |
| 31 | +## Step 3: Define the Agent Configuration |
| 32 | + |
| 33 | +Create a file named `agents.yaml` and add the following content to configure the agent: |
| 34 | + |
| 35 | +```yaml |
| 36 | +framework: crewai |
| 37 | +topic: research about the causes of lung disease |
| 38 | +roles: |
| 39 | + research_analyst: |
| 40 | + backstory: Experienced in analyzing scientific data related to respiratory health. |
| 41 | + goal: Analyze data on lung diseases |
| 42 | + role: Research Analyst |
| 43 | + tasks: |
| 44 | + data_analysis: |
| 45 | + description: Gather and analyze data on the causes and risk factors of lung diseases. |
| 46 | + expected_output: Report detailing key findings on lung disease causes. |
| 47 | + tools: |
| 48 | + - InternetSearchTool |
| 49 | +``` |
| 50 | +
|
| 51 | +## Step 4: Run the PraisonAI Tool |
| 52 | +
|
| 53 | +To run the PraisonAI tool, simply type the following command in your terminal: |
| 54 | +
|
| 55 | +```bash |
| 56 | +praisonai |
| 57 | +``` |
| 58 | + |
| 59 | +If you want to run the `autogen` framework, use: |
| 60 | + |
| 61 | +```bash |
| 62 | +praisonai --framework autogen |
| 63 | +``` |
| 64 | + |
| 65 | +## Prerequisites |
| 66 | + |
| 67 | +Ensure you have the `duckduckgo_search` package installed. If not, you can install it using: |
| 68 | + |
| 69 | +```bash |
| 70 | +pip install duckduckgo_search |
| 71 | +``` |
| 72 | + |
| 73 | +That's it! You should now have the PraisonAI tool installed and configured. |
| 74 | + |
| 75 | +## Other information |
| 76 | + |
| 77 | +### TL;DR to Create a Custom Tool |
| 78 | + |
| 79 | +```bash |
| 80 | +pip install praisonai duckduckgo-search |
| 81 | +export OPENAI_API_KEY="Enter your API key" |
| 82 | +praisonai --init research about the latest AI News and prepare a detailed report |
| 83 | +``` |
| 84 | + |
| 85 | +- Add `- InternetSearchTool` in the agents.yaml file in the tools section. |
| 86 | +- Create a file called tools.py and add this code [tools.py](./tools.py) |
| 87 | + |
| 88 | +```bash |
| 89 | +praisonai |
| 90 | +``` |
| 91 | + |
| 92 | +### Pre-requisite to Create a Custom Tool |
| 93 | +`agents.yaml` file should be present in the current directory. |
| 94 | + |
| 95 | +If it doesn't exist, create it by running the command `praisonai --init research about the latest AI News and prepare a detailed report`. |
| 96 | + |
| 97 | +#### Step 1 to Create a Custom Tool |
| 98 | + |
| 99 | +Create a file called tools.py in the same directory as the agents.yaml file. |
| 100 | + |
| 101 | +```python |
| 102 | +# example tools.py |
| 103 | +from duckduckgo_search import DDGS |
| 104 | +from praisonai_tools import BaseTool |
| 105 | + |
| 106 | +class InternetSearchTool(BaseTool): |
| 107 | + name: str = "InternetSearchTool" |
| 108 | + description: str = "Search Internet for relevant information based on a query or latest news" |
| 109 | + |
| 110 | + def _run(self, query: str): |
| 111 | + ddgs = DDGS() |
| 112 | + results = ddgs.text(keywords=query, region='wt-wt', safesearch='moderate', max_results=5) |
| 113 | + return results |
| 114 | +``` |
| 115 | + |
| 116 | +#### Step 2 to Create a Custom Tool |
| 117 | + |
| 118 | +Add the tool to the agents.yaml file as show below under the tools section `- InternetSearchTool`. |
| 119 | + |
| 120 | +```yaml |
| 121 | +framework: crewai |
| 122 | +topic: research about the latest AI News and prepare a detailed report |
| 123 | +roles: |
| 124 | + research_analyst: |
| 125 | + backstory: Experienced in gathering and analyzing data related to AI news trends. |
| 126 | + goal: Analyze AI News trends |
| 127 | + role: Research Analyst |
| 128 | + tasks: |
| 129 | + gather_data: |
| 130 | + description: Conduct in-depth research on the latest AI News trends from reputable |
| 131 | + sources. |
| 132 | + expected_output: Comprehensive report on current AI News trends. |
| 133 | + tools: |
| 134 | + - InternetSearchTool |
| 135 | +``` |
0 commit comments