diff --git a/README.md b/README.md index 8003bdd..c670a57 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ Hey there! Meet MySpotiPal - your AI-powered music buddy that knows your Spotify ## What Can MySpotiPal Do? 🌟 +## Playlist Generation πŸš€ +``` +"Can you create a playlist of bunker techno?" +"Help me generate a playlist that sounds like chilling by a beach lounge" +"Create a playlist called '80s Rock' and add some hair metal classics from the 80s" +``` +Automatically create playlists in your Spotify account + ### Check Your Music Taste 🎧 ``` "Who are my top artists this month?" @@ -26,7 +34,6 @@ MySpotiPal analyzes your listening habits across different timeframes (4 weeks, ``` "Who do I follow on Spotify?" "Show me my playlists" -"What did I listen to recently?" "What podcasts have I saved?" ``` Keep track of your followed artists, playlists, and recent plays @@ -46,11 +53,6 @@ Get both general info and Spotify stats for any artist! "What should I listen to if I like indie rock?" ``` -## Coming Soon πŸš€ -- AI-powered playlist creation from text prompts -- Direct playlist saving to your Spotify -- Enhanced recommendation system - ## Technical Setup πŸ› οΈ ### You'll Need: diff --git a/llm_client.py b/llm_client.py index 504737d..e316dbc 100644 --- a/llm_client.py +++ b/llm_client.py @@ -40,23 +40,30 @@ def process_query(self, query: str, spotify_data: Dict, access_token: str, sessi logger.info(f"Lengh of messages: {len(messages)}") # Initial OpenAI API call - assistant_message = self._initial_openai_call(messages) - + current_messages = messages.copy() response = "" - if assistant_message.tool_calls: - # Only make final call if tools were used - messages = self._handle_tool_calls(assistant_message.tool_calls, access_token, messages) + + while True: + assistant_message = self._initial_openai_call(current_messages) - for chunk in self._final_openai_call(messages): - response += chunk - yield chunk - else: - # If no tools were used, just use the initial response - response = assistant_message.content - yield response + # Add any assistant message content to the conversation + if assistant_message.content: + current_messages.append({"role": "assistant", "content": assistant_message.content}) + for chunk in assistant_message.content: + response += chunk + yield chunk + + # If no more tool calls, we're done + if not assistant_message.tool_calls: + break + + # Handle tool calls and continue the conversation + current_messages = self._handle_tool_calls(assistant_message.tool_calls, access_token, current_messages) + # Update chat history messages.append({"role": "assistant", "content": response}) self.chat_history[session_id] = messages + @task(name="build_messages") def _build_messages(self, session_id: str, query: str) -> List[Dict[str, str]]: @@ -66,29 +73,51 @@ def _build_messages(self, session_id: str, query: str) -> List[Dict[str, str]]: if not self.chat_history[session_id]: messages.append({ "role": "system", - "content": """You are MySpotiPal, an AI-powered Spotify assistant with real-time access to users' Spotify data. You combine music expertise with data-driven insights while maintaining a friendly, professional demeanor. + "content": """ +You are MySpotiPal, an AI-powered Spotify assistant with real-time access to users' Spotify data. Your role is to provide expert music recommendations, insightful data analysis, and seamless playlist management while maintaining a friendly, professional, and engaging communication style. + +# Core Functions +1. Song Recommendations: + - Respond to requests for song or artist recommendations without automatically creating a playlist. + - Curate suggestions based on user input, listening history, and musical patterns. + +2. Playlist Creation: + Follow these steps: + a. Curate song recommendations based on user input. + b. Use 'search_item' to find the exact track IDs for each recommended song. If a song is unavailable, replace it with an alternative and explain your reasoning + c. Create a new playlist using 'create_playlist' + d. Add all identified tracks to the playlist using 'add_songs_to_playlist' + e. Share the playlist URL along with a summary of the theme and reasoning behind your recommendations + - IMPORTANT: DO NOT end your response until you have completed ALL these steps. Keep user posted of progress -You are an accurate music recommender that can generate playlists for users. First you will curate the song recommendations based on user input. Then you will display the list of songs added and explain the rationale behind the recommendations. You will also ask for user confirmation to add these items to a playlist. Then you will create the playlist while adding the recommended tracks to the playlist using both create_playlist and add_songs_to_playlist functions and then share the playlist URL with the user. +3. User Insights & Analysis: + - Provide meaningful patterns and trends in the user’s library and listening behavior. -Core Functions: -- Comprehensive search across tracks, albums, artists, playlists, and audio content -- Access to user's library and listening history -- Analysis of user preferences and patterns -- Custom playlist creation and management +4. Comprehensive Search Capabilities: + - Search for tracks, albums, artists, playlists, audiobooks, and podcasts while providing relevant details (e.g., follower counts, genres, and release dates). -Communication Style: -- Strategic use of music-related emojis (🎡, 🎧, 🎸) -- Data-informed insights and recommendations -- Clear explanation of musical choices -- Concise yet affirmative responses +# Communication Style +- Friendly, conversational, and engaging. +- Use strategic, music-related emojis (🎡, 🎧, 🎸) to enhance the user experience. +- Provide data-informed insights with concise but detailed reasoning. +- Balance familiar recommendations with opportunities for musical discovery. -Response Guidelines: -- Search Results: Include key metrics and relevant details -- Library Analysis: Surface meaningful patterns and trends -- Recommendations: Balance familiar choices with discovery options -- Content Information: Provide context through relevant statistics +# Response Guidelines +1. Recommendations: + - Explain your song suggestions clearly, highlighting why they align with the user’s preferences. +2. Search Results: + - Prioritize Spotify-provided information and include key metrics, such as genre, release year, and artist popularity. + - Supplement with external knowledge if Spotify data is insufficient. +3. Incomplete Data: + - Acknowledge any limitations (e.g., unavailable tracks) and offer alternative solutions. +4. Playlist Creation: + - Begin playlist generation if user asks to create/generate a playlist -When faced with incomplete data or access limitations, acknowledge constraints and offer alternative solutions.""" +# Playlist Generation Reminder +- Never assume a user wants a playlist when asking for recommendations +- If a user asks to create a playlist, proceed with all the playlist generation steps +- If the user only wants song recommendations, stop after providing suggestions +""" }) # Add existing chat history messages.extend(self.chat_history[session_id]) diff --git a/templates/chat.html b/templates/chat.html index d9eab59..5426b72 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -21,7 +21,8 @@

MySpotiPal Chat

Who are my top artists of all time?

-

What's my top track recently?

+

What's my most played track?

+

Generate a playlist for a disco party