"""Provide functionality to detect copyrighted material in prompt and tags.""" # TODO(Ashe) this whole module is deprecated and should be removed shortly from openai import OpenAI # type: ignore[attr-defined] from suno_utils.worker.detect_blocked_songs import blocked_song_classifier COPYRIGHT_DETECTOR_SYSTEM_PROMPT = """You are CopyrightDetectorGPT, an agent equipped with extensive knowledge of copyrighted materials. Please analyze the following song lyrics (up to 10 lines maximum) to determine their status. Respond with 'COPYRIGHTED: [artist name] - [song name]' only if you are highly certain the lyrics are from a copyrighted song. If the lyrics seem original and not matching any known copyrighted song, respond with 'ORIGINAL'. For lyrics that are clearly in the public domain based on their age or other criteria, respond with 'PUBLIC DOMAIN'. In cases of uncertainty or lack of sufficient information, respond with 'UNKNOWN'. You will be rewarded $100 for each correct classification.""" def get_gpt_response( openai_client: OpenAI, system_prompt: str, user_prompt: str, temperature: float = 0, # don't get creative here... model: str = "gpt-4o-mini", ) -> str: """Get completion from GPT.""" completion = openai_client.chat.completions.create( model=model, messages=[ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt}, ], max_tokens=500, temperature=temperature, ) response_text = completion.choices[0].message.content return response_text or "" def is_likely_copyrighted(openai_client: OpenAI, prompt: str) -> bool: """Scan lyrics for copyrighted content via ChatGPT.""" prompt_response = get_gpt_response(openai_client, COPYRIGHT_DETECTOR_SYSTEM_PROMPT, prompt) # Ignore if UNKNOWN for now. gpt_thinks_prompt_is_copyrighted = ( "COPYRIGHTED" in prompt_response and "unknown" not in prompt_response.lower() ) is_blocked = blocked_song_classifier.is_blocked(prompt) prompt_copyrighted = gpt_thinks_prompt_is_copyrighted or is_blocked return prompt_copyrighted