{"slug": "automatically-attaching-youtube-video-footers-to-ai-tutorial-questions-gemini", "title": "Automatically Attaching YouTube Video Footers to AI Tutorial Questions: Gemini LLM & YouTube Search Service Integration", "summary": "A developer integrated Gemini LLM and YouTube Search services to automatically attach relevant video footers to AI tutorial questions. The system initially struggled when Gemini extracted overly general keywords from ambiguous queries, but the developer resolved this by modifying prompts to generate more specific search terms and adding filtering logic to YouTube Search for tutorial-appropriate videos.", "body_md": "Automatically Attaching YouTube Video Footers to Tutorial-Style Questions: An Integration Log of gemini_llm_service & youtube_search_service\n\nI've been developing a feature to automatically attach YouTube video footers to AI tutorial questions. My initial thought was simple: find a YouTube video relevant to the question and display it as a footer.\n\nMy first approach was to have `gemini_llm_service`\n\nunderstand the intent of the question and then use those keywords to search for videos via `youtube_search_service`\n\n. However, this turned out to be harder than I expected.\n\nWhen questions were a bit ambiguous, `gemini_llm_service`\n\noften extracted irrelevant keywords. For example, for a question like \"How to build a website with Python,\" just searching with the keyword \"website\" would yield overly general results.\n\n``` python\n# Initial attempt code (conceptual)\nfrom gemini_llm_service import GeminiLLM\nfrom youtube_search_service import YouTubeSearch\n\ngemini = GeminiLLM()\nyoutube = YouTubeSearch()\n\nquestion = \"Tell me how to build a simple website with Python\"\nkeywords = gemini.extract_keywords(question) # Problem often occurred here\n\nsearch_results = youtube.search(keywords)\n# ... video footer processing logic ...\n```\n\nDuring this process, the accuracy of keywords returned by `gemini_llm_service`\n\nwas low, repeatedly leading to `youtube_search_service`\n\nfailing to find the desired videos. I probably spent about 3 hours just struggling with this part.\n\nUltimately, the problem was that `gemini_llm_service`\n\nwasn't fully grasping the context of the question and was extracting overly general keywords. I realized that especially for tutorial-style questions, it's difficult to find the right video based solely on keywords.\n\nSo, I modified the prompt to instruct `gemini_llm_service`\n\nto generate more specific search keywords *only* when it clearly identifies the question as a tutorial request. I also implemented additional filtering logic in `youtube_search_service`\n\nto improve the relevance of search results.\n\n```\n# Modified prompt example (inside gemini_llm_service)\nprompt = f\"\"\"\nYou are an AI assistant that helps users find relevant YouTube tutorials.\nGiven the following user question, extract specific keywords that would be ideal for searching YouTube for a tutorial.\nFocus on the core topic and any specific technologies or methods mentioned.\nIf the question is clearly a request for a tutorial, be more specific in your keyword extraction.\n\nUser Question: \"{user_question}\"\nKeywords:\n\"\"\"\n\n# Added logic in youtube_search_service for filtering highly relevant videos (conceptual)\ndef search_and_filter_tutorials(query):\n    results = youtube_search_service.search(query)\n    # Logic to filter results more suitable for tutorial videos (e.g., video length, channel info)\n    filtered_results = [video for video in results if is_likely_tutorial(video)]\n    return filtered_results\n\ndef is_likely_tutorial(video):\n    # Simple heuristic: title includes 'tutorial', 'how to', 'guide', or\n    # description has many relevant keywords, or video length is appropriate.\n    title = video.get('title', '').lower()\n    description = video.get('description', '').lower()\n    duration = video.get('duration_seconds', 0)\n\n    if any(keyword in title for keyword in ['tutorial', 'how to', 'guide']):\n        return True\n    if 'python' in description and 'web development' in description: # Example\n        return True\n    if 300 < duration < 3600: # Videos between 5 minutes and 1 hour\n        return True\n    return False\n```\n\nBy integrating `gemini_llm_service`\n\nand `youtube_search_service`\n\nmore closely and adjusting the logic to suit each service's characteristics, the system started working much more stably.\n\n`gemini_llm_service`\n\nand `youtube_search_service`\n\n.", "url": "https://wpnews.pro/news/automatically-attaching-youtube-video-footers-to-ai-tutorial-questions-gemini", "canonical_source": "https://dev.to/junhee916/automatically-attaching-youtube-video-footers-to-ai-tutorial-questions-gemini-llm-youtube-search-5df2", "published_at": "2026-06-06 04:00:01+00:00", "updated_at": "2026-06-06 04:42:39.344373+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-tools", "ai-products", "natural-language-processing"], "entities": ["GeminiLLM", "YouTubeSearchService", "YouTube"], "alternates": {"html": "https://wpnews.pro/news/automatically-attaching-youtube-video-footers-to-ai-tutorial-questions-gemini", "markdown": "https://wpnews.pro/news/automatically-attaching-youtube-video-footers-to-ai-tutorial-questions-gemini.md", "text": "https://wpnews.pro/news/automatically-attaching-youtube-video-footers-to-ai-tutorial-questions-gemini.txt", "jsonld": "https://wpnews.pro/news/automatically-attaching-youtube-video-footers-to-ai-tutorial-questions-gemini.jsonld"}}