| |
| """ |
| ์๋๋ฆฌ์ค ์์ฑ๊ธฐ ๊ณตํต ํฌํผ (๋ ์ด์ด ํ์ผ ์ถ๋ ฅ). |
| |
| build_<scenario>_scenario.py๊ฐ TAXโbuild_intents/actions/behavior_intents๋ก ๋ง๋ ์ฐ์ถ์ |
| engine ๋ ์ด์ด ํ์ผ์ ๊ธฐ๋กํ๋ค. L0๋ ์ ์ฒด ๊ต์ฒด, L3/L2๋ ํด๋น ํค๋ง ๊ต์ฒด(ํ์ ์น์
๋ณด์กด). |
| """ |
| from __future__ import annotations |
|
|
| import json |
| from pathlib import Path |
|
|
|
|
| def load_json(path: Path) -> dict: |
| return json.load(open(path, encoding="utf-8")) if path.exists() else {} |
|
|
|
|
| |
| |
| _INLINE_WIDTH = 100 |
|
|
|
|
| def compact_json(data, *, indent: int = 2, width: int = _INLINE_WIDTH) -> str: |
| """ |
| "ํญ(leaf) ๋จ์ ์ธ๋ผ์ธ" JSON ์ง๋ ฌํ. |
| |
| ํ์ค indent=2๋ ์์ ๋ฐฐ์ดยทleaf ๊ฐ์ฒด๊น์ง ํ ์์์ฉ ํผ์ณ ์์ ํ์
์ด ์ด๋ ต๋ค. |
| ์ด ํฌ๋งคํฐ๋ ๋
ธ๋๋ฅผ ๋จผ์ ํ ์ค(json.dumps)๋ก ๋ง๋ค์ด๋ณด๊ณ , width ์ดํ๋ฉด ์ธ๋ผ์ธ ์ ์ง, |
| ์ด๊ณผํ๋ฉด dict/list์ ์์๋ณ๋ก ์ค๋ฐ๊ฟ ํผ์น๋ค. โ terms/steps/rule ๋งต ๊ฐ์ ๊ตฌ์กฐ๋ |
| ํญ๋น ํ ์ค, linear[1,0]ยท์์ leaf ๊ฐ์ฒด๋ ํ ์ค๋ก ๋ชจ์ธ๋ค. (๊ฐ์ ํ์ค๊ณผ 1:1 ๋์ผ) |
| """ |
| def fmt(node, level: int) -> str: |
| pad = " " * (indent * level) |
| child_pad = " " * (indent * (level + 1)) |
|
|
| |
| inline = json.dumps(node, ensure_ascii=False, separators=(", ", ": ")) |
| if not isinstance(node, (dict, list)) or len(pad) + len(inline) <= width: |
| return inline |
|
|
| if isinstance(node, dict): |
| if not node: |
| return "{}" |
| items = [f'{child_pad}{json.dumps(k, ensure_ascii=False)}: {fmt(v, level + 1)}' |
| for k, v in node.items()] |
| return "{\n" + ",\n".join(items) + "\n" + pad + "}" |
|
|
| |
| if not node: |
| return "[]" |
| items = [child_pad + fmt(v, level + 1) for v in node] |
| return "[\n" + ",\n".join(items) + "\n" + pad + "]" |
|
|
| return fmt(data, 0) |
|
|
|
|
| def dump_json(path: Path, data: dict) -> None: |
| path.parent.mkdir(parents=True, exist_ok=True) |
| path.write_text(compact_json(data) + "\n", encoding="utf-8") |
| print(f"Wrote {path}") |
|
|
|
|
| def emit_layers(eng_dir: Path, *, taxonomy: dict, context_library: dict, behavior_signals: dict) -> None: |
| """ |
| L0_taxonomy.json ์ ์ฒด ๊ต์ฒด + L3_serving.json์ context_library + L2_inference.json์ |
| ranker.behavior_signals ํค๋ง ๊ต์ฒด(context_manager/action_signal/calibrator ๋ฑ ํ์ ๋ณด์กด). |
| """ |
| dump_json(eng_dir / "L0_taxonomy.json", taxonomy) |
|
|
| l3 = load_json(eng_dir / "L3_serving.json") |
| l3["context_library"] = context_library |
| dump_json(eng_dir / "L3_serving.json", l3) |
|
|
| l2 = load_json(eng_dir / "L2_inference.json") |
| l2.setdefault("ranker", {})["behavior_signals"] = behavior_signals |
| dump_json(eng_dir / "L2_inference.json", l2) |
|
|