Files
Negotiation_daegu/server/services/cards/completer.py
T
민헌andClaude Fable 5 dfb9ad6e66 초기 커밋 — 협상 AI 에이전트 정본: 엔진·데모 콘솔·측정 인프라·증빙
- 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
2026-08-31 13:09:52 +09:00

41 lines
1.5 KiB
Python

"""협상 카드 스크립트 완성 — 템플릿 + card_data 치환."""
from typing import Optional
from common.textutil import hide_unresolved_lines, safe_format
from router.v1.nego.protocol import NegotiationCardData
from services.cards.repository import CardScriptRepository
class CardScriptCompleter:
"""
1. Repository에서 카드 스크립트 템플릿을 가져온다.
2. 입력받은 CardData로 템플릿을 완성한다.
3. 값이 없는 변수가 포함된 문장은 숨긴다.
"""
def __init__(self, repository: CardScriptRepository):
self.repository = repository
def execute(self, card_id: str,
card_data: Optional[NegotiationCardData] = None) -> Optional[str]:
card = self.repository.find_by_id(card_id)
if not card:
return None
raw_script = card.get("script", "")
# 컨텍스트 구성 — None 값 제외, 숫자는 천단위 콤마
context = {}
if card_data is not None:
for k, v in card_data.model_dump().items():
if v is None:
continue
# 경쟁사 가격차는 최소 1% 표기 (0.x% 압박은 무의미)
if k == "competitor_price_diff" and isinstance(v, (int, float)) and v < 1:
v = 1
context[k] = f"{v:,.0f}" if isinstance(v, (int, float)) else str(v)
completed = safe_format(raw_script, context)
return hide_unresolved_lines(completed, source=card_id)