fix(music-lab): market API 타입 강화·ANTHROPIC_API_KEY call-time·HTTP 레이어 테스트 추가

This commit is contained in:
2026-05-01 12:32:24 +09:00
parent 26b9eea0dc
commit 355667cf9c
3 changed files with 69 additions and 8 deletions

View File

@@ -8,8 +8,6 @@ from .db import (
insert_market_trends, upsert_trend_report,
)
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY", "")
GENRE_PROMPTS: Dict[str, str] = {
"lo-fi": "lo-fi hip hop, chill, relaxing beats, study music, 85 BPM, jazzy chords",
"phonk": "dark phonk, aggressive 808 bass, Memphis trap, distorted synths, 140 BPM",
@@ -71,14 +69,15 @@ def _build_report(trends: List[Dict[str, Any]], report_date: str) -> Dict[str, A
def _generate_insights(top_genres: list, top_keywords: list) -> str:
api_key = os.getenv("ANTHROPIC_API_KEY", "")
if not top_genres:
return "아직 수집된 트렌드 데이터가 없습니다."
if not ANTHROPIC_API_KEY:
if not api_key:
names = ", ".join(g["genre"] for g in top_genres[:3])
return f"이번 주 인기 장르: {names}. 해당 장르 중심 제작을 추천합니다."
import anthropic
client = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)
client = anthropic.Anthropic(api_key=api_key)
genre_str = ", ".join(f"{g['genre']}({g['score']:.1f})" for g in top_genres[:5])
kw_str = ", ".join(top_keywords[:10])
try: