Skip to content

Implement AI Playlist Generator for Playlist Recomendations (api/ai-playlist) #70

@tran2106

Description

@tran2106

- Create a POST endpoint at /auth/spotify/ai-playlist to receive user prompts from the frontend.

2. Prompt Validation

  • Validate the incoming prompt:
    • If prompt is too short or not music-related (eexample "hi"), return a friendly message suggesting the user send a mood, genre, or vibe.

3. Gemini AI Integration

  • Send valid prompts to Gemini AI.
  • Parse Gemini’s response to extract a JSON list of { song, artist } pairs.

4. Output Validation

  • Validate Gemini’s output:
    • If output is invalid or empty, return a fallback message to the frontend.

5. Spotify Track Search

  • For each { song, artist } from Gemini, search Spotify’s API for matching track IDs.
  • Collect valid Spotify track URIs.

6. Playlist Creation

  • Use the authenticated user’s Spotify token to create a new playlist named AI Playlist: [prompt].
  • Add the collected tracks to the playlist via Spotify API.

7. Response Handling

  • If playlist creation is successful, return { playlistUrl: "https://open.spotify.com/playlist/..." }.
  • If prompt is invalid or playlist creation fails, return { message: "Send a mood, genre, or vibe and I can make a playlist for you." }.

8. Error Handling & Logging

  • Log errors at each step for debugging.
  • Return appropriate error messages to the frontend.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions