fix: 썰박스 포스터·SNS 메타데이터 생성 및 공유 미리보기 수정
This commit is contained in:
1 parent
5fcb964d7f
commit
048a8f36a8
5 files changed
+178
-35
No files matched your search
@@ -70,10 +70,6 @@ class SeoService:
|
||||
session: AsyncSession,
|
||||
) -> YoutubeDescriptionResponse:
|
||||
"""썰박스 콘텐츠용 SEO 생성 — ADO2 와 다른 프롬프트(시트 ssul_upload)를 쓴다."""
|
||||
from app.ssulbox.constants import SCENARIO_NAMES
|
||||
from app.utils.prompts.chatgpt_prompt import ChatgptService
|
||||
from app.utils.prompts.prompts import get_ssul_upload_prompt
|
||||
|
||||
try:
|
||||
content = (
|
||||
await session.execute(
|
||||
@@ -93,24 +89,12 @@ class SeoService:
|
||||
if has_stored_sns_metadata(content):
|
||||
return self._response_from_row(content)
|
||||
|
||||
input_data = {
|
||||
"store_name": content.store_name or "",
|
||||
"region": content.region or "",
|
||||
"scenario_name": SCENARIO_NAMES.get(content.scenario, content.scenario),
|
||||
}
|
||||
|
||||
chatgpt = ChatgptService(timeout=180)
|
||||
out = await chatgpt.generate_structured_output(
|
||||
get_ssul_upload_prompt(), input_data
|
||||
)
|
||||
result = YoutubeDescriptionResponse(
|
||||
title=out.title,
|
||||
description=out.description,
|
||||
keywords=out.keywords,
|
||||
)
|
||||
apply_sns_metadata(content, result.title, result.description, result.keywords)
|
||||
result = await self.generate_and_save_for_ssul(content_id, session)
|
||||
if result is None:
|
||||
raise HTTPException(
|
||||
status_code=404, detail="콘텐츠를 찾을 수 없습니다."
|
||||
)
|
||||
await session.commit()
|
||||
logger.info(f"[SEO_SERVICE] Saved ssul metadata - content_id: {content_id}")
|
||||
return result
|
||||
|
||||
except HTTPException:
|
||||
@@ -122,6 +106,50 @@ class SeoService:
|
||||
detail=f"썰박스 SEO 생성에 실패했습니다. : {str(e)}",
|
||||
)
|
||||
|
||||
async def generate_and_save_for_ssul(
|
||||
self,
|
||||
content_id: int,
|
||||
session: AsyncSession,
|
||||
) -> YoutubeDescriptionResponse | None:
|
||||
"""GPT로 썰박스 SNS 메타데이터를 생성해 저장합니다. 워커/온디맨드 공용."""
|
||||
content = await session.get(SsulContent, content_id)
|
||||
if content is None:
|
||||
logger.warning(f"[SEO_SERVICE] SsulContent NOT FOUND - content_id: {content_id}")
|
||||
return None
|
||||
|
||||
if has_stored_sns_metadata(content):
|
||||
return self._response_from_row(content)
|
||||
|
||||
result = await self._generate_ssul_seo_description(content)
|
||||
apply_sns_metadata(content, result.title, result.description, result.keywords)
|
||||
await session.flush()
|
||||
logger.info(f"[SEO_SERVICE] Saved ssul metadata - content_id: {content_id}")
|
||||
return result
|
||||
|
||||
async def _generate_ssul_seo_description(
|
||||
self,
|
||||
content: SsulContent,
|
||||
) -> YoutubeDescriptionResponse:
|
||||
"""썰박스 전용 프롬프트로 제목/설명/해시태그를 생성합니다."""
|
||||
from app.ssulbox.constants import SCENARIO_NAMES
|
||||
from app.utils.prompts.chatgpt_prompt import ChatgptService
|
||||
from app.utils.prompts.prompts import get_ssul_upload_prompt
|
||||
|
||||
input_data = {
|
||||
"store_name": content.store_name or "",
|
||||
"region": content.region or "",
|
||||
"scenario_name": SCENARIO_NAMES.get(content.scenario, content.scenario),
|
||||
}
|
||||
chatgpt = ChatgptService(timeout=180)
|
||||
out = await chatgpt.generate_structured_output(
|
||||
get_ssul_upload_prompt(), input_data
|
||||
)
|
||||
return YoutubeDescriptionResponse(
|
||||
title=out.title,
|
||||
description=out.description,
|
||||
keywords=out.keywords,
|
||||
)
|
||||
|
||||
async def generate_and_save_for_video(
|
||||
self,
|
||||
video_id: int,
|
||||
|
||||
Reference in new issue
Block a user