이미지 업로드 때 task_id 생성으로 변경, 가사 생성시 task_id 받아오는 것으로 변경
This commit is contained in:
1 parent
f81d158f0f
commit
c6d9edbb42
4 files changed
+130
-53
No files matched your search
@@ -42,7 +42,6 @@ from app.lyric.schemas.lyric import (
|
||||
LyricStatusResponse,
|
||||
)
|
||||
from app.utils.chatgpt_prompt import ChatgptService
|
||||
from app.utils.common import generate_task_id
|
||||
from app.utils.pagination import PaginatedResponse, get_paginated
|
||||
|
||||
router = APIRouter(prefix="/lyric", tags=["lyric"])
|
||||
@@ -159,6 +158,7 @@ async def get_lyric_by_task_id(
|
||||
고객 정보를 기반으로 ChatGPT를 이용하여 가사를 생성합니다.
|
||||
|
||||
## 요청 필드
|
||||
- **task_id**: 작업 고유 식별자 (이미지 업로드 시 생성된 task_id, 필수)
|
||||
- **customer_name**: 고객명/가게명 (필수)
|
||||
- **region**: 지역명 (필수)
|
||||
- **detail_region_info**: 상세 지역 정보 (선택)
|
||||
@@ -180,6 +180,7 @@ async def get_lyric_by_task_id(
|
||||
```
|
||||
POST /lyric/generate
|
||||
{
|
||||
"task_id": "0694b716-dbff-7219-8000-d08cb5fce431",
|
||||
"customer_name": "스테이 머뭄",
|
||||
"region": "군산",
|
||||
"detail_region_info": "군산 신흥동 말랭이 마을",
|
||||
@@ -220,9 +221,10 @@ async def generate_lyric(
|
||||
session: AsyncSession = Depends(get_session),
|
||||
) -> GenerateLyricResponse:
|
||||
"""고객 정보를 기반으로 가사를 생성합니다."""
|
||||
task_id = await generate_task_id(session=session, table_name=Project)
|
||||
task_id = request_body.task_id
|
||||
print(
|
||||
f"[generate_lyric] START - task_id: {task_id}, customer_name: {request_body.customer_name}, region: {request_body.region}"
|
||||
f"[generate_lyric] START - task_id: {task_id}, "
|
||||
f"customer_name: {request_body.customer_name}, region: {request_body.region}"
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
+57
-40
@@ -25,7 +25,7 @@ Lyric API Schemas
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class GenerateLyricRequest(BaseModel):
|
||||
@@ -37,6 +37,7 @@ class GenerateLyricRequest(BaseModel):
|
||||
|
||||
Example Request:
|
||||
{
|
||||
"task_id": "0694b716-dbff-7219-8000-d08cb5fce431",
|
||||
"customer_name": "스테이 머뭄",
|
||||
"region": "군산",
|
||||
"detail_region_info": "군산 신흥동 말랭이 마을",
|
||||
@@ -44,17 +45,21 @@ class GenerateLyricRequest(BaseModel):
|
||||
}
|
||||
"""
|
||||
|
||||
model_config = {
|
||||
"json_schema_extra": {
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"task_id": "0694b716-dbff-7219-8000-d08cb5fce431",
|
||||
"customer_name": "스테이 머뭄",
|
||||
"region": "군산",
|
||||
"detail_region_info": "군산 신흥동 말랭이 마을",
|
||||
"language": "Korean",
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
task_id: str = Field(
|
||||
..., description="작업 고유 식별자 (이미지 업로드 시 생성된 task_id)"
|
||||
)
|
||||
customer_name: str = Field(..., description="고객명/가게명")
|
||||
region: str = Field(..., description="지역명")
|
||||
detail_region_info: Optional[str] = Field(None, description="상세 지역 정보")
|
||||
@@ -76,26 +81,20 @@ class GenerateLyricResponse(BaseModel):
|
||||
- ChatGPT API 오류
|
||||
- ChatGPT 거부 응답 (I'm sorry, I cannot, I can't, I apologize 등)
|
||||
- 응답에 ERROR: 포함
|
||||
|
||||
Example Response (Success):
|
||||
{
|
||||
"success": true,
|
||||
"task_id": "019123ab-cdef-7890-abcd-ef1234567890",
|
||||
"lyric": "인스타 감성의 스테이 머뭄...",
|
||||
"language": "Korean",
|
||||
"error_message": null
|
||||
}
|
||||
|
||||
Example Response (Failure):
|
||||
{
|
||||
"success": false,
|
||||
"task_id": "019123ab-cdef-7890-abcd-ef1234567890",
|
||||
"lyric": null,
|
||||
"language": "Korean",
|
||||
"error_message": "I'm sorry, I can't comply with that request."
|
||||
}
|
||||
"""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"success": True,
|
||||
"task_id": "0694b716-dbff-7219-8000-d08cb5fce431",
|
||||
"lyric": "인스타 감성의 스테이 머뭄\n군산 신흥동 말랭이 마을에서\n여유로운 하루를 보내며\n추억을 만들어가요",
|
||||
"language": "Korean",
|
||||
"error_message": None,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
success: bool = Field(..., description="생성 성공 여부")
|
||||
task_id: Optional[str] = Field(None, description="작업 고유 식별자 (uuid7)")
|
||||
lyric: Optional[str] = Field(None, description="생성된 가사 (성공 시)")
|
||||
@@ -109,15 +108,18 @@ class LyricStatusResponse(BaseModel):
|
||||
Usage:
|
||||
GET /lyric/status/{task_id}
|
||||
Returns the current processing status of a lyric generation task.
|
||||
|
||||
Example Response:
|
||||
{
|
||||
"task_id": "019123ab-cdef-7890-abcd-ef1234567890",
|
||||
"status": "completed",
|
||||
"message": "가사 생성이 완료되었습니다."
|
||||
}
|
||||
"""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"task_id": "0694b716-dbff-7219-8000-d08cb5fce431",
|
||||
"status": "completed",
|
||||
"message": "가사 생성이 완료되었습니다.",
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
task_id: str = Field(..., description="작업 고유 식별자")
|
||||
status: str = Field(..., description="처리 상태 (processing, completed, failed)")
|
||||
message: str = Field(..., description="상태 메시지")
|
||||
@@ -129,19 +131,22 @@ class LyricDetailResponse(BaseModel):
|
||||
Usage:
|
||||
GET /lyric/{task_id}
|
||||
Returns the generated lyric content for a specific task.
|
||||
|
||||
Example Response:
|
||||
{
|
||||
"id": 1,
|
||||
"task_id": "019123ab-cdef-7890-abcd-ef1234567890",
|
||||
"project_id": 1,
|
||||
"status": "completed",
|
||||
"lyric_prompt": "...",
|
||||
"lyric_result": "생성된 가사...",
|
||||
"created_at": "2024-01-01T12:00:00"
|
||||
}
|
||||
"""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"id": 1,
|
||||
"task_id": "0694b716-dbff-7219-8000-d08cb5fce431",
|
||||
"project_id": 1,
|
||||
"status": "completed",
|
||||
"lyric_prompt": "고객명: 스테이 머뭄, 지역: 군산...",
|
||||
"lyric_result": "인스타 감성의 스테이 머뭄\n군산 신흥동 말랭이 마을에서\n여유로운 하루를 보내며\n추억을 만들어가요",
|
||||
"created_at": "2024-01-15T12:00:00",
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
id: int = Field(..., description="가사 ID")
|
||||
task_id: str = Field(..., description="작업 고유 식별자")
|
||||
project_id: int = Field(..., description="프로젝트 ID")
|
||||
@@ -158,6 +163,18 @@ class LyricListItem(BaseModel):
|
||||
Used as individual items in paginated lyric list responses.
|
||||
"""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"id": 1,
|
||||
"task_id": "0694b716-dbff-7219-8000-d08cb5fce431",
|
||||
"status": "completed",
|
||||
"lyric_result": "인스타 감성의 스테이 머뭄\n군산 신흥동 말랭이 마을에서...",
|
||||
"created_at": "2024-01-15T12:00:00",
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
id: int = Field(..., description="가사 ID")
|
||||
task_id: str = Field(..., description="작업 고유 식별자")
|
||||
status: str = Field(..., description="처리 상태")
|
||||
|
||||
Reference in new issue
Block a user