Lynean/GemmaYTAgent

Natural-language YouTube Music assistant powered by a 270M-parameter function-calling Gemma model — type plain English, it picks the right tool and opens your browser.

0

stars

2

commits

Python

primary language

Apr 8, 2026

updated

README

Gemma YTMusic Assistant

A natural-language YouTube Music assistant powered by FunctionGemma — a 270M-parameter Gemma 3 model fine-tuned for structured function calling. Type plain English; the model dispatches to the right tool; your browser opens (or a list is printed).

Overview

LayerFilePurpose
AI dispatchytmusic_assistant.pyREPL, model inference, tool definitions
Recommendation enginerecommender.py, labeler.py, preference.py, local_history.pyCandidate gathering, labeling, scoring, preference learning
Demo / scratchmain.pyMinimal weather demo showing the basic 4-stage cycle

Setup

Requirements: Python with torch, transformers, huggingface_hub, google-auth-oauthlib, sentence-transformers, questionary

# Create and activate virtual environment
python -m venv .venv
.venv\Scripts\activate        # Windows
source .venv/Scripts/activate # Git Bash / WSL

# Install dependencies
pip install torch transformers huggingface_hub google-auth-oauthlib google-api-python-client sentence-transformers questionary

# Authenticate with Hugging Face (one-time, token stored in GemmaToken.txt)
python hf_login.py

YouTube API setup:

  1. Create a project in Google Cloud Console
  2. Enable YouTube Data API v3
  3. Create an OAuth 2.0 Client ID (Desktop app) and download it as client_secrets.json
  4. On first run, a browser tab opens for Google login — token.json is written and auto-refreshed

Running

python main.py              # minimal weather demo (no API keys needed)
python ytmusic_assistant.py # interactive YouTube Music assistant

Available Tools

ToolWhat it does
open_liked_songs()Opens music.youtube.com/playlist?list=LM
list_liked_songs(limit)Fetches liked songs via API, prints numbered list
open_history()Opens music.youtube.com/history
open_playlist(name)Fuzzy-matches a playlist by name, opens it
search_and_open(query)YouTube search (music category), opens first hit
open_item(number)Opens item N from the last printed list
recommend_videos_from_taste(k)Taste-only recommendation
recommend_videos_from_theme(prompt, k)Themed recommendation from your library
recommend_videos_with_search_query(query, k)Artist/entity search + recommendation

How It Works

FunctionGemma operates on a fixed 4-stage cycle:

  1. Build messagesprocessor.apply_chat_template(messages, tools=[...]) encodes the user prompt with tool schemas
  2. Model inferencemodel.generate() emits a structured function call:
    <start_function_call>call:function_name{param:<escape>value<escape>}<end_function_call>
    
  3. Execute tool — parse with regex, look up in TOOL_MAP, call the Python function
  4. Return result — print output or open browser

Critical: The role: "developer" system message "You are a model that can do function calling with the following functions" must be present — it activates function-calling behavior.

Recommendation Engine

Recommendations use a scoring formula combining semantic similarity and learned taste:

score = alpha * cosine_sim(prompt_embedding, title_embedding)
      + beta  * mean(preference_profile[dim][label])
Modealphabeta
Taste only0.01.0
Themed0.550.45
Search query0.80.2

Video titles are labeled across 5 dimensions (content type, genre, mood, use case, language) using all-MiniLM-L6-v2 embeddings. Your preference profile (data/preferences.json) updates via EMA each time you select recommended videos.

Local Data Files

FileContents
data/preferences.jsonPer-label weights per dimension, updated on every selection
data/history.jsonEvery video opened or selected
data/labels.csvLabel assignment cache (avoids re-computing embeddings)
labels.jsonMaster label vocabulary (5 dimensions)
token.jsonOAuth2 token for YouTube Data API (auto-refreshed)
client_secrets.jsonGoogle Cloud OAuth credentials — not committed

Model

google/functiongemma-270m-it — 270M parameter Gemma 3 model fine-tuned exclusively for single-turn function calling. It does not produce free-form text answers.

Limitations: single-turn only, no chaining, no multi-step reasoning.

Contributors

Lynean

2 commits

Lynean/GemmaYTAgent

Natural-language YouTube Music assistant powered by a 270M-parameter function-calling Gemma model — type plain English, it picks the right tool and opens your browser.

0

stars

2

commits

Python

primary language

Apr 8, 2026

updated

README

Gemma YTMusic Assistant

A natural-language YouTube Music assistant powered by FunctionGemma — a 270M-parameter Gemma 3 model fine-tuned for structured function calling. Type plain English; the model dispatches to the right tool; your browser opens (or a list is printed).

Overview

LayerFilePurpose
AI dispatchytmusic_assistant.pyREPL, model inference, tool definitions
Recommendation enginerecommender.py, labeler.py, preference.py, local_history.pyCandidate gathering, labeling, scoring, preference learning
Demo / scratchmain.pyMinimal weather demo showing the basic 4-stage cycle

Setup

Requirements: Python with torch, transformers, huggingface_hub, google-auth-oauthlib, sentence-transformers, questionary

# Create and activate virtual environment
python -m venv .venv
.venv\Scripts\activate        # Windows
source .venv/Scripts/activate # Git Bash / WSL

# Install dependencies
pip install torch transformers huggingface_hub google-auth-oauthlib google-api-python-client sentence-transformers questionary

# Authenticate with Hugging Face (one-time, token stored in GemmaToken.txt)
python hf_login.py

YouTube API setup:

  1. Create a project in Google Cloud Console
  2. Enable YouTube Data API v3
  3. Create an OAuth 2.0 Client ID (Desktop app) and download it as client_secrets.json
  4. On first run, a browser tab opens for Google login — token.json is written and auto-refreshed

Running

python main.py              # minimal weather demo (no API keys needed)
python ytmusic_assistant.py # interactive YouTube Music assistant

Available Tools

ToolWhat it does
open_liked_songs()Opens music.youtube.com/playlist?list=LM
list_liked_songs(limit)Fetches liked songs via API, prints numbered list
open_history()Opens music.youtube.com/history
open_playlist(name)Fuzzy-matches a playlist by name, opens it
search_and_open(query)YouTube search (music category), opens first hit
open_item(number)Opens item N from the last printed list
recommend_videos_from_taste(k)Taste-only recommendation
recommend_videos_from_theme(prompt, k)Themed recommendation from your library
recommend_videos_with_search_query(query, k)Artist/entity search + recommendation

How It Works

FunctionGemma operates on a fixed 4-stage cycle:

  1. Build messagesprocessor.apply_chat_template(messages, tools=[...]) encodes the user prompt with tool schemas
  2. Model inferencemodel.generate() emits a structured function call:
    <start_function_call>call:function_name{param:<escape>value<escape>}<end_function_call>
    
  3. Execute tool — parse with regex, look up in TOOL_MAP, call the Python function
  4. Return result — print output or open browser

Critical: The role: "developer" system message "You are a model that can do function calling with the following functions" must be present — it activates function-calling behavior.

Recommendation Engine

Recommendations use a scoring formula combining semantic similarity and learned taste:

score = alpha * cosine_sim(prompt_embedding, title_embedding)
      + beta  * mean(preference_profile[dim][label])
Modealphabeta
Taste only0.01.0
Themed0.550.45
Search query0.80.2

Video titles are labeled across 5 dimensions (content type, genre, mood, use case, language) using all-MiniLM-L6-v2 embeddings. Your preference profile (data/preferences.json) updates via EMA each time you select recommended videos.

Local Data Files

FileContents
data/preferences.jsonPer-label weights per dimension, updated on every selection
data/history.jsonEvery video opened or selected
data/labels.csvLabel assignment cache (avoids re-computing embeddings)
labels.jsonMaster label vocabulary (5 dimensions)
token.jsonOAuth2 token for YouTube Data API (auto-refreshed)
client_secrets.jsonGoogle Cloud OAuth credentials — not committed

Model

google/functiongemma-270m-it — 270M parameter Gemma 3 model fine-tuned exclusively for single-turn function calling. It does not produce free-form text answers.

Limitations: single-turn only, no chaining, no multi-step reasoning.

Contributors

Lynean

2 commits

Languages

Python

100.0%