WIP: channel-brand merge + Optional 모델 완화 + collect_extras rename + mock_urls 영문 채널 51건
머지 본체: - 5채널 외 부가 수집(틱톡/IG·FB EN/네이버 카페/카카오톡) - 브랜드 자산/채널 로고 Vision 분석 - ReportInput/PlanInput에 신규 채널 필드 추가 - ChannelBrandingRule literal "missing" → "N/A" 후속 로컬 작업 (분리 커밋 예정): - fix(report): ClinicSnapshot/YouTubeAudit/Instagram*/Facebook* required→Optional (LLM null 응답 대응) - refactor: enrichment.py → collect_extras.py (네이밍 명확화) - data(mock_urls): 38개 병원 영문 채널 51건 추가 + 78개 필드 캐노니컬 순서 정규화 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
aff2b2720d
27 files changed
+3005
-223
No files matched your search
+52
-6
@@ -8,10 +8,38 @@ from models.file import FileListItem, FileType, FileUploadResponse
|
||||
from models.status import AnalysisStatus
|
||||
from services.pipeline import run_pipeline
|
||||
from services.file import get_analysis_files_response, handle_analysis_file_upload, soft_delete_analysis_file
|
||||
from mock_urls import MOCK_CLINICS
|
||||
from common.utils import _normalize_homepage, _with_scheme
|
||||
|
||||
router = APIRouter(prefix="/api/analysis", tags=["analysis"], dependencies=[Depends(verify_api_key)])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 추후 DB에 클리닉별로 매핑할 채널들 — 지금은 mock_urls에서 homepage 매칭으로 보충.
|
||||
# 메인 채널(IG/FB/YT/네이버블로그/강남언니) + 부가 채널(틱톡/영문 IG·FB/카카오/네이버카페) 모두 포함.
|
||||
# 클라가 일부만 보내거나 빈 값이면 mock에서 동일 hospital을 찾아 채워줌.
|
||||
def _channels_from_mockurls(homepage_url: str) -> dict:
|
||||
target = _normalize_homepage(homepage_url)
|
||||
if not target:
|
||||
return {}
|
||||
for c in MOCK_CLINICS:
|
||||
urls = c["urls"]
|
||||
if _normalize_homepage(urls.get("homepage", "")) == target:
|
||||
return {
|
||||
# main
|
||||
"instagram": _with_scheme(urls.get("instagram")),
|
||||
"facebook": _with_scheme(urls.get("facebook")),
|
||||
"naver_blog": _with_scheme(urls.get("naverBlog")),
|
||||
"youtube": _with_scheme(urls.get("youtube")),
|
||||
"gangnam_unni": _with_scheme(urls.get("gangnamUnni")),
|
||||
# extra
|
||||
"tiktok": _with_scheme(urls.get("tiktok")),
|
||||
"instagram_en": _with_scheme(urls.get("instagramEn")),
|
||||
"facebook_en": _with_scheme(urls.get("facebookEn")),
|
||||
"kakao_talk": _with_scheme(urls.get("kakaoTalk")),
|
||||
"naver_cafe": _with_scheme(urls.get("naverCafe")),
|
||||
}
|
||||
return {}
|
||||
|
||||
|
||||
@router.post("", status_code=status.HTTP_202_ACCEPTED, response_model=AnalysisStartResponse)
|
||||
async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks):
|
||||
@@ -27,18 +55,36 @@ async def start_analysis(body: AnalysisCreate, background_tasks: BackgroundTasks
|
||||
if not hospital:
|
||||
raise HTTPException(status_code=409, detail="Clinic not found")
|
||||
|
||||
ig_id = await insert_instagram_row(hospital_id, body.channels.instagram) if body.channels.instagram else None
|
||||
fb_id = await insert_facebook_row(hospital_id, body.channels.facebook) if body.channels.facebook else None
|
||||
nb_id = await insert_naver_blog_row(hospital_id, body.channels.naver_blog) if body.channels.naver_blog else None
|
||||
yt_id = await insert_youtube_row(hospital_id, body.channels.youtube) if body.channels.youtube else None
|
||||
gu_id = await insert_gangnam_unni_row(hospital_id, body.channels.gangnam_unni) if body.channels.gangnam_unni else None
|
||||
# 클라가 안 보낸 채널은 mock_urls에서 homepage 매칭으로 보충 (main + extra 동일 규칙)
|
||||
mock = _channels_from_mockurls(hospital["url"])
|
||||
|
||||
# 사용자가 'gangnamunni.com/...' 같이 scheme/www 없이 줘도 _with_scheme이 https://www. 보강.
|
||||
ig_url = _with_scheme(body.channels.instagram) or mock.get("instagram")
|
||||
fb_url = _with_scheme(body.channels.facebook) or mock.get("facebook")
|
||||
nb_url = _with_scheme(body.channels.naver_blog) or mock.get("naver_blog")
|
||||
yt_url = _with_scheme(body.channels.youtube) or mock.get("youtube")
|
||||
gu_url = _with_scheme(body.channels.gangnam_unni) or mock.get("gangnam_unni")
|
||||
|
||||
ig_id = await insert_instagram_row(hospital_id, ig_url) if ig_url else None
|
||||
fb_id = await insert_facebook_row(hospital_id, fb_url) if fb_url else None
|
||||
nb_id = await insert_naver_blog_row(hospital_id, nb_url) if nb_url else None
|
||||
yt_id = await insert_youtube_row(hospital_id, yt_url) if yt_url else None
|
||||
gu_id = await insert_gangnam_unni_row(hospital_id, gu_url) if gu_url else None
|
||||
|
||||
analysis_run_id = await insert_analysis_run(
|
||||
analysis_run_id, hospital_id, hospital["owner_user_id"],
|
||||
ig_id, fb_id, nb_id, yt_id, gu_id,
|
||||
)
|
||||
|
||||
background_tasks.add_task(run_pipeline, analysis_run_id)
|
||||
extra_channels = {
|
||||
"tiktok": body.channels.tiktok or mock.get("tiktok"),
|
||||
"instagram_en": body.channels.instagram_en or mock.get("instagram_en"),
|
||||
"facebook_en": body.channels.facebook_en or mock.get("facebook_en"),
|
||||
"kakao_talk": body.channels.kakao_talk or mock.get("kakao_talk"),
|
||||
"naver_cafe": body.channels.naver_cafe or mock.get("naver_cafe"),
|
||||
}
|
||||
logger.info("[analysis] main+extra channels resolved (mock_matched=%s)", bool(mock))
|
||||
background_tasks.add_task(run_pipeline, analysis_run_id, extra_channels)
|
||||
|
||||
return AnalysisStartResponse(
|
||||
analysis_run_id=analysis_run_id,
|
||||
|
||||
+7
-4
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
import logging
|
||||
from fastapi import APIRouter, Depends, HTTPException, Response
|
||||
from common.db import fetchone
|
||||
from common.db import fetchone, fetch_raw
|
||||
from common.deps import verify_api_key
|
||||
from common.utils import _with_scheme
|
||||
from integrations.llm.schemas.plan import PlanOutput
|
||||
from models.plan import PlanApiResponse
|
||||
|
||||
@@ -14,7 +15,7 @@ logger = logging.getLogger(__name__)
|
||||
async def get_plan(run_id: str):
|
||||
logger.info("GET /api/plan/%s", run_id)
|
||||
row = await fetchone(
|
||||
"SELECT ar.plan_data, ar.created_at, h.hospital_name, h.hospital_name_en, h.url"
|
||||
"SELECT ar.plan_data, ar.created_at, ar.gangnam_unni_data_id, h.hospital_name, h.hospital_name_en, h.url"
|
||||
" FROM analysis_runs ar"
|
||||
" JOIN hospital_baseinfo h ON ar.hospital_id = h.hospital_id"
|
||||
" WHERE ar.analysis_run_id = %s",
|
||||
@@ -26,11 +27,13 @@ async def get_plan(run_id: str):
|
||||
return Response(status_code=204)
|
||||
data = json.loads(row["plan_data"]) if isinstance(row["plan_data"], str) else row["plan_data"]
|
||||
plan = PlanOutput(**data)
|
||||
gangnam_unni = await fetch_raw("gangnam_unni_data", row["gangnam_unni_data_id"]) or {}
|
||||
clinic_name = gangnam_unni.get("name") or row["hospital_name"]
|
||||
return PlanApiResponse(
|
||||
id=run_id,
|
||||
clinic_name=row["hospital_name"],
|
||||
clinic_name=clinic_name,
|
||||
clinic_name_en=row["hospital_name_en"],
|
||||
created_at=str(row["created_at"]),
|
||||
target_url=row["url"],
|
||||
target_url=_with_scheme(row["url"]),
|
||||
**plan.model_dump(),
|
||||
)
|
||||
+2
-1
@@ -3,6 +3,7 @@ import logging
|
||||
from fastapi import APIRouter, Depends, HTTPException, Response
|
||||
from common.db import fetchone
|
||||
from common.deps import verify_api_key
|
||||
from common.utils import _with_scheme
|
||||
from integrations.llm.schemas.report import ReportOutput
|
||||
from models.report import MarketingReportResponse
|
||||
|
||||
@@ -31,6 +32,6 @@ async def get_report(run_id: str):
|
||||
clinic_name=row["hospital_name"],
|
||||
clinic_name_en=row["hospital_name_en"],
|
||||
created_at=str(row["created_at"]),
|
||||
target_url=row["url"],
|
||||
target_url=_with_scheme(row["url"]),
|
||||
**llm_output.model_dump(exclude={"id", "created_at", "target_url"}),
|
||||
)
|
||||
Reference in new issue
Block a user