البحث في فيديوهات YouTube باستخدام RAG
YoutubeVideoSearchTool
Section titled “YoutubeVideoSearchTool”هذه الأداة جزء من حزمة crewai_tools وهي مصممة لإجراء عمليات بحث دلالية داخل محتوى فيديو YouTube، باستخدام تقنيات التوليد المعزز بالاسترجاع (RAG).
هي واحدة من عدة أدوات “بحث” في الحزمة التي تستفيد من RAG لمصادر مختلفة.
تتيح أداة YoutubeVideoSearchTool المرونة في عمليات البحث؛ يمكن للمستخدمين البحث عبر أي محتوى فيديو YouTube دون تحديد عنوان URL للفيديو،
أو يمكنهم توجيه بحثهم إلى فيديو YouTube محدد من خلال تقديم عنوان URL الخاص به.
التثبيت
Section titled “التثبيت”لاستخدام YoutubeVideoSearchTool، يجب أولاً تثبيت حزمة crewai_tools.
تحتوي هذه الحزمة على YoutubeVideoSearchTool إلى جانب أدوات مساعدة أخرى مصممة لتعزيز مهام تحليل ومعالجة البيانات.
ثبّت الحزمة بتنفيذ الأمر التالي في الطرفية:
pip install 'crewai[tools]'يوضح المثال التالي كيفية استخدام YoutubeVideoSearchTool مع وكيل CrewAI:
from crewai import Agent, Task, Crewfrom crewai_tools import YoutubeVideoSearchTool
# Initialize the tool for general YouTube video searchesyoutube_search_tool = YoutubeVideoSearchTool()
# Define an agent that uses the toolvideo_researcher = Agent( role="Video Researcher", goal="Extract relevant information from YouTube videos", backstory="An expert researcher who specializes in analyzing video content.", tools=[youtube_search_tool], verbose=True,)
# Example task to search for information in a specific videoresearch_task = Task( description="Search for information about machine learning frameworks in the YouTube video at {youtube_video_url}", expected_output="A summary of the key machine learning frameworks mentioned in the video.", agent=video_researcher,)
# Create and run the crewcrew = Crew(agents=[video_researcher], tasks=[research_task])result = crew.kickoff(inputs={"youtube_video_url": "https://youtube.com/watch?v=example"})يمكنك أيضاً تهيئة الأداة بعنوان URL محدد لفيديو YouTube:
# Initialize the tool with a specific YouTube video URLyoutube_search_tool = YoutubeVideoSearchTool( youtube_video_url='https://youtube.com/watch?v=example')
# Define an agent that uses the toolvideo_researcher = Agent( role="Video Researcher", goal="Extract relevant information from a specific YouTube video", backstory="An expert researcher who specializes in analyzing video content.", tools=[youtube_search_tool], verbose=True,)المعاملات
Section titled “المعاملات”تقبل أداة YoutubeVideoSearchTool المعاملات التالية:
- youtube_video_url: اختياري. عنوان URL لفيديو YouTube للبحث داخله. إذا تم تقديمه أثناء التهيئة، لن يحتاج الوكيل إلى تحديده عند استخدام الأداة.
- config: اختياري. تكوين لنظام RAG الأساسي، بما في ذلك إعدادات LLM والتضمينات.
- summarize: اختياري. ما إذا كان يجب تلخيص المحتوى المسترجع. الافتراضي هو
False.
عند استخدام الأداة مع وكيل، سيحتاج الوكيل إلى تقديم:
- search_query: مطلوب. استعلام البحث للعثور على معلومات ذات صلة في محتوى الفيديو.
- youtube_video_url: مطلوب فقط إذا لم يتم تقديمه أثناء التهيئة. عنوان URL لفيديو YouTube للبحث داخله.
النموذج المخصص والتضمينات
Section titled “النموذج المخصص والتضمينات”بشكل افتراضي، تستخدم الأداة OpenAI لكل من التضمينات والتلخيص. لتخصيص النموذج، يمكنك استخدام قاموس تكوين كما يلي:
youtube_search_tool = YoutubeVideoSearchTool( 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-generativeai", # or openai, ollama, ... config=dict( model_name="gemini-embedding-001", task_type="RETRIEVAL_DOCUMENT", # title="Embeddings", ), ), ))مثال على التكامل مع الوكيل
Section titled “مثال على التكامل مع الوكيل”إليك مثالاً أكثر تفصيلاً لكيفية دمج YoutubeVideoSearchTool مع وكيل CrewAI:
from crewai import Agent, Task, Crewfrom crewai_tools import YoutubeVideoSearchTool
# Initialize the toolyoutube_search_tool = YoutubeVideoSearchTool()
# Define an agent that uses the toolvideo_researcher = Agent( role="Video Researcher", goal="Extract and analyze information from YouTube videos", backstory="""You are an expert video researcher who specializes in extracting and analyzing information from YouTube videos. You have a keen eye for detail and can quickly identify key points and insights from video content.""", tools=[youtube_search_tool], verbose=True,)
# Create a task for the agentresearch_task = Task( description=""" Search for information about recent advancements in artificial intelligence in the YouTube video at {youtube_video_url}.
Focus on: 1. Key AI technologies mentioned 2. Real-world applications discussed 3. Future predictions made by the speaker
Provide a comprehensive summary of these points. """, expected_output="A detailed summary of AI advancements, applications, and future predictions from the video.", agent=video_researcher,)
# Run the taskcrew = Crew(agents=[video_researcher], tasks=[research_task])result = crew.kickoff(inputs={"youtube_video_url": "https://youtube.com/watch?v=example"})تفاصيل التنفيذ
Section titled “تفاصيل التنفيذ”أداة YoutubeVideoSearchTool مُنفّذة كفئة فرعية من RagTool، التي توفر الوظائف الأساسية للتوليد المعزز بالاسترجاع:
class YoutubeVideoSearchTool(RagTool): name: str = "Search a Youtube Video content" description: str = "A tool that can be used to semantic search a query from a Youtube Video content." args_schema: Type[BaseModel] = YoutubeVideoSearchToolSchema
def __init__(self, youtube_video_url: Optional[str] = None, **kwargs): super().__init__(**kwargs) if youtube_video_url is not None: kwargs["data_type"] = DataType.YOUTUBE_VIDEO 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()الخلاصة
Section titled “الخلاصة”توفر أداة YoutubeVideoSearchTool طريقة قوية للبحث واستخراج المعلومات من محتوى فيديو YouTube باستخدام تقنيات RAG. من خلال تمكين الوكلاء من البحث داخل محتوى الفيديو، تسهّل مهام استخراج المعلومات والتحليل التي قد يكون من الصعب تنفيذها بطريقة أخرى. هذه الأداة مفيدة بشكل خاص للبحث وتحليل المحتوى واستخراج المعرفة من مصادر الفيديو.