[feat] solution/backend: SNS 캡션 첫 문장에 지역·업종·상호
겨냥하는 것이 AI 검색 노출인데 캡션에 그 단서가 하나도 없었다. "군산 숙소" 같은
지역+업종은 실제 검색어이고 AI 가 인용할 때 잡는 말이다.
★ 해시태그가 아니라 문장에 녹인다. AI 는 태그가 아니라 문장을 읽고, 이 글은
사장님 개인 계정으로 나가는 발화라(DECISIONS 8) 태그 나열은 그 전제와 어긋난다.
기존 해시태그 금지는 그대로 둔다.
★ 지역·업종은 fact 가 아니라 카카오 로컬 검증을 통과한 place 값이다. ground_check
근거에 같이 얹는다 — 안 얹으면 본문에 쓴 순간 '근거 없는 주장' 으로 반려되고
3회 재시도를 태우고 실패한다. 상호명을 그렇게 다루던 방식 그대로다.
- prompts/social: caption_category("숙박업소"→숙소) · caption_region(
"전북특별자치도 군산시"→"전북 군산"). ★ copy.py 라벨과 region_label() 을 그대로
쓰지 않는다 — 저쪽은 홈페이지 본문·쇼케이스 목록용이라 그 자리에선 그게 맞다
- 표에 없는 시·도는 그대로 둔다 — 줄이려다 엉뚱한 지역이 되는 것보다 낫다
- 값이 없으면 그 말만 빠지고 나머지는 그대로 나간다
실모델 확인: "전북 군산의 숙소 스테이,머뭄은…" weighted 141/500(전 120).
test_social 27 passed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
87343c791b
commit
e9849584c4
5 files changed
+183
-7
No files matched your search
@@ -641,3 +641,76 @@ async def test_publish_reused_text_inserts_approved_post_with_link_and_enqueues_
|
||||
assert (
|
||||
await c.execute(text("SELECT count(*) FROM place_social_posts WHERE place_id=:p"), {"p": pid})
|
||||
).scalar_one() == 1
|
||||
|
||||
|
||||
# ── 캡션에 지역·업종·상호 (2026-09-30) ──────────────────────────────────
|
||||
|
||||
def test_캡션_업종말은_홈페이지_본문_말과_다르다():
|
||||
"""★ 쓰이는 자리가 다르다 — "숙박업소에서 쉬어 가세요" 는 사람이 쓰는 말이 아니다."""
|
||||
from common.enums import PlaceCategory
|
||||
from services.prompts import copy as copy_prompt, social as social_prompt
|
||||
|
||||
assert social_prompt.caption_category(PlaceCategory.LODGING.value) == "숙소"
|
||||
assert copy_prompt._CATEGORY_LABEL[PlaceCategory.LODGING] == "숙박업소"
|
||||
# 모르는 값이면 그 말만 빠진다 — 캡션 생성이 통째로 막히지 않는다.
|
||||
assert social_prompt.caption_category(999) == ""
|
||||
assert social_prompt.caption_category(None) == ""
|
||||
|
||||
|
||||
def test_캡션_지역말은_행정표기를_줄인다():
|
||||
"""★ region_label 은 쇼케이스 목록용이라 "전북특별자치도 군산시" 가 맞다. 캡션은 다르다 —
|
||||
사람이 검색하는 말은 "군산 숙소" 이고 AI 가 인용할 때 잡는 말도 그쪽이다."""
|
||||
from services.prompts import social as social_prompt
|
||||
|
||||
assert social_prompt.caption_region("전북특별자치도 군산시") == "전북 군산"
|
||||
assert social_prompt.caption_region("서울특별시 종로구") == "서울 종로"
|
||||
assert social_prompt.caption_region("제주특별자치도 제주시") == "제주" # 겹치면 한 번만
|
||||
assert social_prompt.caption_region("") == ""
|
||||
# ★ 표에 없는 시·도는 그대로 둔다(시·군·구 접미사만 뗀다).
|
||||
assert social_prompt.caption_region("어느도 어디시") == "어느도 어디"
|
||||
|
||||
|
||||
def test_프롬프트가_지역_업종_상호를_문장으로_넣게_시킨다():
|
||||
"""★ 해시태그가 아니다. AI 는 태그가 아니라 문장을 읽고, 이 글은 사장님 명의다."""
|
||||
from services.prompts import social as social_prompt
|
||||
|
||||
prompt = social_prompt.build_prompt(
|
||||
"스테이,머뭄", [], 400, region="전북 군산", category="숙소")
|
||||
assert "전북 군산의 숙소 스테이,머뭄" in prompt
|
||||
assert "태그로 나열하지 말고" in prompt
|
||||
assert "해시태그" in prompt # 기존 금지는 그대로 남는다
|
||||
|
||||
# 값이 없으면 그 말만 빠진다.
|
||||
plain = social_prompt.build_prompt("스테이,머뭄", [], 400)
|
||||
assert '"스테이,머뭄" 를 자연스럽게' in plain
|
||||
|
||||
|
||||
async def test_지역과_업종은_근거에_얹힌다(monkeypatch):
|
||||
"""★ 얹지 않으면 본문에 쓴 순간 '근거 없는 주장' 으로 반려되고 3회 재시도를 태우고 실패한다."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
from services.external import gemini_text
|
||||
from services.llm import provider as llm_provider
|
||||
|
||||
seen = {}
|
||||
|
||||
def fake_ground_check(body, grounds):
|
||||
seen["keys"] = {g.key for g in grounds}
|
||||
return True, []
|
||||
|
||||
async def fake_generate(client, model, **kw):
|
||||
return SimpleNamespace(
|
||||
json={"body": "전북 군산의 숙소 스테이,머뭄에서 조용한 하루를 보내세요.",
|
||||
"fact_keys": ["check_in_time"]},
|
||||
text="", usage=None,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(gemini_text, "ground_check", fake_ground_check)
|
||||
active = llm_provider.active()
|
||||
monkeypatch.setattr(active, "is_configured", lambda: True)
|
||||
monkeypatch.setattr(active, "generate", fake_generate)
|
||||
|
||||
facts = [gemini_text.FactInput(key="check_in_time", label="체크인", value="15:00")]
|
||||
await gemini_text.generate_social_post(
|
||||
"스테이,머뭄", facts, "https://example.com/s/x", 2, region="전북 군산", category="숙소")
|
||||
assert {"name", "region", "category", "check_in_time"} <= seen["keys"]
|
||||
Reference in new issue
Block a user