lyric, song finished
This commit is contained in:
1 parent
4ad6be7504
commit
dd855ff11a
11 files changed
+701
-10
No files matched your search
@@ -40,12 +40,13 @@ Deliver outputs optimized for three formats:1 minute. Ensure that each version a
|
||||
|
||||
LYRICS_PROMPT_TEMPLATE = """
|
||||
[ROLE]
|
||||
Content marketing expert specializing in pension/accommodation services in Korea
|
||||
Content marketing expert and creative songwriter specializing in pension/accommodation services
|
||||
|
||||
[INPUT]
|
||||
- Business Name: {customer_name}
|
||||
- Region: {region}
|
||||
- Region Details: {detail_region_info}
|
||||
- Output Language: {language}
|
||||
|
||||
[INTERNAL ANALYSIS - DO NOT OUTPUT]
|
||||
Analyze the following internally to inform lyrics creation:
|
||||
@@ -53,24 +54,59 @@ Analyze the following internally to inform lyrics creation:
|
||||
- Unique Selling Propositions (USPs)
|
||||
- Regional characteristics and nearby attractions (within 10 min access)
|
||||
- Seasonal appeal points
|
||||
- Emotional triggers for the target audience
|
||||
|
||||
[LYRICS REQUIREMENTS]
|
||||
- Must include: business name, region name, main target audience, nearby famous places
|
||||
- Keywords to incorporate: 인스타 감성, 사진같은 하루, 힐링, 여행
|
||||
- Length: For 1-minute video (approximately 8-12 lines)
|
||||
- Tone: Emotional, trendy, viral-friendly
|
||||
1. Must Include Elements:
|
||||
- Business name (TRANSLATED or TRANSLITERATED to {language})
|
||||
- Region name (TRANSLATED or TRANSLITERATED to {language})
|
||||
- Main target audience appeal
|
||||
- Nearby famous places or regional characteristics
|
||||
|
||||
2. Keywords to Incorporate (use language-appropriate trendy expressions):
|
||||
- Korean: 인스타 감성, 사진같은 하루, 힐링, 여행, 감성 숙소
|
||||
- English: Instagram vibes, picture-perfect day, healing, travel, getaway
|
||||
- Chinese: 网红打卡, 治愈系, 旅行, 度假, 拍照圣地
|
||||
- Japanese: インスタ映え, 写真のような一日, 癒し, 旅行, 絶景
|
||||
- Thai: ที่พักสวย, ฮีลใจ, เที่ยว, ถ่ายรูป, วิวสวย
|
||||
- Vietnamese: check-in đẹp, healing, du lịch, nghỉ dưỡng, view đẹp
|
||||
|
||||
3. Structure:
|
||||
- Length: For 1-minute video (approximately 8-12 lines)
|
||||
- Flow: Verse structure suitable for music
|
||||
- Rhythm: Natural speech rhythm in the specified language
|
||||
|
||||
4. Tone:
|
||||
- Emotional and heartfelt
|
||||
- Trendy and viral-friendly
|
||||
- Relatable to target audience
|
||||
|
||||
[CRITICAL LANGUAGE REQUIREMENT - ABSOLUTE RULE]
|
||||
ALL OUTPUT MUST BE 100% WRITTEN IN {language} - NO EXCEPTIONS
|
||||
- ALL lyrics content: {language} ONLY
|
||||
- ALL proper nouns (business names, region names, place names): MUST be translated or transliterated to {language}
|
||||
- Korean input like "군산" must become "Gunsan" in English, "群山" in Chinese, "グンサン" in Japanese, etc.
|
||||
- Korean input like "스테이 머뭄" must become "Stay Meoum" in English, "住留" in Chinese, "ステイモーム" in Japanese, etc.
|
||||
- ZERO Korean characters (한글) allowed when output language is NOT Korean
|
||||
- ZERO mixing of languages - the entire output must be monolingual in {language}
|
||||
- This is a NON-NEGOTIABLE requirement
|
||||
- Any output containing characters from other languages is considered a COMPLETE FAILURE
|
||||
- Violation of this rule invalidates the entire response
|
||||
|
||||
[OUTPUT RULES - STRICTLY ENFORCED]
|
||||
- Output lyrics ONLY
|
||||
- Lyrics MUST be written in Korean (한국어)
|
||||
- Lyrics MUST be written ENTIRELY in {language} - NO EXCEPTIONS
|
||||
- ALL names and places MUST be in {language} script/alphabet
|
||||
- NO Korean (한글), Chinese (漢字), Japanese (仮名), Thai (ไทย), or Vietnamese (Tiếng Việt) characters unless that is the selected output language
|
||||
- NO titles, descriptions, analysis, or explanations
|
||||
- NO greetings or closing remarks
|
||||
- NO additional commentary before or after lyrics
|
||||
- NO line numbers or labels
|
||||
- Follow the exact format below
|
||||
|
||||
[OUTPUT FORMAT - SUCCESS]
|
||||
---
|
||||
[Lyrics in Korean here]
|
||||
[Lyrics ENTIRELY in {language} here - no other language characters allowed]
|
||||
---
|
||||
|
||||
[OUTPUT FORMAT - FAILURE]
|
||||
@@ -181,6 +217,7 @@ class ChatgptService:
|
||||
customer_name: str,
|
||||
region: str,
|
||||
detail_region_info: str = "",
|
||||
language: str = "Korean",
|
||||
):
|
||||
# 최신 모델: GPT-5, GPT-5 mini, GPT-5 nano, GPT-4.1, GPT-4.1 mini, GPT-4.1 nano
|
||||
# 이전 세대: GPT-4o, GPT-4o mini, GPT-4 Turbo, GPT-3.5 Turbo
|
||||
@@ -189,6 +226,7 @@ class ChatgptService:
|
||||
self.customer_name = customer_name
|
||||
self.region = region
|
||||
self.detail_region_info = detail_region_info
|
||||
self.language = language
|
||||
|
||||
def build_lyrics_prompt(self) -> str:
|
||||
"""LYRICS_PROMPT_TEMPLATE에 고객 정보를 대입하여 완성된 프롬프트 반환"""
|
||||
@@ -196,6 +234,7 @@ class ChatgptService:
|
||||
customer_name=self.customer_name,
|
||||
region=self.region,
|
||||
detail_region_info=self.detail_region_info,
|
||||
language=self.language,
|
||||
)
|
||||
|
||||
def build_market_analysis_prompt(self) -> str:
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
"""
|
||||
Suno API 클라이언트 모듈
|
||||
|
||||
API 문서: https://docs.sunoapi.org
|
||||
|
||||
## 사용법
|
||||
```python
|
||||
from app.utils.suno import SunoService
|
||||
|
||||
# config에서 자동으로 API 키를 가져옴
|
||||
suno = SunoService()
|
||||
|
||||
# 또는 명시적으로 API 키 전달
|
||||
suno = SunoService(api_key="your_api_key")
|
||||
|
||||
# 음악 생성 요청
|
||||
task_id = await suno.generate(
|
||||
prompt="[Verse]\\n오늘도 좋은 하루...",
|
||||
style="K-Pop, Happy, 110 BPM",
|
||||
title="좋은 하루"
|
||||
)
|
||||
|
||||
# 상태 확인 (폴링 방식)
|
||||
result = await suno.get_task_status(task_id)
|
||||
```
|
||||
|
||||
## 콜백 URL 사용법
|
||||
generate() 호출 시 callback_url 파라미터를 전달하면 생성 완료 시 해당 URL로 POST 요청이 전송됩니다.
|
||||
콜백 요청 형식:
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "All generated successfully.",
|
||||
"data": {
|
||||
"callbackType": "complete",
|
||||
"task_id": "작업ID",
|
||||
"data": [
|
||||
{
|
||||
"id": "clip_id",
|
||||
"audio_url": "https://...",
|
||||
"image_url": "https://...",
|
||||
"title": "곡 제목",
|
||||
"status": "complete"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
콜백 주의사항:
|
||||
- HTTPS 프로토콜 권장
|
||||
- 15초 내 응답 필수
|
||||
- 동일 task_id에 대해 여러 콜백 수신 가능 (멱등성 처리 필요)
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
from config import apikey_settings
|
||||
|
||||
|
||||
class SunoService:
|
||||
"""Suno API를 통한 AI 음악 생성 서비스"""
|
||||
|
||||
BASE_URL = "https://api.sunoapi.org/api/v1"
|
||||
|
||||
def __init__(self, api_key: str | None = None):
|
||||
"""
|
||||
Args:
|
||||
api_key: Suno API 키 (Bearer token으로 사용)
|
||||
None일 경우 config에서 자동으로 가져옴
|
||||
"""
|
||||
self.api_key = api_key or apikey_settings.SUNO_API_KEY
|
||||
self.headers = {
|
||||
"Authorization": f"Bearer {self.api_key}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
async def generate(
|
||||
self,
|
||||
prompt: str,
|
||||
genre: str | None = None,
|
||||
callback_url: str | None = None,
|
||||
) -> str:
|
||||
"""
|
||||
음악 생성 요청
|
||||
|
||||
Args:
|
||||
prompt: 가사 (customMode=true일 때 가사로 사용)
|
||||
1분 이내 길이의 노래에 적합한 가사여야 함
|
||||
genre: 음악 장르 (예: "K-Pop", "Pop", "R&B", "Hip-Hop", "Ballad", "EDM")
|
||||
None일 경우 style 파라미터를 전송하지 않음
|
||||
callback_url: 생성 완료 시 알림 받을 URL (None일 경우 config에서 기본값 사용)
|
||||
|
||||
Returns:
|
||||
task_id: 작업 추적용 ID
|
||||
|
||||
Note:
|
||||
- 스트림 URL: 30-40초 내 생성
|
||||
- 다운로드 URL: 2-3분 내 생성
|
||||
- 생성되는 노래는 약 1분 이내의 길이
|
||||
"""
|
||||
# 1분 이내 노래 생성을 위한 프롬프트 조건 추가
|
||||
formatted_prompt = f"[Short Song - Under 1 minute]\n{prompt}"
|
||||
|
||||
# callback_url이 없으면 config에서 기본값 사용 (Suno API 필수 파라미터)
|
||||
actual_callback_url = callback_url or apikey_settings.SUNO_CALLBACK_URL
|
||||
|
||||
payload: dict[str, Any] = {
|
||||
"model": "V5",
|
||||
"customMode": True,
|
||||
"instrumental": False,
|
||||
"prompt": formatted_prompt,
|
||||
"callBackUrl": actual_callback_url,
|
||||
}
|
||||
|
||||
# genre가 있을 때만 style 추가
|
||||
if genre:
|
||||
payload["style"] = genre
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(
|
||||
f"{self.BASE_URL}/generate",
|
||||
headers=self.headers,
|
||||
json=payload,
|
||||
timeout=30.0,
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
# 응답: {"code": 200, "msg": "success", "data": {"taskId": "..."}}
|
||||
# API 응답 검증
|
||||
if data is None:
|
||||
raise ValueError("Suno API returned empty response")
|
||||
|
||||
if data.get("code") != 200:
|
||||
error_msg = data.get("msg", "Unknown error")
|
||||
raise ValueError(f"Suno API error: {error_msg}")
|
||||
|
||||
response_data = data.get("data")
|
||||
if response_data is None:
|
||||
raise ValueError(f"Suno API response missing 'data' field: {data}")
|
||||
|
||||
task_id = response_data.get("taskId")
|
||||
if task_id is None:
|
||||
raise ValueError(f"Suno API response missing 'taskId': {response_data}")
|
||||
|
||||
return task_id
|
||||
|
||||
async def get_task_status(self, task_id: str) -> dict[str, Any]:
|
||||
"""
|
||||
음악 생성 작업 상태 확인
|
||||
|
||||
Args:
|
||||
task_id: generate()에서 반환된 작업 ID
|
||||
|
||||
Returns:
|
||||
작업 상태 정보 (status, audio_url, image_url 등 포함)
|
||||
|
||||
Note:
|
||||
폴링 방식으로 상태 확인 시 사용.
|
||||
콜백 URL을 사용하면 폴링 없이 결과를 받을 수 있음.
|
||||
"""
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(
|
||||
f"{self.BASE_URL}/generate/record-info",
|
||||
headers=self.headers,
|
||||
params={"taskId": task_id},
|
||||
timeout=30.0,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
Reference in new issue
Block a user