Make Bandcamp mode opt-in toggle on Discover page
This commit is contained in:
@@ -22,7 +22,7 @@ async def generate(
|
||||
raise HTTPException(status_code=400, detail="Provide a playlist_id or query")
|
||||
|
||||
recs, remaining = await generate_recommendations(
|
||||
db, user, playlist_id=data.playlist_id, query=data.query
|
||||
db, user, playlist_id=data.playlist_id, query=data.query, bandcamp_mode=data.bandcamp_mode
|
||||
)
|
||||
|
||||
if not recs and remaining == 0:
|
||||
|
||||
@@ -6,6 +6,7 @@ from pydantic import BaseModel
|
||||
class RecommendationRequest(BaseModel):
|
||||
playlist_id: int | None = None
|
||||
query: str | None = None # Manual search/request
|
||||
bandcamp_mode: bool = False # Prioritize Bandcamp/indie artists
|
||||
|
||||
|
||||
class RecommendationItem(BaseModel):
|
||||
|
||||
@@ -67,6 +67,7 @@ async def generate_recommendations(
|
||||
user: User,
|
||||
playlist_id: int | None = None,
|
||||
query: str | None = None,
|
||||
bandcamp_mode: bool = False,
|
||||
) -> tuple[list[Recommendation], int | None]:
|
||||
"""Generate AI music recommendations using Claude."""
|
||||
|
||||
@@ -113,6 +114,11 @@ async def generate_recommendations(
|
||||
# Build prompt
|
||||
user_request = query or "Find me music I'll love based on my taste profile. Prioritize lesser-known artists and hidden gems."
|
||||
|
||||
if bandcamp_mode:
|
||||
focus_instruction = "IMPORTANT: Strongly prioritize independent and underground artists who release music on Bandcamp. Think DIY, indie labels, self-released artists, and the kind of music you'd find crate-digging on Bandcamp. Focus on artists who self-publish or release on small indie labels."
|
||||
else:
|
||||
focus_instruction = "Focus on discovery - prioritize lesser-known artists, deep cuts, and hidden gems over obvious popular choices."
|
||||
|
||||
prompt = f"""You are Vynl, an AI music discovery assistant. You help people discover new music they'll love.
|
||||
|
||||
{taste_context}
|
||||
@@ -129,7 +135,7 @@ Respond with exactly 5 music recommendations as a JSON array. Each item should h
|
||||
- "reason": A warm, personal 2-3 sentence explanation of WHY they'll love this track. Reference specific qualities from their taste profile. Be specific about sonic qualities, not generic.
|
||||
- "score": confidence score 0.0-1.0
|
||||
|
||||
IMPORTANT: Strongly prioritize independent and underground artists who release music on Bandcamp. Think DIY, indie labels, self-released artists, and the kind of music you'd find crate-digging on Bandcamp. Mix in some Bandcamp-type artists alongside any well-known recommendations. Focus on real discovery — lesser-known artists, deep cuts, and hidden gems over obvious popular choices.
|
||||
{focus_instruction}
|
||||
Return ONLY the JSON array, no other text."""
|
||||
|
||||
# Call Claude API
|
||||
@@ -152,13 +158,14 @@ Return ONLY the JSON array, no other text."""
|
||||
except json.JSONDecodeError:
|
||||
return [], remaining
|
||||
|
||||
# Search Bandcamp for each recommendation to attach real links
|
||||
# Search Bandcamp for each recommendation if bandcamp mode is on
|
||||
from app.services.bandcamp import search_bandcamp
|
||||
|
||||
# Save to DB
|
||||
recommendations = []
|
||||
for rec in recs_data[:5]:
|
||||
bandcamp_url = None
|
||||
if bandcamp_mode:
|
||||
try:
|
||||
results = await search_bandcamp(
|
||||
f"{rec.get('artist', '')} {rec.get('title', '')}", item_type="t"
|
||||
|
||||
@@ -142,10 +142,11 @@ export const importSpotifyPlaylist = (playlistId: string) =>
|
||||
api.post<PlaylistDetailResponse>('/spotify/import', { playlist_id: playlistId }).then((r) => r.data)
|
||||
|
||||
// Recommendations
|
||||
export const generateRecommendations = (playlistId?: string, query?: string) =>
|
||||
export const generateRecommendations = (playlistId?: string, query?: string, bandcampMode?: boolean) =>
|
||||
api.post<RecommendationResponse>('/recommendations/generate', {
|
||||
playlist_id: playlistId,
|
||||
query,
|
||||
bandcamp_mode: bandcampMode || false,
|
||||
}).then((r) => r.data)
|
||||
|
||||
export const getRecommendationHistory = () =>
|
||||
|
||||
@@ -16,6 +16,7 @@ export default function Discover() {
|
||||
const [discovering, setDiscovering] = useState(false)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState('')
|
||||
const [bandcampMode, setBandcampMode] = useState(false)
|
||||
const [savingIds, setSavingIds] = useState<Set<string>>(new Set())
|
||||
|
||||
useEffect(() => {
|
||||
@@ -45,7 +46,8 @@ export default function Discover() {
|
||||
try {
|
||||
const response = await generateRecommendations(
|
||||
selectedPlaylist || undefined,
|
||||
query.trim() || undefined
|
||||
query.trim() || undefined,
|
||||
bandcampMode
|
||||
)
|
||||
setResults(response.recommendations)
|
||||
setRemaining(response.remaining_today)
|
||||
@@ -133,6 +135,27 @@ export default function Discover() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Bandcamp Mode Toggle */}
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setBandcampMode(!bandcampMode)}
|
||||
className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors cursor-pointer border-none ${
|
||||
bandcampMode ? 'bg-purple' : 'bg-charcoal-muted/30'
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${
|
||||
bandcampMode ? 'translate-x-6' : 'translate-x-1'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
<span className="text-sm text-charcoal">
|
||||
Bandcamp mode
|
||||
<span className="text-charcoal-muted ml-1">— prioritize indie & underground artists</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Remaining count */}
|
||||
{!user?.is_pro && (
|
||||
<p className="text-xs text-charcoal-muted flex items-center gap-1">
|
||||
|
||||
Reference in New Issue
Block a user