lyric, song finished
This commit is contained in:
1 parent
4ad6be7504
commit
dd855ff11a
11 files changed
+701
-10
No files matched your search
@@ -32,11 +32,14 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.database.session import get_session
|
||||
from app.lyric.models import Lyric
|
||||
from app.lyric.schemas.lyric import (
|
||||
GenerateLyricRequest,
|
||||
GenerateLyricResponse,
|
||||
LyricDetailResponse,
|
||||
LyricListItem,
|
||||
LyricStatusResponse,
|
||||
PaginatedResponse,
|
||||
)
|
||||
from app.utils.chatgpt_prompt import ChatgptService
|
||||
|
||||
router = APIRouter(prefix="/lyric", tags=["lyric"])
|
||||
|
||||
@@ -214,6 +217,84 @@ async def get_lyrics_paginated(
|
||||
# =============================================================================
|
||||
|
||||
|
||||
@router.post(
|
||||
"/generate",
|
||||
summary="가사 생성",
|
||||
description="""
|
||||
고객 정보를 기반으로 ChatGPT를 이용하여 가사를 생성합니다.
|
||||
|
||||
## 요청 필드
|
||||
- **customer_name**: 고객명/가게명 (필수)
|
||||
- **region**: 지역명 (필수)
|
||||
- **detail_region_info**: 상세 지역 정보 (선택)
|
||||
- **language**: 가사 출력 언어 (Korean, English, Chinese, Japanese, Thai, Vietnamese)
|
||||
|
||||
## 반환 정보
|
||||
- **success**: 생성 성공 여부
|
||||
- **lyric**: 생성된 가사
|
||||
- **language**: 가사 언어
|
||||
- **prompt_used**: 사용된 프롬프트
|
||||
- **error_message**: 에러 메시지 (실패 시)
|
||||
|
||||
## 사용 예시
|
||||
```
|
||||
POST /lyric/generate
|
||||
{
|
||||
"customer_name": "스테이 머뭄",
|
||||
"region": "군산",
|
||||
"detail_region_info": "군산 신흥동 말랭이 마을",
|
||||
"language": "English"
|
||||
}
|
||||
```
|
||||
""",
|
||||
response_model=GenerateLyricResponse,
|
||||
responses={
|
||||
200: {"description": "가사 생성 성공"},
|
||||
500: {"description": "가사 생성 실패"},
|
||||
},
|
||||
)
|
||||
async def generate_lyric(
|
||||
request_body: GenerateLyricRequest,
|
||||
) -> GenerateLyricResponse:
|
||||
"""고객 정보를 기반으로 가사를 생성합니다."""
|
||||
try:
|
||||
service = ChatgptService(
|
||||
customer_name=request_body.customer_name,
|
||||
region=request_body.region,
|
||||
detail_region_info=request_body.detail_region_info or "",
|
||||
language=request_body.language,
|
||||
)
|
||||
|
||||
prompt = service.build_lyrics_prompt()
|
||||
result = await service.generate(prompt=prompt)
|
||||
|
||||
# ERROR가 포함되어 있으면 실패 처리
|
||||
if "ERROR:" in result:
|
||||
return GenerateLyricResponse(
|
||||
success=False,
|
||||
lyric=None,
|
||||
language=request_body.language,
|
||||
prompt_used=prompt,
|
||||
error_message=result,
|
||||
)
|
||||
|
||||
return GenerateLyricResponse(
|
||||
success=True,
|
||||
lyric=result,
|
||||
language=request_body.language,
|
||||
prompt_used=prompt,
|
||||
error_message=None,
|
||||
)
|
||||
except Exception as e:
|
||||
return GenerateLyricResponse(
|
||||
success=False,
|
||||
lyric=None,
|
||||
language=request_body.language,
|
||||
prompt_used=None,
|
||||
error_message=str(e),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/status/{task_id}",
|
||||
summary="가사 생성 상태 조회",
|
||||
|
||||
@@ -29,6 +29,65 @@ from typing import Generic, List, Optional, TypeVar
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class GenerateLyricRequest(BaseModel):
|
||||
"""가사 생성 요청 스키마
|
||||
|
||||
Usage:
|
||||
POST /lyric/generate
|
||||
Request body for generating lyrics.
|
||||
|
||||
Example Request:
|
||||
{
|
||||
"customer_name": "스테이 머뭄",
|
||||
"region": "군산",
|
||||
"detail_region_info": "군산 신흥동 말랭이 마을",
|
||||
"language": "Korean"
|
||||
}
|
||||
"""
|
||||
|
||||
model_config = {
|
||||
"json_schema_extra": {
|
||||
"example": {
|
||||
"customer_name": "스테이 머뭄",
|
||||
"region": "군산",
|
||||
"detail_region_info": "군산 신흥동 말랭이 마을",
|
||||
"language": "Korean",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
customer_name: str = Field(..., description="고객명/가게명")
|
||||
region: str = Field(..., description="지역명")
|
||||
detail_region_info: Optional[str] = Field(None, description="상세 지역 정보")
|
||||
language: str = Field(
|
||||
default="Korean",
|
||||
description="가사 출력 언어 (Korean, English, Chinese, Japanese, Thai, Vietnamese)",
|
||||
)
|
||||
|
||||
|
||||
class GenerateLyricResponse(BaseModel):
|
||||
"""가사 생성 응답 스키마
|
||||
|
||||
Usage:
|
||||
POST /lyric/generate
|
||||
Returns the generated lyrics.
|
||||
|
||||
Example Response:
|
||||
{
|
||||
"success": true,
|
||||
"lyric": "생성된 가사...",
|
||||
"language": "Korean",
|
||||
"prompt_used": "..."
|
||||
}
|
||||
"""
|
||||
|
||||
success: bool = Field(..., description="생성 성공 여부")
|
||||
lyric: Optional[str] = Field(None, description="생성된 가사")
|
||||
language: str = Field(..., description="가사 언어")
|
||||
prompt_used: Optional[str] = Field(None, description="사용된 프롬프트")
|
||||
error_message: Optional[str] = Field(None, description="에러 메시지 (실패 시)")
|
||||
|
||||
|
||||
class LyricStatusResponse(BaseModel):
|
||||
"""가사 상태 조회 응답 스키마
|
||||
|
||||
|
||||
Reference in new issue
Block a user