초기 커밋 — 협상 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
This commit is contained in:
commit
dfb9ad6e66
268 files changed
+164241
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,40 @@
|
||||
"""협상 카드 스크립트 완성 — 템플릿 + 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)
|
||||
@@ -0,0 +1,56 @@
|
||||
"""Action-Card 매핑 — Q-Table action_id ↔ 협상 카드 card_id."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional
|
||||
|
||||
from common.paths import RESOURCES_DIR
|
||||
|
||||
|
||||
class ActionCardMapper:
|
||||
"""
|
||||
action_id (0, 1, 2, ...) ↔ card_id ("NC26-000", ...)
|
||||
|
||||
Q_Table은 추상적인 action_id만 다루고, 카드 저장소는 card_id만 다룬다.
|
||||
매핑은 resources/policy/action_card_mapping.json 에서 로드된다.
|
||||
"""
|
||||
|
||||
def __init__(self, mapping_file: Optional[str] = None):
|
||||
if mapping_file is None:
|
||||
mapping_file = RESOURCES_DIR / "policy" / "action_card_mapping.json"
|
||||
|
||||
self.mapping_file = Path(mapping_file)
|
||||
self.action_to_card: Dict[int, str] = {}
|
||||
self.card_to_action: Dict[str, int] = {}
|
||||
self._load_mapping()
|
||||
|
||||
def _load_mapping(self):
|
||||
if not self.mapping_file.exists():
|
||||
raise FileNotFoundError(f"Mapping file not found: {self.mapping_file}")
|
||||
|
||||
with open(self.mapping_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
self.action_to_card = {int(k): v for k, v in data["action_to_card"].items()}
|
||||
self.card_to_action = {v: int(k) for k, v in data["action_to_card"].items()}
|
||||
|
||||
def get_card_id(self, action_id: int) -> Optional[str]:
|
||||
return self.action_to_card.get(action_id)
|
||||
|
||||
def get_action_id(self, card_id: str) -> Optional[int]:
|
||||
return self.card_to_action.get(card_id)
|
||||
|
||||
def get_action_space_size(self) -> int:
|
||||
return len(self.action_to_card)
|
||||
|
||||
def get_all_card_ids(self) -> list:
|
||||
return [self.action_to_card[i] for i in sorted(self.action_to_card.keys())]
|
||||
|
||||
def reload(self):
|
||||
self._load_mapping()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"ActionCardMapper(action_space_size={self.get_action_space_size()}, "
|
||||
f"mapping_file={self.mapping_file})"
|
||||
)
|
||||
@@ -0,0 +1,45 @@
|
||||
"""협상 카드 스크립트 Repository — JSON 파일 기반 (DB 없음)."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from common.paths import RESOURCES_DIR
|
||||
|
||||
|
||||
class CardScriptRepository:
|
||||
"""협상 카드 스크립트를 resources/cards/nego_card.json 에서 관리한다."""
|
||||
|
||||
def __init__(self, json_file_path: Optional[str] = None):
|
||||
if json_file_path is None:
|
||||
json_file_path = RESOURCES_DIR / "cards" / "nego_card.json"
|
||||
self.json_file_path = Path(json_file_path)
|
||||
self._ensure_file_exists()
|
||||
|
||||
def _ensure_file_exists(self):
|
||||
if not self.json_file_path.exists():
|
||||
self.json_file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self._save_to_file({"cards": []})
|
||||
|
||||
def _load_from_file(self) -> Dict:
|
||||
with open(self.json_file_path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
def _save_to_file(self, data: Dict):
|
||||
with open(self.json_file_path, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
|
||||
def find_all(self) -> List[Dict]:
|
||||
return self._load_from_file().get("cards", [])
|
||||
|
||||
def find_by_id(self, card_id: str) -> Optional[Dict]:
|
||||
for card in self.find_all():
|
||||
if card.get("card_id") == card_id:
|
||||
return card
|
||||
return None
|
||||
|
||||
def exists(self, card_id: str) -> bool:
|
||||
return self.find_by_id(card_id) is not None
|
||||
|
||||
def count(self) -> int:
|
||||
return len(self.find_all())
|
||||
Reference in new issue
Block a user