YoutubeChannelSearchTool
我们仍在努力改进工具,因此未来可能会出现意外行为或变更。
此工具旨在对特定 YouTube 频道的内容进行语义搜索。它利用 RAG(检索增强生成)方法提供相关的搜索结果,对于提取信息或查找特定内容非常有价值,无需手动筛选视频。它简化了在 YouTube 频道内的搜索过程,满足了研究人员、内容创作者和寻求特定信息或主题的观众的需求。
要使用 YoutubeChannelSearchTool,必须安装 crewai_tools 包。在您的 shell 中执行以下命令进行安装
pip install 'crewai[tools]'
以下示例演示了如何将 YoutubeChannelSearchTool 与 CrewAI 代理一起使用
from crewai import Agent, Task, Crew
from crewai_tools import YoutubeChannelSearchTool
# Initialize the tool for general YouTube channel searches
youtube_channel_tool = YoutubeChannelSearchTool()
# Define an agent that uses the tool
channel_researcher = Agent(
role="Channel Researcher",
goal="Extract relevant information from YouTube channels",
backstory="An expert researcher who specializes in analyzing YouTube channel content.",
tools=[youtube_channel_tool],
verbose=True,
)
# Example task to search for information in a specific channel
research_task = Task(
description="Search for information about machine learning tutorials in the YouTube channel {youtube_channel_handle}",
expected_output="A summary of the key machine learning tutorials available on the channel.",
agent=channel_researcher,
)
# Create and run the crew
crew = Crew(agents=[channel_researcher], tasks=[research_task])
result = crew.kickoff(inputs={"youtube_channel_handle": "@exampleChannel"})
您也可以使用特定的 YouTube 频道句柄来初始化该工具
# Initialize the tool with a specific YouTube channel handle
youtube_channel_tool = YoutubeChannelSearchTool(
youtube_channel_handle='@exampleChannel'
)
# Define an agent that uses the tool
channel_researcher = Agent(
role="Channel Researcher",
goal="Extract relevant information from a specific YouTube channel",
backstory="An expert researcher who specializes in analyzing YouTube channel content.",
tools=[youtube_channel_tool],
verbose=True,
)
YoutubeChannelSearchTool 接受以下参数
- youtube_channel_handle:可选。要搜索的 YouTube 频道的句柄。如果在初始化时提供,代理在使用该工具时将无需指定它。如果句柄不以“@”开头,将会自动添加。
- config:可选。底层 RAG 系统的配置,包括 LLM 和嵌入器设置。
- summarize:可选。是否对检索到的内容进行总结。默认为
False。
当智能体使用此工具时,需要提供:
- search_query:必需。用于在频道内容中查找相关信息的搜索查询。
- youtube_channel_handle:仅当初始化时未提供时才需要。要搜索的 YouTube 频道的句柄。
自定义模型和嵌入
默认情况下,该工具使用 OpenAI 进行嵌入和摘要。要自定义模型,您可以使用如下所示的配置字典:
youtube_channel_tool = YoutubeChannelSearchTool(
config=dict(
llm=dict(
provider="ollama", # or google, openai, anthropic, llama2, ...
config=dict(
model="llama2",
# temperature=0.5,
# top_p=1,
# stream=true,
),
),
embedder=dict(
provider="google", # or openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
# title="Embeddings",
),
),
)
)
代理集成示例
以下是一个更详细的示例,说明如何将 YoutubeChannelSearchTool 与 CrewAI 代理集成
from crewai import Agent, Task, Crew
from crewai_tools import YoutubeChannelSearchTool
# Initialize the tool
youtube_channel_tool = YoutubeChannelSearchTool()
# Define an agent that uses the tool
channel_researcher = Agent(
role="Channel Researcher",
goal="Extract and analyze information from YouTube channels",
backstory="""You are an expert channel researcher who specializes in extracting
and analyzing information from YouTube channels. You have a keen eye for detail
and can quickly identify key points and insights from video content across an entire channel.""",
tools=[youtube_channel_tool],
verbose=True,
)
# Create a task for the agent
research_task = Task(
description="""
Search for information about data science projects and tutorials
in the YouTube channel {youtube_channel_handle}.
Focus on:
1. Key data science techniques covered
2. Popular tutorial series
3. Most viewed or recommended videos
Provide a comprehensive summary of these points.
""",
expected_output="A detailed summary of data science content available on the channel.",
agent=channel_researcher,
)
# Run the task
crew = Crew(agents=[channel_researcher], tasks=[research_task])
result = crew.kickoff(inputs={"youtube_channel_handle": "@exampleDataScienceChannel"})
实现细节
YoutubeChannelSearchTool 作为 RagTool 的子类实现,后者为检索增强生成提供了基础功能
class YoutubeChannelSearchTool(RagTool):
name: str = "Search a Youtube Channels content"
description: str = "A tool that can be used to semantic search a query from a Youtube Channels content."
args_schema: Type[BaseModel] = YoutubeChannelSearchToolSchema
def __init__(self, youtube_channel_handle: Optional[str] = None, **kwargs):
super().__init__(**kwargs)
if youtube_channel_handle is not None:
kwargs["data_type"] = DataType.YOUTUBE_CHANNEL
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,
youtube_channel_handle: str,
**kwargs: Any,
) -> None:
if not youtube_channel_handle.startswith("@"):
youtube_channel_handle = f"@{youtube_channel_handle}"
super().add(youtube_channel_handle, **kwargs)
YoutubeChannelSearchTool 提供了一种强大的方式,使用 RAG 技术搜索和提取 YouTube 频道内容中的信息。通过使代理能够在整个频道的视频中进行搜索,它促进了信息提取和分析任务,否则这些任务将难以执行。此工具对于从 YouTube 频道进行研究、内容分析和知识提取特别有用。