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

[BUG] compatibility error with pydantic #1551

Open
JoseiltonMota opened this issue Nov 1, 2024 · 0 comments
Open

[BUG] compatibility error with pydantic #1551

JoseiltonMota opened this issue Nov 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@JoseiltonMota
Copy link

Description

Im getting this erro:
AttributeError: type object 'YoutubeVideoDetailsToolInput' has no attribute 'model_fields'

Steps to Reproduce

when I run the crew, it shows the error in the agents

Expected behavior

Screenshots/Code snippets

def research_manager(self, youtube_video_search_tool, youtube_video_details_tool):
    return Agent(
        role="YouTube Research Manager",
        goal="""For a given topic and description for a new YouTube video, find a minimum of 15 high-performing videos 
            on the same topic with the ultimate goal of populating the research table which will be used by 
            other agents to help them generate titles  and other aspects of the new YouTube video 
            that we are planning to create.""",
        backstory="""As a methodical and detailed research managar, you are responsible for overseeing researchers who 
            actively search YouTube to find high-performing YouTube videos on the same topic.""",
        verbose=True,
        allow_delegation=True,
        tools=[youtube_video_search_tool, youtube_video_details_tool]
    )

Operating System

Windows 11

Python Version

3.11

crewAI Version

crewai==0.76.9

crewAI Tools Version

crewai-tools==0.13.4

Virtual Environment

Venv

Evidence

Traceback (most recent call last):
File "D:\Documentos\codigos\youtube_helper\main.py", line 25, in
research_manager = agents.research_manager(youtube_video_search_tool, youtube_video_details_tool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documentos\codigos\youtube_helper\agents.py", line 29, in research_manager
return Agent(
^^^^^^
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\pydantic\main.py", line 212, in init
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agent.py", line 179, in post_init_setup
self._setup_agent_executor()
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agent.py", line 189, in _setup_agent_executor
self.set_cache_handler(self.cache_handler)
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agents\agent_builder\base_agent.py", line 262, in set_cache_handler
self.create_agent_executor()
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agent.py", line 300, in create_agent_executor
tools_description=self._render_text_description_and_args(parsed_tools),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documentos\codigos\youtube_helper\env\Lib\site-packages\crewai\agent.py", line 412, in _render_text_description_and_args
for name, field in tool.args_schema.model_fields.items()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'YoutubeVideoDetailsToolInput' has no attribute 'model_fields'

Possible Solution

None

Additional context

from typing import List, Type
from pydantic import BaseModel, Field
from crewai_tools import BaseTool
import os
import requests
from datetime import datetime, timezone

class VideoSearchResult(BaseModel):
video_id: str
title: str
channel_id: str
channel_title: str
days_since_published: int

class YoutubeVideoSearchToolInput(BaseModel):
"""Input for YoutubeVideoSearchTool."""
keyword: str = Field(..., description="The search keyword.")
max_results: int = Field(10, description="The maximum number of results to return.")

class YoutubeVideoSearchTool(BaseTool):
name: str = "Search YouTube Videos"
description: str = "Searches YouTube videos based on a keyword and returns a list of video search results."
#args_schema: Type[BaseModel] = YoutubeVideoSearchToolInput

def _run(self, keyword: str, max_results: int = 10) -> list:
    api_key = os.getenv("YOUTUBE_API_KEY")
    url = "https://www.googleapis.com/youtube/v3/search"
    params = {
        "part": "snippet",
        "q": keyword,
        "maxResults": max_results,
        "type": "video",
        "key": api_key
    }
    response = requests.get(url, params=params)
    response.raise_for_status()
    items = response.json().get("items", [])

    results = []
    for item in items:
        video_id = item["id"]["videoId"]
        title = item["snippet"]["title"]
        channel_id = item["snippet"]["channelId"]
        channel_title = item["snippet"]["channelTitle"]
        publish_date = datetime.fromisoformat(
            item["snippet"]["publishedAt"].replace('Z', '+00:00')).astimezone(timezone.utc)
        days_since_published = (datetime.now(
            timezone.utc) - publish_date).days
        results.append(
            video_id=video_id,
            title=title,
            channel_id=channel_id,
            channel_title=channel_title,
            days_since_published=days_since_published
        )

    return results
@JoseiltonMota JoseiltonMota added the bug Something isn't working label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant