From cbfbe7bc6115054de77edf7aef3cb8a804081be7 Mon Sep 17 00:00:00 2001 From: Kye Date: Mon, 26 Jun 2023 22:17:30 -0400 Subject: [PATCH] tools --- swarms/tools/README.md | 60 ++++++++++++++++++++++++++++++++++++++++++ swarms/tools/main.py | 0 2 files changed, 60 insertions(+) create mode 100644 swarms/tools/README.md create mode 100644 swarms/tools/main.py diff --git a/swarms/tools/README.md b/swarms/tools/README.md new file mode 100644 index 00000000..20fa3a2f --- /dev/null +++ b/swarms/tools/README.md @@ -0,0 +1,60 @@ +Here are 20 tools the individual worker swarm nodes can use: + +1. Write File Tool: Create a new file and write content to it. +2. Read File Tool: Open and read the content of an existing file. +3. Copy File Tool: Duplicate a file. +4. Delete File Tool: Remove a file. +5. Rename File Tool: Rename a file. +6. Web Search Tool: Use a web search engine (like Google or DuckDuckGo) to find information. +7. API Call Tool: Make requests to APIs. +8. Process CSV Tool: Load a CSV file and perform operations on it using pandas. +9. Create Directory Tool: Create a new directory. +10. List Directory Tool: List all the files in a directory. +11. Install Package Tool: Install Python packages using pip. +12. Code Compilation Tool: Compile and run code in different languages. +13. System Command Tool: Execute system commands. +14. Image Processing Tool: Perform operations on images (resizing, cropping, etc.). +15. PDF Processing Tool: Read, write, and manipulate PDF files. +16. Text Processing Tool: Perform text processing operations like tokenization, stemming, etc. +17. Email Sending Tool: Send emails. +18. Database Query Tool: Execute SQL queries on a database. +19. Data Scraping Tool: Scrape data from web pages. +20. Version Control Tool: Perform Git operations. + +The architecture for these tools involves creating a base `Tool` class that can be extended for each specific tool. The base `Tool` class would define common properties and methods that all tools would use. + +The pseudocode for each tool would follow a similar structure: + +``` +Class ToolNameTool extends Tool: + Define properties specific to the tool + + Method run: + Perform the specific action of the tool + Return the result +``` + +Here's an example of how you might define the WriteFileTool: + +```python +import os +from langchain.tools import BaseTool + +class WriteFileTool(BaseTool): + name = "write_file" + description = "Create a new file and write content to it." + + def __init__(self, root_dir: str): + self.root_dir = root_dir + + def _run(self, file_name: str, content: str) -> str: + """Creates a new file and writes the content.""" + try: + with open(os.path.join(self.root_dir, file_name), 'w') as f: + f.write(content) + return f"Successfully wrote to {file_name}" + except Exception as e: + return f"Error: {e}" +``` + +This tool takes the name of the file and the content to be written as parameters, writes the content to the file in the specified directory, and returns a success message. In case of any error, it returns the error message. You would follow a similar process to create the other tools. \ No newline at end of file diff --git a/swarms/tools/main.py b/swarms/tools/main.py new file mode 100644 index 00000000..e69de29b