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()
|