Skip to content

krankos/chat-ytchannel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Chat with YouTube Videos ๐ŸŽฌ

Want to talk to YouTube videos? This template builds a RAG (Retrieval-Augmented Generation) system that lets you chat with the Mastra AI YouTube channel using AI! Ask questions, get summaries, find topics - just like having a conversation with video transcripts.

๐ŸŽฏ Built for Mastra AI: This template works with the Mastra AI YouTube channel, but you can use it with any YouTube channel!

What This Does ๐Ÿค–

This template creates a RAG chatbot that knows everything about YouTube videos:

๐ŸŽฏ Chat with Videos: Ask "What did they say about workflows?" and get smart answers from Mastra AI video transcripts.

๐Ÿ“š Learn Mastra: Build something fun while learning Mastra concepts like workflows, agents, and tools.

๐Ÿ”„ Use Any Channel: Want different videos? Just change the video IDs.

How It Works โœจ

  1. Process Videos: Download and transcribe Mastra AI YouTube videos (or any videos!)
  2. Extract & Store: AI pulls out speakers, topics, and key insights, stores them as searchable chunks
  3. RAG Chat: When you ask questions, it retrieves relevant transcript chunks first
  4. Get YouTube Data: Uses the video IDs from retrieved chunks to fetch metadata, thumbnails, analytics via MCP

Why This is Cool ๐Ÿš€

  • ๐ŸŽฌ Talk to Videos: Get instant answers about Mastra AI content
  • ๐Ÿ” Smart Search: Find videos by topic, speaker, or just ask in plain English
  • ๐Ÿ“š Learn by Doing: Pick up Mastra skills while building something useful
  • ๐Ÿ› ๏ธ Ready to Use: Built for real use, not just demos

Quick Start ๐Ÿƒโ€โ™‚๏ธ

What You Need ๐Ÿ“‹

  • Node.js 20.9.0+
  • PostgreSQL with pgvector
  • OpenAI API key
  • Deepgram API key
  • Smithery.ai account

Get Started ๐Ÿ”ง

# Get the code
git clone <repository-url>
cd chat-ytchannel
pnpm install

# Add your API keys
cp .env.example .env
# Edit .env with your keys

# Set up database
pnpm db:push

# Start it up!
pnpm dev

Your API Keys ๐Ÿ”‘

Put these in your .env file:

# Database
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres

# AI Services
OPENAI_API_KEY=your_openai_key_here
DEEPGRAM_API_KEY=your_deepgram_key_here

# YouTube Access (you'll need YouTube Data API key when setting up Smithery)
SMITHERY_API_KEY=your_smithery_key_here
SMITHERY_PROFILE=your_profile_here

๐Ÿ’ก Note: When setting up your Smithery account, you'll need a YouTube Data API key to access YouTube videos and their metadata.

How to Use It ๐ŸŽฎ

1. Process Some Videos ๐Ÿฟ

First, let's teach the RAG system about some Mastra videos:

  1. Start the server: pnpm dev
  2. Go to the Mastra playground at http://localhost:4111/workflows
  3. Find the transcript-workflow and run it
  4. Provide these inputs:
    • videoId: Any YouTube video ID (e.g., "dQw4w9WgXcQ")
    • keywords: Array of relevant terms like ["AI", "Mastra", "workflows"]

This will:

  • Download the video's audio
  • Turn speech into text with Deepgram
  • Extract topics, speakers, and summaries with AI
  • Split into chunks and store with vector embeddings for RAG

2. Start Chatting! ๐Ÿ’ฌ

Once you've processed some videos, go to http://localhost:4111/agents/youtubeAgent/chat and try asking:

For Mastra AI videos:

  • "What did they say about building agents?"
  • "Find videos about workflows"
  • "Summarize the latest tool tutorial"
  • "Who talks about memory in the videos?"
  • "Show me the most popular video about agents"

The RAG system works like this:

  1. Retrieves transcript chunks that match your question from the vector database
  2. Gets video IDs from those chunks
  3. Fetches YouTube metadata (titles, descriptions, thumbnails, view counts) via MCP
  4. Combines everything to give you complete answers with context

๐Ÿ’ก Note: You need to process at least one video first using the workflow above, or you won't have any data to chat about!

3. Use Different Channels ๐ŸŒŸ

Want to build RAG on other YouTube channels? Just process their videos using the same workflow in the playground with any YouTube video ID and relevant keywords.

What's Inside? ๐Ÿ”ง

This template shows you how to use key Mastra features:

The Tech Stack ๐Ÿ› ๏ธ

  • Workflows: Multi-step processes that handle errors and keep going
  • Tools: Functions the AI can call to search and analyze videos
  • Agents: Chatbots that remember conversations and use tools smartly
  • MCP: Connect to external APIs (like YouTube) seamlessly

The Main Parts โœจ

  • transcriptWorkflow: Processes videos behind the scenes
  • youtubeAgent: Your chat buddy who knows about videos
  • videoSearchTool: Smart search that's both fast and accurate

What Powers It โšก

  • Database: PostgreSQL + pgvector for storing video transcripts and embeddings
  • AI: OpenAI for chat + Deepgram for transcription
  • YouTube: Access via Smithery.ai MCP servers (gets metadata, thumbnails, analytics)
  • Framework: Mastra with TypeScript

Database ๐Ÿ—„๏ธ

Simple schema that stores everything you need:

-- Videos: transcripts and AI insights
CREATE TABLE videos (
  id TEXT PRIMARY KEY,              -- YouTube video ID
  fullTranscript TEXT,              -- Complete transcript
  metadata JSONB,                   -- AI insights (summary, speakers, topics)
  createdAt TIMESTAMP,
  updatedAt TIMESTAMP
);

-- Chunks: searchable pieces
CREATE TABLE chunks (
  id TEXT PRIMARY KEY,
  videoId TEXT REFERENCES videos(id),
  data JSONB,                       -- Chunk content + metadata
  createdAt TIMESTAMP
);

Customize It ๐ŸŽจ

Add More Metadata

// In transcript-workflow.ts, add more fields
const videoDataSchema = z.object({
  summary: z.string(),
  sentiment: z.enum(["positive", "negative", "neutral"]),
  difficulty: z.enum(["beginner", "intermediate", "advanced"]),
  keyTopics: z.array(z.string()),
  speakers: z.array(z.string()),
});

Add Search Filters

// In retrieval-tool.ts, add date filtering
const queryVideos = async (filters?: {
  speaker?: string;
  tag?: string;
  dateRange?: { start: Date; end: Date };
}) => {
  // Your filtering logic
};

Commands ๐Ÿ’ป

# Development
pnpm dev                    # Start with playground
pnpm build                  # Build for production
pnpm start                  # Run production

# Database
pnpm db:push               # Update schema
pnpm db:studio             # View data

Common Issues ๐Ÿ”ง

"Failed to download video"

  • Check the video ID is correct
  • Some videos can't be downloaded
  • Try a different video

"Database connection failed"

  • Make sure PostgreSQL is running
  • Check your DATABASE_URL
  • Install pgvector extension

"No search results"

  • Process some videos first
  • Check your API keys work
  • Make sure the database has data

What Makes This Special โœจ

Learn by Building

  • Real Example: Not just theory - you build something useful
  • Mastra Patterns: See how workflows, tools, and agents work together
  • Best Practices: Learn the right way to structure Mastra apps

Production Ready

  • Error Handling: Things break, but the app keeps working
  • Type Safety: TypeScript catches bugs before they happen
  • Performance: Built to handle lots of videos efficiently

Easy to Extend

  • Any Channel: Works with any YouTube channel
  • Add Features: Easy to add new search filters or metadata
  • Integration: Connect to other services via MCP

Ideas for More ๐Ÿ’ก

This template can become:

  • Multi-channel processor - Handle entire YouTube channels
  • Real-time updates - Auto-process new videos
  • Analytics dashboard - Track trends and engagement
  • Slack bot - Ask questions from your team chat
  • API service - Power other apps with video intelligence

Learn More ๐Ÿ“š

Contributing ๐Ÿค

This is a learning template! Feel free to:

  • Fork it and make it your own
  • Submit improvements
  • Share what you built with it

Built with โค๏ธ using Mastra - The AI framework that makes building actually fun.

About

A Mastra template that let's you chat with youtube videos.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published