From 80f9613959f17bf867866fb6b4ecdce218fce633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Wed, 27 Mar 2024 15:04:35 -0300 Subject: [PATCH 01/13] Adding two default arguments to cache function --- src/crewai_tools/tools/base_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crewai_tools/tools/base_tool.py b/src/crewai_tools/tools/base_tool.py index 961688629..e8e497859 100644 --- a/src/crewai_tools/tools/base_tool.py +++ b/src/crewai_tools/tools/base_tool.py @@ -20,7 +20,7 @@ class BaseTool(BaseModel, ABC): """The schema for the arguments that the tool accepts.""" description_updated: bool = False """Flag to check if the description has been updated.""" - cache_function: Optional[Callable] = lambda: True + cache_function: Optional[Callable] = lambda _args, _result: True """Function that will be used to determine if the tool should be cached, should return a boolean. If None, the tool will be cached.""" @validator("args_schema", always=True, pre=True) From 92abe0b726845f4b7aacdd0b844f0dacb745265e Mon Sep 17 00:00:00 2001 From: Victor C Tavernari Date: Sun, 31 Mar 2024 23:32:40 +0100 Subject: [PATCH 02/13] Enhance file reading with error handling - Wrapped the file reading functionality inside a `_run` method. - Added error handling to return a descriptive error message if an exception occurs during file reading. --- .../tools/file_read_tool/file_read_tool.py | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/src/crewai_tools/tools/file_read_tool/file_read_tool.py b/src/crewai_tools/tools/file_read_tool/file_read_tool.py index 8c7643852..38aeeeb2e 100644 --- a/src/crewai_tools/tools/file_read_tool/file_read_tool.py +++ b/src/crewai_tools/tools/file_read_tool/file_read_tool.py @@ -2,32 +2,45 @@ from typing import Optional, Type, Any from pydantic.v1 import BaseModel, Field from ..base_tool import BaseTool + class FixedFileReadToolSchema(BaseModel): - """Input for FileReadTool.""" - pass + """Input for FileReadTool.""" + pass + class FileReadToolSchema(FixedFileReadToolSchema): - """Input for FileReadTool.""" - file_path: str = Field(..., description="Mandatory file full path to read the file") + """Input for FileReadTool.""" + file_path: str = Field( + ..., + description="Mandatory file full path to read the file" + ) + class FileReadTool(BaseTool): - name: str = "Read a file's content" - description: str = "A tool that can be used to read a file's content." - args_schema: Type[BaseModel] = FileReadToolSchema - file_path: Optional[str] = None + name: str = "Read a file's content" + description: str = "A tool that can be used to read a file's content." + args_schema: Type[BaseModel] = FileReadToolSchema + file_path: Optional[str] = None - def __init__(self, file_path: Optional[str] = None, **kwargs): - super().__init__(**kwargs) - if file_path is not None: - self.file_path = file_path - self.description = f"A tool that can be used to read {file_path}'s content." - self.args_schema = FixedFileReadToolSchema - self._generate_description() + def __init__( + self, + file_path: Optional[str] = None, + **kwargs + ): + super().__init__(**kwargs) + if file_path is not None: + self.file_path = file_path + self.description = f"A tool that can be used to read {file_path}'s content." + self.args_schema = FixedFileReadToolSchema + self._generate_description() - def _run( - self, - **kwargs: Any, - ) -> Any: - file_path = kwargs.get('file_path', self.file_path) - with open(file_path, 'r') as file: - return file.read() \ No newline at end of file + def _run( + self, + **kwargs: Any, + ) -> Any: + try: + file_path = kwargs.get('file_path', self.file_path) + with open(file_path, 'r') as file: + return file.read() + except Exception as e: + return f"Fail to read the file {file_path}. Error: {e}" From 4e9709b8fb4a1f88eaaaaf9f7bddd9c3a54a5153 Mon Sep 17 00:00:00 2001 From: Gui Vieira Date: Thu, 4 Apr 2024 13:42:30 -0300 Subject: [PATCH 03/13] Fix RAG tools --- .../tools/code_docs_search_tool/code_docs_search_tool.py | 7 +++++++ .../tools/csv_search_tool/csv_search_tool.py | 7 +++++++ .../tools/directory_search_tool/directory_search_tool.py | 7 +++++++ .../tools/docx_search_tool/docx_search_tool.py | 7 +++++++ .../tools/github_search_tool/github_search_tool.py | 9 ++++++++- .../tools/json_search_tool/json_search_tool.py | 7 +++++++ src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py | 7 +++++++ src/crewai_tools/tools/pg_seach_tool/pg_search_tool.py | 7 +++++++ .../tools/txt_search_tool/txt_search_tool.py | 7 +++++++ .../tools/website_search/website_search_tool.py | 7 +++++++ .../tools/xml_search_tool/xml_search_tool.py | 7 +++++++ .../youtube_channel_search_tool.py | 7 +++++++ .../youtube_video_search_tool.py | 7 +++++++ 13 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py b/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py index 195cc8a05..a5d6e5a21 100644 --- a/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py +++ b/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py @@ -50,3 +50,10 @@ class CodeDocsSearchTool(RagTool): ) -> Any: if "docs_url" in kwargs: self.add(kwargs["docs_url"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py b/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py index 6b8e79f88..fe9617f40 100644 --- a/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py +++ b/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py @@ -50,3 +50,10 @@ class CSVSearchTool(RagTool): ) -> Any: if "csv" in kwargs: self.add(kwargs["csv"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py b/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py index 7f20f5979..bb07d44ed 100644 --- a/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py +++ b/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py @@ -50,3 +50,10 @@ class DirectorySearchTool(RagTool): ) -> Any: if "directory" in kwargs: self.add(kwargs["directory"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py b/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py index 5c64f9824..d79efd82c 100644 --- a/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py +++ b/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py @@ -50,3 +50,10 @@ class DOCXSearchTool(RagTool): ) -> Any: if "docx" in kwargs: self.add(kwargs["docx"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/github_search_tool/github_search_tool.py b/src/crewai_tools/tools/github_search_tool/github_search_tool.py index 4a84b166c..eead8e49a 100644 --- a/src/crewai_tools/tools/github_search_tool/github_search_tool.py +++ b/src/crewai_tools/tools/github_search_tool/github_search_tool.py @@ -21,7 +21,7 @@ class GithubSearchToolSchema(FixedGithubSearchToolSchema): github_repo: str = Field(..., description="Mandatory github you want to search") content_types: List[str] = Field( ..., - description="Mandatory content types you want to be inlcuded search, options: [code, repo, pr, issue]", + description="Mandatory content types you want to be included search, options: [code, repo, pr, issue]", ) @@ -56,3 +56,10 @@ class GithubSearchTool(RagTool): ) -> Any: if "github_repo" in kwargs: self.add(kwargs["github_repo"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/json_search_tool/json_search_tool.py b/src/crewai_tools/tools/json_search_tool/json_search_tool.py index 308dca726..71bda18fb 100644 --- a/src/crewai_tools/tools/json_search_tool/json_search_tool.py +++ b/src/crewai_tools/tools/json_search_tool/json_search_tool.py @@ -50,3 +50,10 @@ class JSONSearchTool(RagTool): ) -> Any: if "json_path" in kwargs: self.add(kwargs["json_path"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py b/src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py index 33a58e142..a3a768e99 100644 --- a/src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py +++ b/src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py @@ -50,3 +50,10 @@ class MDXSearchTool(RagTool): ) -> Any: if "mdx" in kwargs: self.add(kwargs["mdx"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/pg_seach_tool/pg_search_tool.py b/src/crewai_tools/tools/pg_seach_tool/pg_search_tool.py index f22cac123..226fb1ddd 100644 --- a/src/crewai_tools/tools/pg_seach_tool/pg_search_tool.py +++ b/src/crewai_tools/tools/pg_seach_tool/pg_search_tool.py @@ -35,3 +35,10 @@ class PGSearchTool(RagTool): kwargs["data_type"] = "postgres" kwargs["loader"] = PostgresLoader(config=dict(url=self.db_uri)) super().add(f"SELECT * FROM {table_name};", **kwargs) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/txt_search_tool/txt_search_tool.py b/src/crewai_tools/tools/txt_search_tool/txt_search_tool.py index 375ba960a..e8e653061 100644 --- a/src/crewai_tools/tools/txt_search_tool/txt_search_tool.py +++ b/src/crewai_tools/tools/txt_search_tool/txt_search_tool.py @@ -50,3 +50,10 @@ class TXTSearchTool(RagTool): ) -> Any: if "txt" in kwargs: self.add(kwargs["txt"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/website_search/website_search_tool.py b/src/crewai_tools/tools/website_search/website_search_tool.py index 5768a6ccd..9233e7766 100644 --- a/src/crewai_tools/tools/website_search/website_search_tool.py +++ b/src/crewai_tools/tools/website_search/website_search_tool.py @@ -50,3 +50,10 @@ class WebsiteSearchTool(RagTool): ) -> Any: if "website" in kwargs: self.add(kwargs["website"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/xml_search_tool/xml_search_tool.py b/src/crewai_tools/tools/xml_search_tool/xml_search_tool.py index 4b3e445ea..6caf09971 100644 --- a/src/crewai_tools/tools/xml_search_tool/xml_search_tool.py +++ b/src/crewai_tools/tools/xml_search_tool/xml_search_tool.py @@ -50,3 +50,10 @@ class XMLSearchTool(RagTool): ) -> Any: if "xml" in kwargs: self.add(kwargs["xml"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py b/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py index d3e4698c9..1eb89fe56 100644 --- a/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py +++ b/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py @@ -53,3 +53,10 @@ class YoutubeChannelSearchTool(RagTool): ) -> Any: if "youtube_channel_handle" in kwargs: self.add(kwargs["youtube_channel_handle"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) diff --git a/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py b/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py index f85457988..a2dd45661 100644 --- a/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py +++ b/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py @@ -50,3 +50,10 @@ class YoutubeVideoSearchTool(RagTool): ) -> Any: if "youtube_video_url" in kwargs: self.add(kwargs["youtube_video_url"]) + + def _run( + self, + search_query: str, + **kwargs: Any, + ) -> Any: + return super()._run(query=search_query) From 776826ec992b567718862b8eaf772b8eb7693dd4 Mon Sep 17 00:00:00 2001 From: Gui Vieira Date: Fri, 5 Apr 2024 18:04:45 -0300 Subject: [PATCH 04/13] Fix GithubSearchTool --- .../tools/github_search_tool/github_search_tool.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/crewai_tools/tools/github_search_tool/github_search_tool.py b/src/crewai_tools/tools/github_search_tool/github_search_tool.py index eead8e49a..1d64bae34 100644 --- a/src/crewai_tools/tools/github_search_tool/github_search_tool.py +++ b/src/crewai_tools/tools/github_search_tool/github_search_tool.py @@ -36,18 +36,21 @@ class GithubSearchTool(RagTool): def __init__(self, github_repo: Optional[str] = None, **kwargs): super().__init__(**kwargs) if github_repo is not None: - self.add(github_repo) + self.add(repo=github_repo) self.description = f"A tool that can be used to semantic search a query the {github_repo} github repo's content." self.args_schema = FixedGithubSearchToolSchema def add( self, - *args: Any, + repo: str, + content_types: List[str] | None = None, **kwargs: Any, ) -> None: + content_types = content_types or self.content_types + kwargs["data_type"] = "github" kwargs["loader"] = GithubLoader(config={"token": self.gh_token}) - super().add(*args, **kwargs) + super().add(f"repo:{repo} type:{','.join(content_types)}", **kwargs) def _before_run( self, @@ -55,7 +58,9 @@ class GithubSearchTool(RagTool): **kwargs: Any, ) -> Any: if "github_repo" in kwargs: - self.add(kwargs["github_repo"]) + self.add( + repo=kwargs["github_repo"], content_types=kwargs.get("content_types") + ) def _run( self, From 9f41fb405732b79ff7897019069c4e1cd7b28589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sun, 7 Apr 2024 14:18:41 -0300 Subject: [PATCH 05/13] Adding timeout to scrapping website tool --- .../tools/scrape_website_tool/scrape_website_tool.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/crewai_tools/tools/scrape_website_tool/scrape_website_tool.py b/src/crewai_tools/tools/scrape_website_tool/scrape_website_tool.py index cd8fd50d3..148a0b320 100644 --- a/src/crewai_tools/tools/scrape_website_tool/scrape_website_tool.py +++ b/src/crewai_tools/tools/scrape_website_tool/scrape_website_tool.py @@ -44,7 +44,12 @@ class ScrapeWebsiteTool(BaseTool): **kwargs: Any, ) -> Any: website_url = kwargs.get('website_url', self.website_url) - page = requests.get(website_url, headers=self.headers, cookies=self.cookies if self.cookies else {}) + page = requests.get( + website_url, + timeout=15, + headers=self.headers, + cookies=self.cookies if self.cookies else {} + ) parsed = BeautifulSoup(page.content, "html.parser") text = parsed.get_text() text = '\n'.join([i for i in text.split('\n') if i.strip() != '']) From 873112d696ab8acedc2c921493a6d8939fea7339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sun, 7 Apr 2024 18:12:16 -0300 Subject: [PATCH 06/13] fxing docs --- .../tools/github_search_tool/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/crewai_tools/tools/github_search_tool/README.md b/src/crewai_tools/tools/github_search_tool/README.md index 220e0aeb8..e6f47e082 100644 --- a/src/crewai_tools/tools/github_search_tool/README.md +++ b/src/crewai_tools/tools/github_search_tool/README.md @@ -1,24 +1,24 @@ -# GitHubSearchTool +# GithubSearchTool ## Description -The GitHubSearchTool is a Read, Append, and Generate (RAG) tool specifically designed for conducting semantic searches within GitHub repositories. Utilizing advanced semantic search capabilities, it sifts through code, pull requests, issues, and repositories, making it an essential tool for developers, researchers, or anyone in need of precise information from GitHub. +The GithubSearchTool is a Read, Append, and Generate (RAG) tool specifically designed for conducting semantic searches within GitHub repositories. Utilizing advanced semantic search capabilities, it sifts through code, pull requests, issues, and repositories, making it an essential tool for developers, researchers, or anyone in need of precise information from GitHub. ## Installation -To use the GitHubSearchTool, first ensure the crewai_tools package is installed in your Python environment: +To use the GithubSearchTool, first ensure the crewai_tools package is installed in your Python environment: ```shell pip install 'crewai[tools]' ``` -This command installs the necessary package to run the GitHubSearchTool along with any other tools included in the crewai_tools package. +This command installs the necessary package to run the GithubSearchTool along with any other tools included in the crewai_tools package. ## Example -Here’s how you can use the GitHubSearchTool to perform semantic searches within a GitHub repository: +Here’s how you can use the GithubSearchTool to perform semantic searches within a GitHub repository: ```python -from crewai_tools import GitHubSearchTool +from crewai_tools import GithubSearchTool # Initialize the tool for semantic searches within a specific GitHub repository -tool = GitHubSearchTool( +tool = GithubSearchTool( github_repo='https://github.com/example/repo', content_types=['code', 'issue'] # Options: code, repo, pr, issue ) @@ -26,7 +26,7 @@ tool = GitHubSearchTool( # OR # Initialize the tool for semantic searches within a specific GitHub repository, so the agent can search any repository if it learns about during its execution -tool = GitHubSearchTool( +tool = GithubSearchTool( content_types=['code', 'issue'] # Options: code, repo, pr, issue ) ``` From be1a60554f206ebfe3e44770659819e2fcc0e18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sun, 7 Apr 2024 18:22:09 -0300 Subject: [PATCH 07/13] TYPO --- src/crewai_tools/tools/github_search_tool/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crewai_tools/tools/github_search_tool/README.md b/src/crewai_tools/tools/github_search_tool/README.md index e6f47e082..4550e4224 100644 --- a/src/crewai_tools/tools/github_search_tool/README.md +++ b/src/crewai_tools/tools/github_search_tool/README.md @@ -40,7 +40,7 @@ tool = GithubSearchTool( By default, the tool uses OpenAI for both embeddings and summarization. To customize the model, you can use a config dictionary as follows: ```python -tool = GitHubSearchTool( +tool = GithubSearchTool( config=dict( llm=dict( provider="ollama", # or google, openai, anthropic, llama2, ... From c5fd5196e21d49af9f42ad4f6d5460bb34071652 Mon Sep 17 00:00:00 2001 From: Gui Vieira Date: Wed, 10 Apr 2024 11:48:23 -0300 Subject: [PATCH 08/13] Fix tool descriptions --- .../tools/code_docs_search_tool/code_docs_search_tool.py | 1 + src/crewai_tools/tools/csv_search_tool/csv_search_tool.py | 1 + .../tools/directory_search_tool/directory_search_tool.py | 1 + src/crewai_tools/tools/docx_search_tool/docx_search_tool.py | 1 + src/crewai_tools/tools/github_search_tool/README.md | 3 +++ .../tools/github_search_tool/github_search_tool.py | 5 +++-- src/crewai_tools/tools/json_search_tool/json_search_tool.py | 1 + src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py | 1 + src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py | 1 + src/crewai_tools/tools/txt_search_tool/txt_search_tool.py | 1 + src/crewai_tools/tools/website_search/website_search_tool.py | 1 + src/crewai_tools/tools/xml_search_tool/xml_search_tool.py | 1 + .../youtube_channel_search_tool.py | 1 + .../youtube_video_search_tool/youtube_video_search_tool.py | 1 + 14 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py b/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py index a5d6e5a21..a69ea7eb4 100644 --- a/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py +++ b/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py @@ -34,6 +34,7 @@ class CodeDocsSearchTool(RagTool): self.add(docs_url) self.description = f"A tool that can be used to semantic search a query the {docs_url} Code Docs content." self.args_schema = FixedCodeDocsSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py b/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py index fe9617f40..a04f227ca 100644 --- a/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py +++ b/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py @@ -34,6 +34,7 @@ class CSVSearchTool(RagTool): self.add(csv) self.description = f"A tool that can be used to semantic search a query the {csv} CSV's content." self.args_schema = FixedCSVSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py b/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py index bb07d44ed..9a988a7fa 100644 --- a/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py +++ b/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py @@ -34,6 +34,7 @@ class DirectorySearchTool(RagTool): self.add(directory) self.description = f"A tool that can be used to semantic search a query the {directory} directory's content." self.args_schema = FixedDirectorySearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py b/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py index d79efd82c..e6f5b2d55 100644 --- a/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py +++ b/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py @@ -34,6 +34,7 @@ class DOCXSearchTool(RagTool): self.add(docx) self.description = f"A tool that can be used to semantic search a query the {docx} DOCX's content." self.args_schema = FixedDOCXSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/github_search_tool/README.md b/src/crewai_tools/tools/github_search_tool/README.md index 4550e4224..55e01dd50 100644 --- a/src/crewai_tools/tools/github_search_tool/README.md +++ b/src/crewai_tools/tools/github_search_tool/README.md @@ -19,6 +19,7 @@ from crewai_tools import GithubSearchTool # Initialize the tool for semantic searches within a specific GitHub repository tool = GithubSearchTool( + gh_token='...', github_repo='https://github.com/example/repo', content_types=['code', 'issue'] # Options: code, repo, pr, issue ) @@ -27,11 +28,13 @@ tool = GithubSearchTool( # Initialize the tool for semantic searches within a specific GitHub repository, so the agent can search any repository if it learns about during its execution tool = GithubSearchTool( + gh_token='...', content_types=['code', 'issue'] # Options: code, repo, pr, issue ) ``` ## Arguments +- `gh_token` : The GitHub token used to authenticate the search. This is a mandatory field and allows the tool to access the GitHub API for conducting searches. - `github_repo` : The URL of the GitHub repository where the search will be conducted. This is a mandatory field and specifies the target repository for your search. - `content_types` : Specifies the types of content to include in your search. You must provide a list of content types from the following options: `code` for searching within the code, `repo` for searching within the repository's general information, `pr` for searching within pull requests, and `issue` for searching within issues. This field is mandatory and allows tailoring the search to specific content types within the GitHub repository. diff --git a/src/crewai_tools/tools/github_search_tool/github_search_tool.py b/src/crewai_tools/tools/github_search_tool/github_search_tool.py index 1d64bae34..5bfa65542 100644 --- a/src/crewai_tools/tools/github_search_tool/github_search_tool.py +++ b/src/crewai_tools/tools/github_search_tool/github_search_tool.py @@ -27,7 +27,7 @@ class GithubSearchToolSchema(FixedGithubSearchToolSchema): class GithubSearchTool(RagTool): name: str = "Search a github repo's content" - description: str = "A tool that can be used to semantic search a query from a github repo's content." + description: str = "A tool that can be used to semantic search a query from a github repo's content. This is not the GitHub API, but instead a tool that can provide semantic search capabilities." summarize: bool = False gh_token: str args_schema: Type[BaseModel] = GithubSearchToolSchema @@ -37,8 +37,9 @@ class GithubSearchTool(RagTool): super().__init__(**kwargs) if github_repo is not None: self.add(repo=github_repo) - self.description = f"A tool that can be used to semantic search a query the {github_repo} github repo's content." + self.description = f"A tool that can be used to semantic search a query the {github_repo} github repo's content. This is not the GitHub API, but instead a tool that can provide semantic search capabilities." self.args_schema = FixedGithubSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/json_search_tool/json_search_tool.py b/src/crewai_tools/tools/json_search_tool/json_search_tool.py index 71bda18fb..102cd89ad 100644 --- a/src/crewai_tools/tools/json_search_tool/json_search_tool.py +++ b/src/crewai_tools/tools/json_search_tool/json_search_tool.py @@ -34,6 +34,7 @@ class JSONSearchTool(RagTool): self.add(json_path) self.description = f"A tool that can be used to semantic search a query the {json_path} JSON's content." self.args_schema = FixedJSONSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py b/src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py index a3a768e99..99bd37348 100644 --- a/src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py +++ b/src/crewai_tools/tools/mdx_seach_tool/mdx_search_tool.py @@ -34,6 +34,7 @@ class MDXSearchTool(RagTool): self.add(mdx) self.description = f"A tool that can be used to semantic search a query the {mdx} MDX's content." self.args_schema = FixedMDXSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py b/src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py index 47e425a45..af95ae0bf 100644 --- a/src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py +++ b/src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py @@ -33,6 +33,7 @@ class PDFSearchTool(RagTool): self.add(pdf) self.description = f"A tool that can be used to semantic search a query the {pdf} PDF's content." self.args_schema = FixedPDFSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/txt_search_tool/txt_search_tool.py b/src/crewai_tools/tools/txt_search_tool/txt_search_tool.py index e8e653061..921e633e8 100644 --- a/src/crewai_tools/tools/txt_search_tool/txt_search_tool.py +++ b/src/crewai_tools/tools/txt_search_tool/txt_search_tool.py @@ -34,6 +34,7 @@ class TXTSearchTool(RagTool): self.add(txt) self.description = f"A tool that can be used to semantic search a query the {txt} txt's content." self.args_schema = FixedTXTSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/website_search/website_search_tool.py b/src/crewai_tools/tools/website_search/website_search_tool.py index 9233e7766..cfe163ae8 100644 --- a/src/crewai_tools/tools/website_search/website_search_tool.py +++ b/src/crewai_tools/tools/website_search/website_search_tool.py @@ -34,6 +34,7 @@ class WebsiteSearchTool(RagTool): self.add(website) self.description = f"A tool that can be used to semantic search a query from {website} website content." self.args_schema = FixedWebsiteSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/xml_search_tool/xml_search_tool.py b/src/crewai_tools/tools/xml_search_tool/xml_search_tool.py index 6caf09971..53fd73248 100644 --- a/src/crewai_tools/tools/xml_search_tool/xml_search_tool.py +++ b/src/crewai_tools/tools/xml_search_tool/xml_search_tool.py @@ -34,6 +34,7 @@ class XMLSearchTool(RagTool): self.add(xml) self.description = f"A tool that can be used to semantic search a query the {xml} XML's content." self.args_schema = FixedXMLSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py b/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py index 1eb89fe56..8e9591be8 100644 --- a/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py +++ b/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py @@ -34,6 +34,7 @@ class YoutubeChannelSearchTool(RagTool): self.add(youtube_channel_handle) self.description = f"A tool that can be used to semantic search a query the {youtube_channel_handle} Youtube Channels content." self.args_schema = FixedYoutubeChannelSearchToolSchema + self._generate_description() def add( self, diff --git a/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py b/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py index a2dd45661..f1caa1b9c 100644 --- a/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py +++ b/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py @@ -34,6 +34,7 @@ class YoutubeVideoSearchTool(RagTool): self.add(youtube_video_url) self.description = f"A tool that can be used to semantic search a query the {youtube_video_url} Youtube Video content." self.args_schema = FixedYoutubeVideoSearchToolSchema + self._generate_description() def add( self, From aab3acbaa66a7ffefac316fd78a4bfc3869a874c Mon Sep 17 00:00:00 2001 From: Christian24 Date: Mon, 15 Apr 2024 22:14:16 +0200 Subject: [PATCH 09/13] Fix wrong comments / descriptions for SerperDevTool --- src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py b/src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py index 3fbf5ea61..7328be83c 100644 --- a/src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py +++ b/src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py @@ -7,12 +7,12 @@ from pydantic.v1 import BaseModel, Field from crewai_tools.tools.base_tool import BaseTool class SerperDevToolSchema(BaseModel): - """Input for TXTSearchTool.""" + """Input for SerperDevTool.""" search_query: str = Field(..., description="Mandatory search query you want to use to search the internet") class SerperDevTool(BaseTool): name: str = "Search the internet" - description: str = "A tool that can be used to semantic search a query from a txt's content." + description: str = "A tool that can be used to search the internet." args_schema: Type[BaseModel] = SerperDevToolSchema search_url: str = "https://google.serper.dev/search" n_results: int = None From b80dd1ca8b83f5aa9b9cb30e6b5af4c54f482376 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:36:21 +0000 Subject: [PATCH 10/13] added BrowserbaseLoadTool --- src/crewai_tools/__init__.py | 1 + src/crewai_tools/tools/__init__.py | 3 +- .../tools/browserbase_load_tool/README.md | 29 +++++++++++++++++++ .../browserbase_load_tool.py | 21 ++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/crewai_tools/tools/browserbase_load_tool/README.md create mode 100644 src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py diff --git a/src/crewai_tools/__init__.py b/src/crewai_tools/__init__.py index 642ad703c..34e15b876 100644 --- a/src/crewai_tools/__init__.py +++ b/src/crewai_tools/__init__.py @@ -1,5 +1,6 @@ from .tools.base_tool import BaseTool, Tool, tool from .tools import ( + BrowserbaseLoadTool, CodeDocsSearchTool, CSVSearchTool, DirectorySearchTool, diff --git a/src/crewai_tools/tools/__init__.py b/src/crewai_tools/tools/__init__.py index 99860a14f..efbe0588e 100644 --- a/src/crewai_tools/tools/__init__.py +++ b/src/crewai_tools/tools/__init__.py @@ -1,3 +1,4 @@ +from .browserbase_load_tool.browserbase_load_tool import BrowserbaseLoadTool from .code_docs_search_tool.code_docs_search_tool import CodeDocsSearchTool from .csv_search_tool.csv_search_tool import CSVSearchTool from .directory_search_tool.directory_search_tool import DirectorySearchTool @@ -18,4 +19,4 @@ from .selenium_scraping_tool.selenium_scraping_tool import SeleniumScrapingTool from .website_search.website_search_tool import WebsiteSearchTool from .xml_search_tool.xml_search_tool import XMLSearchTool from .youtube_channel_search_tool.youtube_channel_search_tool import YoutubeChannelSearchTool -from .youtube_video_search_tool.youtube_video_search_tool import YoutubeVideoSearchTool \ No newline at end of file +from .youtube_video_search_tool.youtube_video_search_tool import YoutubeVideoSearchTool diff --git a/src/crewai_tools/tools/browserbase_load_tool/README.md b/src/crewai_tools/tools/browserbase_load_tool/README.md new file mode 100644 index 000000000..0007feb91 --- /dev/null +++ b/src/crewai_tools/tools/browserbase_load_tool/README.md @@ -0,0 +1,29 @@ +# BrowserbaseLoadTool + +## Description + +[Browserbase](https://browserbase.com) is a serverless platform for running headless browsers, it offers advanced debugging, session recordings, stealth mode, integrated proxies and captcha solving. + +## Installation + +- Get an API key from [browserbase.com](https://browserbase.com) and set it in environment variables (`BROWSERBASE_KEY`). +- Install the [Browserbase SDK](http://github.com/browserbase/python-sdk) along with `crewai[tools]` package: + +``` +pip install browserbase 'crewai[tools]' +``` + +## Example + +Utilize the BrowserbaseLoadTool as follows to allow your agent to load websites: + +```python +from crewai_tools import BrowserbaseLoadTool + +tool = BrowserbaseLoadTool() +``` + +## Arguments + +- `api_key`: Optional. Specifies Browserbase API key. Defaults is the `BROWSERBASE_KEY` environment variable. +- `text_content`: Optional. Load pages as readable text. Default is `False`. diff --git a/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py b/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py new file mode 100644 index 000000000..03ee53f99 --- /dev/null +++ b/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py @@ -0,0 +1,21 @@ +import os +from crewai_tools import BaseTool +from typing import Union + +class BrowserbaseLoadTool(BaseTool): + name: str = "Browserbase web load tool" + description: str = "Load webpages in a headless browser using Browserbase and return the contents" + + def __init__(self, api_key: str = os.environ["BROWSERBASE_KEY"], text_content: bool = False): + try: + from browserbase import Browserbase + except ImportError: + raise ImportError( + "`browserbase` package not found, please run `pip install browserbase`" + ) + + self.browserbase = Browserbase(api_key=api_key) + self.text_content = text_content + + def _run(self, url: str): + return self.browserbase.load_url(url, text_content=self.text_content) From e0d799c075972414d328ee4d9e362e286c90f0ef Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Fri, 19 Apr 2024 11:40:03 +0000 Subject: [PATCH 11/13] updated browserbase integration --- src/crewai_tools/tools/browserbase_load_tool/README.md | 4 ++-- .../tools/browserbase_load_tool/browserbase_load_tool.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/crewai_tools/tools/browserbase_load_tool/README.md b/src/crewai_tools/tools/browserbase_load_tool/README.md index 0007feb91..a2866f9a8 100644 --- a/src/crewai_tools/tools/browserbase_load_tool/README.md +++ b/src/crewai_tools/tools/browserbase_load_tool/README.md @@ -6,7 +6,7 @@ ## Installation -- Get an API key from [browserbase.com](https://browserbase.com) and set it in environment variables (`BROWSERBASE_KEY`). +- Get an API key from [browserbase.com](https://browserbase.com) and set it in environment variables (`BROWSERBASE_API_KEY`). - Install the [Browserbase SDK](http://github.com/browserbase/python-sdk) along with `crewai[tools]` package: ``` @@ -25,5 +25,5 @@ tool = BrowserbaseLoadTool() ## Arguments -- `api_key`: Optional. Specifies Browserbase API key. Defaults is the `BROWSERBASE_KEY` environment variable. +- `api_key`: Optional. Specifies Browserbase API key. Defaults is the `BROWSERBASE_API_KEY` environment variable. - `text_content`: Optional. Load pages as readable text. Default is `False`. diff --git a/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py b/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py index 03ee53f99..126219bd3 100644 --- a/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py +++ b/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py @@ -1,12 +1,12 @@ import os from crewai_tools import BaseTool -from typing import Union +from typing import Union, Optional class BrowserbaseLoadTool(BaseTool): name: str = "Browserbase web load tool" description: str = "Load webpages in a headless browser using Browserbase and return the contents" - def __init__(self, api_key: str = os.environ["BROWSERBASE_KEY"], text_content: bool = False): + def __init__(self, api_key: Optional[str] = None, text_content: bool = False): try: from browserbase import Browserbase except ImportError: From 39aba4cb48b0fdbfc2dff63ee01ec0d6c6c22078 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:14:56 +0000 Subject: [PATCH 12/13] updated browserbase load tool --- .../tools/browserbase_load_tool/browserbase_load_tool.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py b/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py index 126219bd3..7bf066287 100644 --- a/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py +++ b/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py @@ -1,12 +1,15 @@ -import os from crewai_tools import BaseTool -from typing import Union, Optional +from typing import Optional, Any class BrowserbaseLoadTool(BaseTool): name: str = "Browserbase web load tool" description: str = "Load webpages in a headless browser using Browserbase and return the contents" + api_key: Optional[str] = None + text_content: Optional[bool] = False + browserbase: Optional[Any] = None - def __init__(self, api_key: Optional[str] = None, text_content: bool = False): + def __init__(self, api_key: Optional[str] = None, text_content: Optional[bool] = False, **kwargs): + super().__init__(**kwargs) try: from browserbase import Browserbase except ImportError: From f78011e68ca911010b81a4097b153d57eca3162b Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 29 Apr 2024 11:53:10 +0200 Subject: [PATCH 13/13] added args_schema to browserbase tool --- .../tools/browserbase_load_tool/browserbase_load_tool.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py b/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py index 7bf066287..d29656188 100644 --- a/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py +++ b/src/crewai_tools/tools/browserbase_load_tool/browserbase_load_tool.py @@ -1,9 +1,14 @@ from crewai_tools import BaseTool from typing import Optional, Any +from pydantic.v1 import BaseModel, Field + +class BrowserbaseLoadToolSchema(BaseModel): + url: str = Field(description="Website URL") class BrowserbaseLoadTool(BaseTool): name: str = "Browserbase web load tool" description: str = "Load webpages in a headless browser using Browserbase and return the contents" + args_schema: Type[BaseModel] = BrowserbaseLoadToolSchema api_key: Optional[str] = None text_content: Optional[bool] = False browserbase: Optional[Any] = None