okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
53623e56f
main
1#!/usr/bin/env python3 2"""Small verifiable coding check: the model writes a function, a fixed test suite runs it locally. 3 4python coding_check.py --url http://127.0.0.1:18096 --out coding-check.json 5""" 6import argparse 7import json 8import re 9import time 10import urllib .request 11 12TASK = ("Write a Python function `roman_to_int(s: str) -> int` that converts a Roman numeral (I, V, X, L, C, D, M, " 13"including subtractive forms like IV, IX, XL, XC, CD, CM) to an integer, and raises ValueError for an empty " 14"string or any character that is not a Roman numeral. Reply with one Python code block only." ) 15TESTS = [("III" ,3 ), ("IV" ,4 ), ("IX" ,9 ), ("LVIII" ,58 ), ("MCMXCIV" ,1994 ), ("MMXXVI" ,2026 ), ("CDXLIV" ,444 )] 16ERRORS = ["" ,"ABC" ,"MMX1" ] 17 18 19def main (): 20ap = argparse .ArgumentParser () 21ap .add_argument ("--url" ,default = "http://127.0.0.1:18096" ) 22ap .add_argument ("--out" ,default = "coding-check.json" ) 23ap .add_argument ("--effort" ,default = "low" ) 24a = ap .parse_args () 25body = {"model" :"strata" ,"messages" : [{"role" :"user" ,"content" :TASK }],"temperature" :0 , 26"reasoning_effort" :a .effort ,"max_tokens" :4096 } 27t0 = time .perf_counter () 28req = urllib .request .Request (a .url + "/v1/chat/completions" ,data = json .dumps (body ).encode (), 29headers = {"Content-Type" :"application/json" }) 30with urllib .request .urlopen (req ,timeout = 900 )as r : 31answer = json .loads (r .read ()) 32elapsed = time .perf_counter ()- t0 33text = answer ["choices" ][0 ]["message" ].get ("content" )or "" 34m = re .search (r"```(?:python)?\n(.*?)```" ,text ,re .S ) 35code = m .group (1 )if m else text 36results ,passed = [],0 37namespace = {} 38try : 39exec (compile (code ,"<model>" ,"exec" ),namespace ) 40f = namespace ["roman_to_int" ] 41for s ,want in TESTS : 42got = f (s ) 43ok = got == want 44passed += ok 45results .append ({"input" :s ,"expected" :want ,"got" :got ,"ok" :ok }) 46for s in ERRORS : 47try : 48f (s ) 49results .append ({"input" :s ,"expected" :"ValueError" ,"got" :"no error" ,"ok" :False }) 50except ValueError : 51passed += 1 52results .append ({"input" :s ,"expected" :"ValueError" ,"got" :"ValueError" ,"ok" :True }) 53except Exception as e : 54results .append ({"error" :repr (e )}) 55total = len (TESTS )+ len (ERRORS ) 56out = {"task" :TASK ,"reasoning_effort" :a .effort ,"elapsed_s" :round (elapsed ,2 ),"usage" :answer .get ("usage" ), 57"passed" :passed ,"total" :total ,"results" :results ,"code" :code } 58with open (a .out ,"w" ,encoding = "utf-8" )as fh : 59json .dump (out ,fh ,indent = 2 ) 60f"coding check: { passed } / { total } tests passed in { elapsed :.1f } s" ) 61 62 63if __name__ == "__main__" : 64main ()