Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CalculatorTool #98

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crewai_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
XMLSearchTool,
YoutubeChannelSearchTool,
YoutubeVideoSearchTool,
MySQLSearchTool
MySQLSearchTool,
CalculatorTool,
)
from .tools.base_tool import BaseTool, Tool, tool
1 change: 1 addition & 0 deletions crewai_tools/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@
)
from .youtube_video_search_tool.youtube_video_search_tool import YoutubeVideoSearchTool
from .mysql_search_tool.mysql_search_tool import MySQLSearchTool
from .calculator_tool.calculator_tool import CalculatorTool
30 changes: 30 additions & 0 deletions crewai_tools/tools/calculator_tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# WebsiteSearchTool

## Description
This tool is designed to perform calculations within the context of a given problem. It navigates through the information provided to execute operations representative of the given problem.

## Installation
Install the crewai_tools package by executing the following command in your terminal:

```shell
pip install 'crewai[tools]'
```

## Example
To utilize the CalculatorTool for different use cases, follow these examples:

```python
from crewai_tools import CalculatorTool

# To enable the tool to calculate any problem/operation the agent comes across or learns about during its operation
tool = CalculatorTool()

# OR

# To restrict the tool to only calculate a specific mathematical operation.
tool = CalculatorTool(operation='500*17')
```

## Arguments
- `operation` : A required argument that specifies the mathematical operation to evaluate as a string. If the tool is initialized without this argument, it calculates any problem or operation it encounters.

11 changes: 11 additions & 0 deletions crewai_tools/tools/calculator_tool/calculator_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from crewai_tools import BaseTool


class CalculatorTool(BaseTool):
name: str = "Calculator tool"
description: str = (
"Useful to perform any mathematical calculations, like sum, minus, multiplication, division, etc. The input to this tool should be a mathematical expression, a couple examples are `200*7` or `5000/2*10."
)

def _run(self, operation: str) -> int:
return eval(operation)