- server/: FastAPI 협상 엔진 (5라운드, Q-Table/UCB, 페르소나 계측, :53117) - frontend/: 데모 콘솔 (React+Tailwind → nginx, /api 프록시) - eval/·testdata/: 지표 8종 측정 하네스 + 재현 가능 테스트셋 - results/: 측정 증빙 (지표별 result+provenance, raw 원본 동결+SHA256) ① 86.0 · ② 76.0 · ③ 5.99% · ⑥ p95 3.61ms · ⑦ 611만/년 · ⑧ 91/100 · ⑨ 99.71 · ⑩ 97.99 - docker-compose.yml + run.sh: backend+frontend 일괄 기동 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0112XUWF4bc3gGrEt8vsYCzy
62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
"""ScriptModifier — LLM으로 협상 스크립트의 톤을 상황·상대 성향에 맞게 재작성한다.
|
|
|
|
평문 입출력. {변수} 플레이스홀더는 보존해야 하며, 검증은 verifier가 담당한다.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Optional
|
|
|
|
from openai import OpenAI
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
_SYSTEM_PROMPT = """You are an expert Negotiation Script Editor.
|
|
Rewrite the provided Korean negotiation script to match the requested tone/context.
|
|
|
|
Rules:
|
|
1. **Preserve Variables**: Do NOT change, remove, or add any {placeholder} variables. \
|
|
Only use variables that exist in the input.
|
|
2. **Preserve Meaning**: Keep every factual statement and number intact. \
|
|
Only adjust tone, phrasing, and flow.
|
|
3. **Language**: The output MUST be in Korean (Hangul).
|
|
4. **Plain Text Only**: Output ONLY the rewritten script text. \
|
|
No markdown, no code fences, no explanations.
|
|
5. Keep the line structure similar to the input (one thought per line)."""
|
|
|
|
_USER_TEMPLATE = """Original Script:
|
|
{script}
|
|
|
|
Context/Instructions:
|
|
{context}
|
|
|
|
Rewritten script:"""
|
|
|
|
|
|
class ScriptModifier:
|
|
def __init__(self, api_key: str, model: str = "gpt-4o"):
|
|
self.client = OpenAI(api_key=api_key)
|
|
self.model = model
|
|
|
|
def modify_script(self, script: str, context: dict = None) -> Optional[str]:
|
|
"""스크립트 톤 재작성. 실패 시 None을 반환한다 (호출측에서 원문 유지)."""
|
|
if not script or not script.strip():
|
|
return None
|
|
try:
|
|
response = self.client.chat.completions.create(
|
|
model=self.model,
|
|
temperature=0,
|
|
messages=[
|
|
{"role": "system", "content": _SYSTEM_PROMPT},
|
|
{"role": "user", "content": _USER_TEMPLATE.format(
|
|
script=script, context=str(context or {}))},
|
|
],
|
|
)
|
|
text = (response.choices[0].message.content or "").strip()
|
|
# 혹시 모를 코드펜스 제거
|
|
if text.startswith("```"):
|
|
text = text.strip("`").strip()
|
|
return text or None
|
|
except Exception as e:
|
|
logger.error(f"[ScriptModifier] LLM 호출 실패: {e}")
|
|
return None
|