defdeepseek_match(original_text: str, cand: Dict[str, Any], anime_names: List[str]) -> bool: api_key = os.environ.get('DEEPSEEK') ifnot api_key: returnFalse model = 'deepseek-chat' system = 'You are a strict music matcher. Return JSON {"is_same": true|false} only.' cand_title = cand.get('name') or'' cand_artists = ', '.join(cand.get('artists') or []) cand_alias = cand.get('alias') or [] prompt = ( 'Determine if the candidate song matches the intended song described by the original text. ' 'In original text, the song name is inside the parentheses, and the artist name is outside.' 'Consider candidate song name and artists, they must both match.' 'Some artists\' names may be converted to Roman sounds, but they are essentially the same person.' 'Additionally, also consider candidate aliases; ' 'if alias contains anime Chinese names or Japanese names, treat as match. Return strictly JSON with key is_same.\n' f'Original text: {original_text}\n' f'Anime names (CN/JP): {json.dumps([n for n in anime_names if n], ensure_ascii=False)}\n' f'Candidate title: {cand_title}\n' f'Candidate artist: {cand_artists}\n' f'Candidate aliases: {json.dumps(cand_alias, ensure_ascii=False)}\n' ) try: r = requests.post( 'https://api.deepseek.com/v1/chat/completions', headers={ 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json' }, json={ 'model': model, 'messages': [ {'role': 'system', 'content': system}, {'role': 'user', 'content': prompt} ], 'temperature': 0 }, timeout=30 ) r.raise_for_status() data = r.json() content = data.get('choices', [{}])[0].get('message', {}).get('content', '') try: parsed = json.loads(content) print(f"deepseek_answer: {parsed}") return bool(parsed.get('is_same')) except Exception: returnFalse except Exception: returnFalse