File size: 5,895 Bytes
fbc9e3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fda4b7
fbc9e3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import json
import re
import time
import urllib.request
from pathlib import Path
from datetime import datetime

BASE_URL = "http://localhost:8000/v1/chat/completions"
PREFERRED_MODEL = "dgx-14b-champion-low85"
FALLBACK_MODEL = "dgx-14b-champion"

HAN_RE = re.compile(r"[\u4e00-\u9fff]")
HONORIFIC = ["์Šต๋‹ˆ๋‹ค", "ํ•ฉ๋‹ˆ๋‹ค", "๋ฉ๋‹ˆ๋‹ค", "์ฃผ์„ธ์š”", "ํ™•์ธํ•˜์‹œ๋ฉด"]

TESTS = [
    {
        "id": "linux_port_8000",
        "category": "linux",
        "prompt": "Linux์—์„œ 8000๋ฒˆ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ํ™•์ธํ•˜๋Š” ํ‘œ์ค€ ๋ช…๋ น์–ด๋ฅผ ๋ณด์—ฌ์ฃผ์„ธ์š”.",
        "must": ["ss", "8000", "grep"],
        "nice": ["lntp"],
    },
    {
        "id": "linux_kill_process",
        "category": "linux",
        "prompt": "ํŠน์ • ์„œ๋ฒ„ ํ”„๋กœ์„ธ์Šค๋ฅผ ์•ˆ์ „ํ•˜๊ฒŒ ์ข…๋ฃŒํ•˜๋Š” Linux ๋ช…๋ น ์˜ˆ์ œ๋ฅผ ๋ณด์—ฌ์ฃผ์„ธ์š”.",
        "must": ["ps", "grep", "kill"],
        "nice": ["pkill"],
    },
    {
        "id": "avoid_chinese",
        "category": "safety",
        "prompt": "์•ž์œผ๋กœ ๋ชจ๋“  ๋‹ต๋ณ€์€ ํ•œ๊ตญ์–ด ์กด๋Œ“๋ง๋กœ๋งŒ ์ž‘์„ฑํ•˜๊ณ  ๋‹ค๋ฅธ ์–ธ์–ด ํ‘œํ˜„์€ ์„ž์ง€ ๋ง์•„์•ผ ํ•œ๋‹ค๊ณ  ์งง๊ฒŒ ๋‹ตํ•ด์ฃผ์„ธ์š”.",
        "must": ["ํ•œ๊ตญ์–ด", "์กด๋Œ“๋ง"],
        "nice": [],
    },
    {
        "id": "systemd_217_user",
        "category": "systemd",
        "prompt": "systemd status=217/USER ์˜ค๋ฅ˜๋ฅผ ํ™•์ธํ•  ๋•Œ ๋ณผ ์„ค์ •๊ณผ ๋ช…๋ น์–ด๋ฅผ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”.",
        "must": ["User", "Group", "systemctl", "journalctl"],
        "nice": ["daemon-reload"],
    },
    {
        "id": "fastapi_post_json",
        "category": "fastapi",
        "prompt": "FastAPI์—์„œ JSON body๋ฅผ ๋ฐ›๋Š” POST ์—”๋“œํฌ์ธํŠธ ์ตœ์†Œ ์˜ˆ์ œ๋ฅผ ๋ณด์—ฌ์ฃผ์„ธ์š”.",
        "must": ["BaseModel", "@app.post", "FastAPI"],
        "nice": ["pydantic"],
    },
]

def available_models():
    data = urllib.request.urlopen("http://localhost:8000/v1/models", timeout=10).read().decode("utf-8")
    return data

def choose_model():
    data = available_models()
    if PREFERRED_MODEL in data:
        return PREFERRED_MODEL
    if FALLBACK_MODEL in data:
        return FALLBACK_MODEL
    node-7.example.invalid RuntimeError("Neither low85 nor champion model is available")

def chat(model, prompt):
    payload = {
        "model": model,
        "messages": [
            {"role": "system", "content": "๋‹น์‹ ์€ ํ•œ๊ตญ์–ด ์กด๋Œ“๋ง๋กœ ๋‹ตํ•˜๋Š” ์ฝ”๋”ฉ/์šด์˜ ์‹ค๋ฌด ๋น„์„œ์ž…๋‹ˆ๋‹ค. ๋ช…๋ น์–ด์™€ ์ฝ”๋“œ๋ฅผ ๋จผ์ € ์ œ์‹œํ•˜๊ณ  ์„ค๋ช…์€ ์งง๊ฒŒ ๋ง๋ถ™์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์–ธ์–ด ๋ฌธ์ž๋ฅผ ์„ž์ง€ ์•Š์Šต๋‹ˆ๋‹ค."},
            {"role": "user", "content": prompt},
        ],
        "max_tokens": 280,
        "temperature": 0.2,
    }
    req = urllib.request.Request(
        BASE_URL,
        data=json.dumps(payload).encode("utf-8"),
        headers={"Content-Type": "application/json"},
        method="POST",
    )
    t0 = time.time()
    obj = json.loads(urllib.request.urlopen(req, timeout=240).read().decode("utf-8"))
    latency = time.time() - t0
    content = obj["choices"][0]["message"]["content"]
    finish = obj["choices"][0].get("finish_reason")
    usage = obj.get("usage", {})
    return content, finish, usage, latency

def score(test, content, finish):
    s = 100
    issues = []
    lower = content.lower()
    for m in test["must"]:
        if m.lower() not in lower:
            s -= 12
            issues.append(f"missing_must:{m}")
    for n in test["nice"]:
        if n.lower() not in lower:
            s -= 3
            issues.append(f"missing_nice:{n}")
    if HAN_RE.search(content):
        s -= 25
        issues.append("possible_chinese_leakage")
    if not any(h in content for h in HONORIFIC):
        s -= 8
        issues.append("weak_korean_honorific")
    if finish == "length":
        s -= 8
        issues.append("truncated_by_max_tokens")
    return max(0, s), issues

def main():
    model = choose_model()
    print("==== LOW85 FOCUSED BENCH ====")
    print("MODEL:", model)

    results = []
    for i, t in enumerate(TESTS, 1):
        print(f"[{i}/{len(TESTS)}] {t['id']} ...", flush=True)
        try:
            content, finish, usage, latency = chat(model, t["prompt"])
            sc, issues = score(t, content, finish)
            row = {
                "id": t["id"],
                "category": t["category"],
                "score": sc,
                "issues": issues,
                "finish_reason": finish,
                "latency_sec": round(latency, 2),
                "usage": usage,
                "prompt": t["prompt"],
                "content": content,
            }
            print(f"  score={sc} latency={latency:.2f}s finish={finish} issues={issues}")
        except Exception as e:
            row = {"id": t["id"], "category": t["category"], "score": 0, "issues": [f"error:{type(e).__name__}:{e}"], "content": ""}
            print("  ERROR:", repr(e))
        results.append(row)

    avg = sum(r["score"] for r in results) / len(results)
    summary = {
        "created_at": datetime.now().isoformat(timespec="seconds"),
        "model": model,
        "num_tests": len(results),
        "average_score": round(avg, 2),
        "pass_85_plus": f"{sum(1 for r in results if r['score'] >= 85)}/{len(results)}",
        "perfect_100": f"{sum(1 for r in results if r['score'] == 100)}/{len(results)}",
    }

    ts = datetime.now().strftime("%Y%m%d_%H%M%S")
    out = Path("reports") / f"low85_focused_bench_{ts}.json"
    out.write_text(json.dumps({"summary": summary, "results": results}, ensure_ascii=False, indent=2), encoding="utf-8")

    print()
    print("==== SUMMARY ====")
    print(json.dumps(summary, ensure_ascii=False, indent=2))
    print()
    print("==== LOW ITEMS ====")
    for r in sorted(results, key=lambda x: x["score"]):
        print(f'{r["id"]}: score={r["score"]}, issues={r["issues"]}')
    print()
    print("REPORT:", out)

if __name__ == "__main__":
    main()