-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintent_classifier.py
More file actions
60 lines (50 loc) · 2.53 KB
/
Copy pathintent_classifier.py
File metadata and controls
60 lines (50 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import ollama
# Step 1: Define the refined prompt template
INTENT_PROMPT = """
You are an intent classifier for a YouTube content copilot.
Return EXACTLY ONE label from this set (no extra words, no punctuation):
get_recommendation | facts_check | comments_summary | summarize_video | rank_ideas | add_to_notion | none
GATING RULE:
- If the message is NOT clearly about a YouTube video, YouTube channel, a YouTube link, or the user’s ideas for their NEXT VIDEO, return: none.
INTENT DEFINITIONS (use the first that matches):
- get_recommendation → User asks for videos/topics/channels to watch or make, or “which should I do next?” based on trends/subscriptions/ideas list.
- facts_check → User asks to verify truth/accuracy/claims of a specific video or idea.
- comments_summary → User wants a summary of comments or “what are people saying?” on a video.
- summarize_video → User wants a summary/tl;dr/recap/outline of a specific video.
- rank_ideas → User wants to prioritize/sort/pick the best from their VIDEO IDEAS list.
- add_to_notion → User wants toUser wants to save/log an idea to Notion.
ANTI-TRIGGERS:
- Greetings, small talk, unrelated questions → none.
- If ambiguous or missing video/YouTube/next-video-idea context → none.
EXAMPLES:
Q: “hi there” → none
Q: “Summarize this https://youtu.be/abc123” → summarize_video
Q: “What are people saying under this video? https://youtube.com/watch?v=xyz” → comments_summary
Q: “Can you fact check this video’s claims?” → facts_check
Q: “I have three ideas for my next YouTube video, which should I do first?” → rank_ideas
Q: “Recommend trending topics from my subscriptions” → get_recommendation
Q: “Add this idea to Notion: ‘How to edit faster in CapCut’” → add_to_notion
Q: “What’s your name?” → none
User message: "{MESSAGE}"
Return ONLY one of:
get_recommendation | facts_check | comments_summary | summarize_video | rank_ideas | add_to_notion | none
"""
# Step 2: Intent classifier function
def classify_intent(message: str) -> str:
prompt = INTENT_PROMPT.replace("{MESSAGE}", message)
resp = ollama.chat(
model="qwen2.5:3b",
messages=[{"role": "user", "content": prompt}],
options={"temperature": 0.1, "top_p": 0.9}
)
label = resp["message"]["content"].strip()
valid = {
"get_recommendation",
"facts_check",
"comments_summary",
"summarize_video",
"rank_ideas",
"add_to_notion",
"none",
}
return label if label in valid else "none"