feat(backend): fact 목록 응답에 intro/room_intro AI 요약 부착
/v1/place/{id}/fact/list 가 intro·room_intro fact 중 200자를 넘는 것만
Gemini 로 요약해 FactData.summary 에 실어 보낸다. 짧은 값은 API를
부르지 않고, DB에도 저장하지 않는다(응답 전용).
This commit is contained in:
1 parent
3342981bd2
commit
8920e9b9d0
3 files changed
+80
No files matched your search
@@ -32,6 +32,7 @@ from router.v1.fact.protocol import (
|
||||
Res_Fact,
|
||||
Res_FactList,
|
||||
)
|
||||
from services.external import gemini_text
|
||||
from services.external.gemini_extract import extract_facts
|
||||
from services.llm.gemini import GeminiError, GeminiNotConfigured
|
||||
|
||||
@@ -40,6 +41,10 @@ from services.llm.gemini import GeminiError, GeminiNotConfigured
|
||||
# '어디서 왔는가' 는 여전히 명확하다: 사장님이 화면에 직접 붙여넣었다.
|
||||
OWNER_PASTE_SOURCE = "owner:paste"
|
||||
|
||||
# 캔버스 미리보기 요약 대상. 원문이 이 길이를 넘을 때만 요약을 만든다(짧은 문장까지 돈 쓰지 않는다).
|
||||
_SUMMARY_FACT_KEYS = {"intro", "room_intro"}
|
||||
_SUMMARY_THRESHOLD_CHARS = 200
|
||||
|
||||
# 자동 수집 출처 — 노출값을 직접 바꾸지 못하고 후보로만 들어간다.
|
||||
_AUTO_SOURCES = (SourceType.API, SourceType.CRAWL, SourceType.LLM)
|
||||
|
||||
@@ -133,12 +138,26 @@ class FactService:
|
||||
res.result.SetResult(list_err)
|
||||
return res
|
||||
res.facts = [FactData.model_validate(r) for r in rows]
|
||||
await self._attach_summaries(res.facts)
|
||||
# ★ 사이트에 나갈 수 있는 건수. 발행 게이트가 보는 숫자와 같은 기준이다.
|
||||
res.publishable = sum(1 for r in rows if FactStatus(r.status) in PUBLISHABLE_FACT_STATUSES)
|
||||
# 재수집이 올려놓은 확인 대기 건수 — 관리 화면의 '검토할 것' 배지.
|
||||
res.pending_review = sum(1 for r in rows if FactStatus(r.status) == FactStatus.PENDING_OWNER)
|
||||
return res
|
||||
|
||||
async def _attach_summaries(self, facts: list) -> None:
|
||||
"""intro/room_intro 원문이 길면 캔버스 미리보기용 요약을 얹는다.
|
||||
|
||||
★ place_facts 에는 저장하지 않는다 — 이 응답(FactData.summary)에만 실린다.
|
||||
원문이 짧으면 API 를 부르지 않는다(_SUMMARY_THRESHOLD_CHARS)."""
|
||||
for f in facts:
|
||||
if f.key not in _SUMMARY_FACT_KEYS:
|
||||
continue
|
||||
value = (f.value or "").strip()
|
||||
if len(value) <= _SUMMARY_THRESHOLD_CHARS:
|
||||
continue
|
||||
f.summary = await gemini_text.summarize_text(value)
|
||||
|
||||
# ---- 기록 ----
|
||||
async def extract_from_text(self, user_info: UserInfo, place_id: str, text: str) -> Res_ExtractFacts:
|
||||
"""사장님이 붙여넣은 원문 → fact 후보.
|
||||
|
||||
Reference in new issue
Block a user