본문 어투: 기본 다정한 톤 + 다정한/담백한/서정적인 선택과 다시 쓰기(미리보기·적용)
This commit is contained in:
1 parent
a749b9daf8
commit
02e654d75e
5 files changed
+139
-5
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
@@ -164,3 +165,35 @@ def update_product(payload: Dict[str, Any], helpers: Dict[str, Any]) -> Dict[str
|
||||
"deployed": bool(payload.get("deploy")) and deploy_ok,
|
||||
"pushed": push_ok, "build_log": log[-300:], "deploy_log": deploy_log[-300:],
|
||||
"url": f"/p/{slug}.html"}
|
||||
|
||||
|
||||
def rewrite_body(slug: str, tone: str) -> Dict[str, Any]:
|
||||
"""기존 본문을 다른 어투로 다시 쓴다(저장은 사람이 확인하고 한다)."""
|
||||
slug = re.sub(r"[^a-z0-9-]+", "-", str(slug or "").lower()).strip("-")
|
||||
path = reg.PRODUCTS / f"{slug}.md"
|
||||
if not path.is_file():
|
||||
raise FileNotFoundError(f"작품을 찾을 수 없습니다: {slug}")
|
||||
|
||||
data, body = parse_front(path.read_text(encoding="utf-8"))
|
||||
guide = reg.TONES.get(tone) or reg.TONES[reg.DEFAULT_TONE]
|
||||
system = reg.tone_system(tone) + (
|
||||
"\n\n지금 할 일: 아래 '지금 본문'을 같은 사실 그대로 두고 어투만 바꿔 다시 쓴다."
|
||||
"\n- 재료·규격·가격·기간 같은 값은 바꾸지 않는다. 없는 사실을 더하지 않는다."
|
||||
"\n- 문단 수는 2~4개를 지킨다."
|
||||
'\n응답은 설명 없이 JSON 하나: {"body": "새 본문 전문"}'
|
||||
)
|
||||
user = json.dumps({
|
||||
"제목": str(data.get("title") or ""),
|
||||
"부제": str(data.get("subtitle") or ""),
|
||||
"소재": str(data.get("material") or ""),
|
||||
"규격": str(data.get("size") or ""),
|
||||
"지금_본문": body.strip(),
|
||||
"지금_어투": "지금 본문의 어미를 물려받지 말고, 문장 종결 어미를 반드시 위 어투로 바꾼다",
|
||||
}, ensure_ascii=False, indent=2)
|
||||
|
||||
result = reg._ai_json(system, user)
|
||||
new_body = str((result.get("data") or {}).get("body") or "").strip()
|
||||
if not new_body:
|
||||
raise RuntimeError("AI가 본문을 만들지 못했습니다 — 다시 눌러 주세요")
|
||||
return {"ok": True, "slug": slug, "tone": tone, "tone_label": guide["label"],
|
||||
"before": body.strip(), "body": new_body, "tokens": result.get("tokens")}
|
||||
Reference in new issue
Block a user