YouTube视频知识库构建工具

一个结合AI技术的YouTube视频分析与知识库构建系统,提供智能内容发现、转录分析和知识库管理功能。

  • by dannySubsense
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 dannysubsense/youtube-agent

使用说明

YouTube代理-智能知识库构建器

一个全面的YouTube视频分析和知识库构建系统,将人工智能的力量与高效的视频内容处理相结合。该系统通过直观的用户界面实现了智能内容发现、转录分析和知识库管理。

🚀 项目概述

YouTube Agent是一个模块化系统,可帮助您:

  • 🔍 搜索和发现 按主题分类的YouTube视频
  • 📜 提取和处理 视频转录自动
  • 🧠 建立知识库 使用RAG(检索增强生成)
  • 💬 与您的视频内容聊天 使用AI驱动的对话
  • ⚡ 快速问题 即时洞察功能
  • 🎯 智能内容评估 技术新鲜度评分

🛠️ 建筑

该系统采用模块化架构,关注点明确分离:

  • core/ -核心业务逻辑(视频搜索、转录处理、本地矢量数据库)
  • mcp_integration/ -模型上下文协议集成层
  • agents/ -使用LangChain的AI代理编排
  • api/ -具有REST端点的FastAPI应用层
  • ui/ -用户界面组件(Streamlit仪表板)
  • config/ -配置和设置管理
  • tests/ -全面的测试套件

🎬 YouTube MCP服务器集成

此项目与自定义集成 YouTube MCP服务器 提供实时YouTube数据API访问。MCP服务器具有以下功能:

14完整功能

  1. get_video_details -全面的视频信息,包括元数据和统计数据
  2. get_playlist_details -检索播放列表信息和元数据
  3. get_playlist_items -列出播放列表中的视频及其详细信息
  4. get_channel_details -频道信息,包括用户数量和描述
  5. get_video_categories -特定地区的可用视频类别
  6. get_channel_videos -YouTube频道的最新视频
  7. search_videos -使用过滤器进行高级YouTube视频搜索
  8. get_trending_videos -特定地区的趋势内容
  9. get_video_comments -带排序选项的视频评论
  10. analyze_video_engagement -参与度指标和见解
  11. get_channel_playlists -列出YouTube频道的播放列表
  12. get_video_caption_info -可用字幕/文字记录信息
  13. evaluate_video_for_knowledge_base - 具有新鲜度评分的智能内容评估
  14. get_video_transcript - 从视频中提取完整的转录内容

MCP的主要功能

✅ 实时数据 来自YouTube数据API v3
✅ 全面的错误处理 API配额管理
✅ 支持多种URL格式 (youtube.com、youtu.be、@用户名、频道ID)
✅ 智能内容评估 技术新鲜度评分
✅ 灵活的搜索和过滤 选项
✅ 啮合分析 符合行业基准
✅ 区域内容支持 用于趋势和类别
✅ MCP协议合规性 实现无缝的人工智能集成

YouTube MCP服务器存储库: https://github.com/dannySubsense/youtube-mcp-server

🚀 快速开始

先决条件

  • Python 3.8+
  • YouTube数据API v3密钥
  • OpenAI API密钥
  • 不需要外部数据库 -使用本地Chroma矢量数据库

安装

  1. 克隆存储库

    git clone <repository-url>
    cd youtube-agent
    
  2. 安装依赖项

    pip install -r requirements.txt
    # or using uv
    uv pip install -r requirements.txt
    
  3. 设置凭据 创建一个 credentials.yml 使用API密钥在项目根目录中创建文件:

    youtube: 'your-youtube-api-key-here'
    openai: 'your-openai-api-key-here'
    

运行应用程序

选项1:模块化架构(推荐)

uv run streamlit run ui/streamlit/streamlit_runner.py

选项2:MVP版本(参考)

uv run streamlit run youtube_agent_mvp.py

🧪 测试

测试结构

该项目包括跨多个层的全面测试:

tests/
├── unit/                    # Unit tests for individual components
│   ├── test_ui_components.py      # UI component tests
│   ├── test_mcp_client.py         # MCP client functionality tests
│   ├── test_mcp_server.py         # MCP server integration tests
│   ├── test_mcp_property_based.py # Property-based testing
│   └── test_video_search.py       # Video search logic tests
├── integration/             # Integration tests for workflows
│   ├── test_ui_workflow.py        # End-to-end UI workflow tests
│   └── test_modular_integration.py # Modular architecture integration
├── test_mcp_integration.py  # MCP protocol integration tests
└── fixtures/               # Test data and fixtures

运行测试

运行所有测试

# Using pytest
pytest

# Using uv
uv run pytest

运行特定测试类别

# Unit tests only
pytest tests/unit/

# Integration tests only  
pytest tests/integration/

# MCP integration tests
pytest tests/test_mcp_integration.py

# UI workflow tests
pytest tests/integration/test_ui_workflow.py

运行覆盖率测试

pytest --cov=. --cov-report=html

基于属性的测试

# Run property-based tests for robust validation
pytest tests/unit/test_mcp_property_based.py -v

测试特性

  • 单元测试:单独测试单个功能和组件
  • 集成测试:测试完整的工作流程和组件交互
  • 基于属性的测试:使用假设进行稳健的边缘情况测试
  • UI工作流测试:模拟用户交互并验证行为
  • MCP协议测试:验证模型上下文协议集成
  • 夹具:可重复使用的测试数据,用于一致的测试

测试闸门

该项目遵循测试驱动开发(TDD),具有强制性关卡:

  • ✅ black --check -代码格式
  • ✅ flake8 -Linting
  • ✅ mypy -类型检查
  • ✅ pytest -所有测试必须通过

🏗️ 发展

代码质量

# Format code
black .

# Check linting
flake8

# Type checking  
mypy .

# Run all quality checks
black . && flake8 && mypy . && pytest

📊 特性

核心功能

  • 基于主题的视频发现:按主题或关键字在YouTube上搜索视频
  • 智能转录处理:提取、清理和处理视频记录
  • 本地矢量数据库:使用本地Chroma数据库存储和索引视频内容(不需要外部数据库)
  • 高级RAG:检索人工智能对话的相关内容
  • 对话记忆:在聊天会话中保持上下文

用户界面

  • 流线型仪表板:所有操作的直观web界面
  • 快速问题:预先生成的问题,以获得即时见解
  • 实时聊天:与您的视频知识库进行互动对话
  • 视频源显示:明确的归属和来源跟踪
  • 数据库管理:在不同的本地知识库之间轻松切换(存储在 data/ 目录)

人工智能集成

  • LangChain编排:复杂的代理协调
  • OpenAI集成:GPT支持的分析和对话
  • MCP协议:与模型上下文协议无缝集成
  • 内容评价:知识库管理的智能评分

🔧 配置

凭据配置

创建一个 credentials.yml 项目根目录中的文件:

# Required
youtube: 'your-youtube-api-key-here'
openai: 'your-openai-api-key-here'

备注:系统使用本地 credentials.yml 文件,而不是API密钥管理的环境变量。出于安全考虑,git会自动忽略此文件。

🤝 贡献

  1. 分叉存储库
  2. 创建要素分支(git checkout -b feature/amazing-feature)
  3. 遵循开发理念和代码指南
  4. 确保所有测试通过(pytest)
  5. 进行质量检查(black . && flake8 && mypy .)
  6. 使用常规提交格式提交更改
  7. 推到分支(git push origin feature/amazing-feature)
  8. 打开拉取请求

📄 许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

🙏 致谢

  • YouTube数据API v3 用于视频数据访问
  • OpenAI 用于人工智能分析
  • LangChain 用于代理编排
  • 溪流 对于用户界面
  • 色度 用于本地矢量数据库功能
  • 模型上下文协议 AI集成标准

准备好从YouTube内容构建智能知识库了吗?今天就开始吧! 🚀