crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
21.38k stars 2.97k forks source link

TypeError: Cannot instantiate typing.Union - WebsiteSearchTool #573

Closed windowshopr closed 6 months ago

windowshopr commented 6 months ago

Python 3.11, Windows 10, crew==0.9.2, crewai==0.28.8, crewai-tools==0.2.4

from crewai_tools import WebsiteSearchTool
Traceback (most recent call last):
  File "I:\nasty\Python_Projects\LLM\CrewAI\DevelopersOnlyTeam\main.py", line 3, in <module>
    from crewai_tools import WebsiteSearchTool
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai_tools\__init__.py", line 1, in <module>
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai_tools\tools\__init__.py", line 6, in <module>
    from .docx_search_tool.docx_search_tool import DOCXSearchTool
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai_tools\tools\docx_search_tool\docx_search_tool.py", line 9, in <module>
    class FixedDOCXSearchToolSchema(BaseModel):
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\crewai_tools\tools\docx_search_tool\docx_search_tool.py", line 11, in FixedDOCXSearchToolSchema
    docx: str = Optional[Field](..., description="Mandatory docx path you want to search")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 1251, in __call__
    result = self.__origin__(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 463, in __call__
    raise TypeError(f"Cannot instantiate {self!r}")
TypeError: Cannot instantiate typing.Union
windowshopr commented 6 months ago

Looks like this fixed it for me:

    # Replace this line: docx: str = Optional[Field](..., description="Mandatory docx path you want to search")
    docx: Optional[str] = Field(..., description="Mandatory docx path you want to search") # with this one