mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 23:58:34 +00:00
Fixing imports and cutting new patch
This commit is contained in:
@@ -10,7 +10,7 @@ from .tools import (
|
||||
DOCXSearchTool,
|
||||
EXASearchTool,
|
||||
FileReadTool,
|
||||
FileWriterTool
|
||||
FileWriterTool,
|
||||
FirecrawlCrawlWebsiteTool,
|
||||
FirecrawlScrapeWebsiteTool,
|
||||
FirecrawlSearchTool,
|
||||
|
||||
@@ -11,10 +11,10 @@ from .exa_tools.exa_search_tool import EXASearchTool
|
||||
from .file_read_tool.file_read_tool import FileReadTool
|
||||
from .file_writer_tool.file_writer_tool import FileWriterTool
|
||||
from .firecrawl_crawl_website_tool.firecrawl_crawl_website_tool import (
|
||||
FirecrawlCrawlWebsiteTool,
|
||||
FirecrawlCrawlWebsiteTool
|
||||
)
|
||||
from .firecrawl_scrape_website_tool.firecrawl_scrape_website_tool import (
|
||||
FirecrawlScrapeWebsiteTool,
|
||||
FirecrawlScrapeWebsiteTool
|
||||
)
|
||||
from .firecrawl_search_tool.firecrawl_search_tool import FirecrawlSearchTool
|
||||
from .github_search_tool.github_search_tool import GithubSearchTool
|
||||
@@ -27,11 +27,11 @@ from .pdf_search_tool.pdf_search_tool import PDFSearchTool
|
||||
from .pg_seach_tool.pg_search_tool import PGSearchTool
|
||||
from .rag.rag_tool import RagTool
|
||||
from .scrape_element_from_website.scrape_element_from_website import (
|
||||
ScrapeElementFromWebsiteTool,
|
||||
ScrapeElementFromWebsiteTool
|
||||
)
|
||||
from .scrape_website_tool.scrape_website_tool import ScrapeWebsiteTool
|
||||
from .scrapfly_scrape_website_tool.scrapfly_scrape_website_tool import (
|
||||
ScrapflyScrapeWebsiteTool,
|
||||
ScrapflyScrapeWebsiteTool
|
||||
)
|
||||
from .selenium_scraping_tool.selenium_scraping_tool import SeleniumScrapingTool
|
||||
from .serper_dev_tool.serper_dev_tool import SerperDevTool
|
||||
@@ -46,7 +46,7 @@ from .vision_tool.vision_tool import VisionTool
|
||||
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,
|
||||
YoutubeChannelSearchTool
|
||||
)
|
||||
from .youtube_video_search_tool.youtube_video_search_tool import YoutubeVideoSearchTool
|
||||
from .mysql_search_tool.mysql_search_tool import MySQLSearchTool
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
import os
|
||||
from crewai_tools import BaseTool
|
||||
from typing import Optional, Type, Any
|
||||
|
||||
from pydantic.v1 import BaseModel
|
||||
from ..base_tool import BaseTool
|
||||
|
||||
class FileWriterToolInput(BaseModel):
|
||||
filename: str
|
||||
content: str
|
||||
directory: Optional[str] = None
|
||||
overwrite: bool = False
|
||||
|
||||
class FileWriterTool(BaseTool):
|
||||
name: str = "File Writer Tool"
|
||||
description: str = "A tool to write content to a specified file. Accepts filename, content, and optionally a directory path as input."
|
||||
description: str = "A tool to write content to a specified file. Accepts filename, content, and optionally a directory path and overwrite flag as input."
|
||||
args_schema: Type[BaseModel] = FileWriterToolInput
|
||||
|
||||
def _run(self, filename: str, content: str, directory: str = '.') -> str:
|
||||
def _run(self, **kwargs: Any) -> str:
|
||||
try:
|
||||
# Create the directory if it doesn't exist
|
||||
if directory and not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
if kwargs['directory'] and not os.path.exists(kwargs['directory']):
|
||||
os.makedirs(kwargs['directory'])
|
||||
|
||||
# Construct the full path
|
||||
filepath = os.path.join(directory, filename)
|
||||
filepath = os.path.join(kwargs['directory'] or '', kwargs['filename'])
|
||||
|
||||
# Check if file exists and overwrite is not allowed
|
||||
if os.path.exists(filepath) and not kwargs['overwrite']:
|
||||
return f"File {filepath} already exists and overwrite option was not passed."
|
||||
|
||||
# Write content to the file
|
||||
with open(filepath, 'w') as file:
|
||||
file.write(content)
|
||||
mode = 'w' if kwargs['overwrite'] else 'x'
|
||||
with open(filepath, mode) as file:
|
||||
file.write(kwargs['content'])
|
||||
return f"Content successfully written to {filepath}"
|
||||
except FileExistsError:
|
||||
return f"File {filepath} already exists and overwrite option was not passed."
|
||||
except Exception as e:
|
||||
return f"An error occurred while writing to the file: {str(e)}"
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
from typing import Any, Union
|
||||
|
||||
from crewai_tools import BaseTool
|
||||
from ..base_tool import BaseTool
|
||||
from pydantic import Field
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from typing import Optional, Type, Any
|
||||
from pydantic.v1 import BaseModel
|
||||
|
||||
class NL2SQLToolInput(BaseModel):
|
||||
sql_query: str = Field(
|
||||
title="SQL Query",
|
||||
description="The SQL query to execute.",
|
||||
)
|
||||
|
||||
class NL2SQLTool(BaseTool):
|
||||
name: str = "NL2SQLTool"
|
||||
@@ -15,6 +23,7 @@ class NL2SQLTool(BaseTool):
|
||||
)
|
||||
tables: list = []
|
||||
columns: dict = {}
|
||||
args_schema: Type[BaseModel] = NL2SQLToolInput
|
||||
|
||||
def model_post_init(self, __context: Any) -> None:
|
||||
data = {}
|
||||
|
||||
Reference in New Issue
Block a user