o2o-site-AEO/solution/backend/services/copy_service.py
hbyang 4dd0c604ee [fix] solution/backend: 키 미설정 문구가 엉뚱한 공급자를 가리키던 것
공급자를 openai 로 바꾼 뒤에도 호출측에 "GEMINI_API_KEY 미설정" 이 문자열로
박혀 있어서, **없는 것은 OPENAI_API_KEY 인데 화면은 Gemini 를 탓했다**
(실측 2026-09-21: 로컬에서 소개문이 안 나와 Gemini 키를 한참 들여다봤다).
원인을 정확히 반대로 가리키는 종류다.

- llm/provider: missing_key() 추가 — 활성 공급자에게 필요한 env 이름을 돌려준다
- copy_service·collect_service·song_service: 하드코딩 문구를 그 함수로 교체
- enums: GENERATOR_NOT_CONFIGURED 주석도 공급자 중립으로

관련 테스트 55 passed

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 17:19:29 +09:00

50 lines
2.1 KiB
Python

"""COPY 흐름. 단계 구현: copy_steps / 프롬프트: prompts/copy / 호출·검증: external/gemini_text."""
from common.logger import LOG
from services.copy_steps import CopyAborted, prepare_copy, generate_copy, save_copy, fill_faqs
from services.external import gemini_text
from services.llm import provider
from services.job_progress import JobProgress
COPY_STEPS = ("prepare", "generate", "save", "faq_fill")
async def run_copy(job: dict) -> dict:
progress = JobProgress(job, COPY_STEPS)
payload = job["payload"]
async with progress.step("prepare"):
inputs = await prepare_copy(payload["place_id"], payload["owner_user_id"])
copy = None
note = None
if inputs.ungrounded or not gemini_text.is_configured():
note = "근거로 쓸 확인된 fact 가 없다" if inputs.ungrounded else f"{provider.missing_key()} 미설정"
await progress.skip("generate", "no_facts" if inputs.ungrounded else "not_configured")
if inputs.catalog is None and not inputs.ungrounded:
raise CopyAborted(note)
else:
try:
async with progress.step("generate"):
copy = await generate_copy(inputs)
except gemini_text.GeminiError as ex:
# ★ 호출 실패는 미설정과 같은 취급이다 — fact 만으로도 편집·발행이 되고
# (publish_gate.check_unique_content), 발행은 고유 콘텐츠 0건으로 막지 않는다.
# 자세한 배경은 DEVLOG.md 참고.
note = f"생성 호출 실패: {ex}"
LOG.w(f"[copy] 생성 실패, fact 만으로 계속: {ex}")
await progress.skip("generate", "generation_failed")
async with progress.step("save"):
result = await save_copy(inputs, copy)
if inputs.catalog is not None:
async with progress.step("faq_fill"):
result["faq_fill"] = await fill_faqs(
inputs.place.place_id, inputs.catalog, inputs.known_fact_keys, inputs.place.phone,
)
else:
await progress.skip("faq_fill", "no_catalog")
if note:
result["note"] = note
return result