feat(plan): 네이버 블로그 채널 + brand_guide profile_photo 시스템 박기
네이버 블로그 채널 추가: - naver.fetch_blog_total_count: RSS에 totalCount 없으면 blog.naver.com 의 PostList 페이지 HTML에서 '(\d+)개의 글' 패턴으로 진짜 전체 글 수 추출 (RSS는 최근 50개만 줘서 그동안 totalResults=50 으로 잘못 박혔음 — 뷰성형외과 실제 554개) - analysis._naver_blog_summary 다이어트: totalPosts + latestPostDate 만 LLM에 보냄 (posts 본문/링크/제목 빼서 토큰 절약 + LLM의 무관 정보 hallucinate 방지) - plan_prompt: channelStrategies 리스트에 네이버 블로그 명시 포함 brand_guide.channel_branding.profile_photo 코드 박기: - 기존: LLM이 "공식 로고로 통일 (가이드 미보유)" 같은 fallback 문구 hallucinate - 수정: analysis._patch_plan 이 모든 채널의 profile_photo 를 brand_assets.logo_description 으로 일괄 박음 (채널 통일 전략이라 모두 동일 값) - plan_prompt: "profilePhoto 는 빈 문자열로 두세요 — 시스템이 채웁니다" 명시 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8c1e513dc0
commit
9da285e905
3 files changed
+67
-8
No files matched your search
@@ -46,6 +46,8 @@ async def generate_report(analysis_run_id: str) -> ReportOutput:
|
||||
"tiktok": _json(clinic.get("tiktok")),
|
||||
"instagram_en": _json(clinic.get("instagramEn")),
|
||||
"facebook_en": _json(clinic.get("facebookEn")),
|
||||
"kakao_talk": _json(clinic.get("kakaoTalk")),
|
||||
"naver_cafe": _json(clinic.get("naverCafe")),
|
||||
"channel_logos": _json(clinic.get("channelLogos")),
|
||||
**{
|
||||
channel: _json(data)
|
||||
@@ -69,6 +71,7 @@ async def generate_plan(analysis_run_id: str) -> PlanOutput:
|
||||
report_data = run["report_data"]
|
||||
report = json.loads(report_data) if isinstance(report_data, str) else report_data
|
||||
market = await get_market_analysis(analysis_run_id)
|
||||
raw = await get_analysis_raw_data(analysis_run_id)
|
||||
|
||||
def _json(v) -> str | None:
|
||||
return json.dumps(v, ensure_ascii=False) if v else None
|
||||
@@ -89,6 +92,7 @@ async def generate_plan(analysis_run_id: str) -> PlanOutput:
|
||||
"tiktok": _json(clinic.get("tiktok")),
|
||||
"instagram_en": _json(clinic.get("instagramEn")),
|
||||
"facebook_en": _json(clinic.get("facebookEn")),
|
||||
"naver_blog": _json(_naver_blog_summary(raw.get("naver_blog"))),
|
||||
"channel_logos": _json(clinic.get("channelLogos")),
|
||||
"brand_assets": _json(clinic.get("brandAssets")),
|
||||
}
|
||||
@@ -96,6 +100,18 @@ async def generate_plan(analysis_run_id: str) -> PlanOutput:
|
||||
return await LLMService(provider="perplexity").generate(plan_prompt, input_data)
|
||||
|
||||
|
||||
def _naver_blog_summary(blog: dict | None) -> dict | None:
|
||||
"""plan 카드 한 장에 들어가는 건 전체 포스트 수와 최근 활동 시점뿐. 그 외(본문·링크·제목)는
|
||||
던져봐야 토큰만 늘고 LLM이 무관 정보로 hallucinate 함."""
|
||||
if not blog:
|
||||
return None
|
||||
posts = blog.get("posts") or []
|
||||
return {
|
||||
"totalPosts": blog.get("totalResults"),
|
||||
"latestPostDate": posts[0].get("postDate") if posts else None,
|
||||
}
|
||||
|
||||
|
||||
async def _build_overrides(analysis_run_id: str) -> dict:
|
||||
run = await fetchone(
|
||||
"SELECT hospital_id, instagram_data_id, facebook_data_id,"
|
||||
@@ -204,9 +220,25 @@ async def run_report_task(analysis_run_id: str) -> None:
|
||||
logger.info("[report] done run=%s", analysis_run_id)
|
||||
|
||||
|
||||
def _patch_plan(result: PlanOutput, logo_desc: str) -> PlanOutput:
|
||||
"""brand_guide.channel_branding[].profile_photo 는 LLM 안 맡기고 코드가 박는다
|
||||
(모든 채널 동일값 = brand_assets.logo_description). LLM이 fallback 문구 hallucinate 방지."""
|
||||
p = result.model_dump()
|
||||
for ch in (p.get("brand_guide") or {}).get("channel_branding") or []:
|
||||
ch["profile_photo"] = logo_desc
|
||||
return PlanOutput(**p)
|
||||
|
||||
|
||||
async def run_plan_task(analysis_run_id: str) -> None:
|
||||
logger.info("[plan] start run=%s", analysis_run_id)
|
||||
result = await generate_plan(analysis_run_id)
|
||||
# profile_photo 는 brand_assets.logo_description 으로 코드가 박음 (LLM "(가이드 미보유)" 같은 hallucination 차단)
|
||||
run = await fetchone("SELECT hospital_id FROM analysis_runs WHERE analysis_run_id = %s", (analysis_run_id,))
|
||||
if run:
|
||||
hr = await fetchone("SELECT raw_data FROM hospital_baseinfo WHERE hospital_id = %s", (run["hospital_id"],))
|
||||
h = json.loads(hr["raw_data"]) if hr and isinstance(hr.get("raw_data"), str) else (hr or {}).get("raw_data") or {}
|
||||
logo_desc = ((h.get("brandAssets") or {}).get("logo_description")) or ""
|
||||
result = _patch_plan(result, logo_desc)
|
||||
await execute(
|
||||
"UPDATE analysis_runs SET plan_data = %s WHERE analysis_run_id = %s",
|
||||
(json.dumps(result.model_dump(), ensure_ascii=False), analysis_run_id),
|
||||
|
||||
Reference in new issue
Block a user