[feat] solution/backend: 수집 뒤 콘텐츠 채울 때 캐치프레이즈·순환 문구 생성 — 숙박만
가게별 첫 화면 문구를 만드는 곳이 없어 모든 숙박이 공통 문구 10개를 돌려 썼다. - COPY 잡에 catchphrase 단계(prepare→generate→save→catchphrase→faq_fill), 숙박이 아니면 건너뜀 - prompts/catchphrase.py·gemini_text.generate_catchphrases: 캐치프레이즈 1 + 일반 20·계절 3×4·월 12·날씨 2×4. 문구마다 길이·상호명·ground_check(근거 없는 시설·수치) 검사 - fact tagline·catchphrases(lodging 스키마, allow_llm). 순환 문구는 사장님이 줄 단위로 고치게 글로 저장 (catchphrase_text: `봄 | ` · `9월 | ` · `비 | ` 머리) - site_payload: narrative.tagline·catchphrases 로 넘기고 이용정보 표(facts)에서는 뺀다 - 빌더 생성 화면 단계 문구, DATA_MODEL·GENERATION_FLOW 테스트 6건 추가. 관련 20개 파일 386 passed · 실패 102건은 main 과 목록이 같다(기존 실패) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0b14dfca1
commit
ef0c44c5f2
13 files changed
+377
-8
No files matched your search
@@ -0,0 +1,26 @@
|
||||
"""순환 문구 글 형식 — 사장님이 줄 단위로 고친 글이 그대로 계절·월·날씨 문구로 읽혀야 한다."""
|
||||
from services import catchphrase_text
|
||||
|
||||
|
||||
def test_round_trips_every_kind():
|
||||
items = [
|
||||
{"text": "백 년 된 집에서 하룻밤", "kind": "general"},
|
||||
{"text": "봄에는 대문을 열어 둡니다", "kind": "season", "season": "봄"},
|
||||
{"text": "새해 첫 아침을 이 집에서", "kind": "month", "month": 1},
|
||||
{"text": "기와에 빗소리가 납니다", "kind": "weather", "weather": "비"},
|
||||
]
|
||||
text = catchphrase_text.encode(items)
|
||||
assert text.splitlines() == [
|
||||
"백 년 된 집에서 하룻밤",
|
||||
"봄 | 봄에는 대문을 열어 둡니다",
|
||||
"1월 | 새해 첫 아침을 이 집에서",
|
||||
"비 | 기와에 빗소리가 납니다",
|
||||
]
|
||||
assert catchphrase_text.decode(text) == items
|
||||
|
||||
|
||||
def test_unknown_tag_stays_a_general_line():
|
||||
assert catchphrase_text.decode("장마 | 비가 옵니다\n\n 13월 | 없는 달 ") == [
|
||||
{"text": "장마 | 비가 옵니다", "kind": "general"},
|
||||
{"text": "13월 | 없는 달", "kind": "general"},
|
||||
]
|
||||
@@ -30,6 +30,15 @@ def _patch(monkeypatch, copy):
|
||||
|
||||
monkeypatch.setattr(gemini_text, "generate_copy", _gen)
|
||||
|
||||
async def _phrases(place_name, facts, **kw):
|
||||
return gemini_text.GeneratedCatchphrases(
|
||||
tagline="체크인 오후 세 시, 조용한 집",
|
||||
items=[{"text": "짐을 풀면 골목부터 걸어 보세요", "kind": "general"},
|
||||
{"text": "봄에는 창을 열어 둡니다", "kind": "season", "season": "봄"}],
|
||||
)
|
||||
|
||||
monkeypatch.setattr(gemini_text, "generate_catchphrases", _phrases)
|
||||
|
||||
|
||||
async def _place_with_facts(client, h, n_verified=5):
|
||||
pid = (await client.post("/v1/place", headers=h, json={"name": "카피펜션", "category": 1})).json()["place"]["place_id"]
|
||||
@@ -96,7 +105,7 @@ async def test_resume_reuses_completed_job(auth_headers, client, db_engine, monk
|
||||
job = (await client.get(f"/v1/job/{first['job_id']}", headers=h)).json()["job"]
|
||||
assert job["place_id"] == pid
|
||||
assert [(s["id"], s["status"]) for s in job["progress"]["steps"]] == [
|
||||
("prepare", "done"), ("generate", "done"), ("save", "done"), ("faq_fill", "done"),
|
||||
("prepare", "done"), ("generate", "done"), ("save", "done"), ("catchphrase", "done"), ("faq_fill", "done"),
|
||||
]
|
||||
fresh = (await client.post(path, headers=h, json={})).json()
|
||||
assert fresh["job_id"] != first["job_id"]
|
||||
@@ -111,7 +120,7 @@ async def test_copy_progress_is_visible_during_generation(auth_headers, client,
|
||||
async def generate(*args, **kwargs):
|
||||
row = await JobQueue().get(started["job_id"])
|
||||
assert row["status"] == JobStatus.RUNNING.value
|
||||
assert [step["status"] for step in row["progress"]["steps"]] == ["done", "running", "pending", "pending"]
|
||||
assert [step["status"] for step in row["progress"]["steps"]] == ["done", "running", "pending", "pending", "pending"]
|
||||
return _copy()
|
||||
|
||||
monkeypatch.setattr(gemini_text, "generate_copy", generate)
|
||||
@@ -303,3 +312,21 @@ async def test_copy_requires_api_key(auth_headers, client, monkeypatch):
|
||||
pid = await _place_with_facts(client, h)
|
||||
r = await client.post(f"/v1/place/{pid}/copy", headers=h, json={})
|
||||
assert r.json()["result"]["code"] == ErrorType.GENERATOR_NOT_CONFIGURED.value
|
||||
|
||||
|
||||
async def test_copy_writes_one_catchphrase_and_the_rotating_lines(auth_headers, client, db_engine, monkeypatch):
|
||||
_patch(monkeypatch, _copy())
|
||||
h = await auth_headers("catchphrase-owner")
|
||||
pid = await _place_with_facts(client, h)
|
||||
job_id = (await client.post(f"/v1/place/{pid}/copy", headers=h, json={})).json()["job_id"]
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).drain()
|
||||
job = (await client.get(f"/v1/job/{job_id}", headers=h)).json()["job"]
|
||||
assert job["result"]["catchphrase"]["tagline"] is True
|
||||
assert job["result"]["catchphrase"]["catchphrases"] == 2
|
||||
async with db_engine.begin() as c:
|
||||
rows = dict((await c.execute(
|
||||
text("SELECT key, value FROM place_facts WHERE place_id = :p AND key IN ('tagline', 'catchphrases')"),
|
||||
{"p": uuid.UUID(pid)},
|
||||
)).all())
|
||||
assert rows["tagline"] == "체크인 오후 세 시, 조용한 집"
|
||||
assert rows["catchphrases"] == "짐을 풀면 골목부터 걸어 보세요\n봄 | 봄에는 창을 열어 둡니다"
|
||||
@@ -377,3 +377,34 @@ async def test_summarize_empty_text_returns_none():
|
||||
"""검증: 빈 문자열."""
|
||||
result = await gt.summarize_text(" ")
|
||||
assert result is None
|
||||
|
||||
|
||||
# ── 첫 화면 문구 ───────────────────────────────────────────────────────────
|
||||
def _phrase_payload(body):
|
||||
return {
|
||||
"candidates": [{"content": {"parts": [{"text": json.dumps(body, ensure_ascii=False)}]}, "finishReason": "STOP"}],
|
||||
"usageMetadata": {"promptTokenCount": 800, "candidatesTokenCount": 400},
|
||||
}
|
||||
|
||||
|
||||
async def test_catchphrases_keep_only_grounded_lines_of_the_right_shape():
|
||||
body = {
|
||||
"tagline": "주차하고 바로 쉬는 집",
|
||||
"general": ["짐을 풀면 골목부터 걸어 보세요", "오션뷰 수영장이 있습니다", "짧다", "하조대펜션에서 쉬세요"],
|
||||
"season": [{"season": "봄", "text": "봄에는 창을 열어 둡니다"}, {"season": "장마", "text": "비가 오래 오는 계절입니다"}],
|
||||
"month": [{"month": 1, "text": "새해 첫 아침을 조용히"}, {"month": 13, "text": "없는 달의 문구입니다"}],
|
||||
"weather": [{"weather": "비", "text": "빗소리를 들으며 쉬세요"}],
|
||||
}
|
||||
async with _client(_ok(_phrase_payload(body))) as c:
|
||||
res = await gt.generate_catchphrases("하조대펜션", FACTS, client=c)
|
||||
assert res.tagline == "주차하고 바로 쉬는 집"
|
||||
assert res.items == [
|
||||
{"text": "짐을 풀면 골목부터 걸어 보세요", "kind": "general"},
|
||||
{"text": "봄에는 창을 열어 둡니다", "kind": "season", "season": "봄"},
|
||||
{"text": "새해 첫 아침을 조용히", "kind": "month", "month": 1},
|
||||
{"text": "빗소리를 들으며 쉬세요", "kind": "weather", "weather": "비"},
|
||||
]
|
||||
reasons = dict(res.rejected)
|
||||
assert "오션뷰 수영장이 있습니다" in reasons
|
||||
assert reasons["짧다"].startswith("길이")
|
||||
assert reasons["하조대펜션에서 쉬세요"] == "상호명 포함"
|
||||
Reference in new issue
Block a user