Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/bench/inference_cost/fake_model.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / bench / inference_cost / fake_model.om` 465 lines ยท 9341 bytes Raw Blame History 1 note bench/inference_cost/fake_model.om -- a deterministic stand-in for an OpenAI 2 note chat-completions endpoint, so driver.sh --self-test can exercise --run-model end to end 3 note without a live model. 4 note Compose: { printf 'om2\n'; cat seed/json/json.om seed/json/jsonw.om seed/net/http.om seed/net/notls.om bench/inference_cost/fake_model.om; } | omc 5 note Run: fake_model MODE TASKSDIR [MAXCONN]; it listens on an ephemeral 127.0.0.1 port, 6 note prints "PORT n" and serves POST /v1/chat/completions until MAXCONN connections 7 note (default 1000) or 30 s without one. The request names its task and language in the 8 note headers X-Bench-Task and X-Bench-Lang (1..16 bytes of [a-z0-9]); the body must be a 9 note JSON object with a "messages" array. The reply's content is one fenced block holding 10 note TASKSDIR/TASK/reference.LANG or TASKSDIR/TASK/mutant.LANG: 11 note good the reference 12 note bad the mutant (it compiles and returns wrong results) 13 note bad-then-good the mutant while the request has fewer than 3 messages, else the 14 note reference: a retry that carries the failed answer and feedback verifies 15 note refuse a text that compiles in no language 16 note busy the 1st, 3rd, 5th... chat request answers 503 with an empty body (what the 17 note live server answers while it generates another reply), the others as good 18 note down every chat request answers 503 with an empty body 19 note Every reply reports model "fake-omega-bench" and usage 111 / 37 / 148 tokens, so a run's 20 note token sums are exact multiples of the call count. Missing or bad headers, a body that 21 note is not such an object, or a missing file answer 400 / 404 with an empty body. 22 global fkmode ulong 1 23 global fkcnt ulong 1 24 global fkdir uchar 4096 25 global fkdirn ulong 1 26 global fkpath uchar 4400 27 global fkfile uchar 65536 28 global fkfilen ulong 1 29 global fklang uchar 16 30 global fklangn ulong 1 31 text fkgood "good" 32 text fkbad "bad" 33 text fkbtg "bad-then-good" 34 text fkrefm "refuse" 35 text fkbusy "busy" 36 text fkdown "down" 37 text fkchat "/v1/chat/completions" 38 text fkpost "POST" 39 text fkhtask "X-Bench-Task" 40 text fkhlang "X-Bench-Lang" 41 text fkmsgs "messages" 42 text fkref "reference." 43 text fkmut "mutant." 44 text fkslash "/" 45 text fkrefus "@@@ not a program @@@\n" 46 text fkfence "```" 47 text fknl "\n" 48 text fkctype "Content-Type" 49 text fkjson "application/json" 50 text fkid "id" 51 text fkidv "fake-omega-bench-1" 52 text fkobj "object" 53 text fkobjv "chat.completion" 54 text fkmodel "model" 55 text fkmodv "fake-omega-bench" 56 text fkchoic "choices" 57 text fkindex "index" 58 text fkmessg "message" 59 text fkrole "role" 60 text fkasst "assistant" 61 text fkcont "content" 62 text fkfin "finish_reason" 63 text fkstop "stop" 64 text fkusage "usage" 65 text fkptok "prompt_tokens" 66 text fkctok "completion_tokens" 67 text fkttok "total_tokens" 68 text fkportl "PORT " 69 70 note fk_text: append the bytes of t to fkpath at p; the new end 71 fn fk_text t view uchar * p ulong to ulong 72 n = len t 73 for i ulong n 74 put fkpath add p i get t i 75 end 76 ret add p n 77 end 78 79 note fk_namec: c is in [a-z0-9] 80 fn fk_namec c uchar to bool 81 if and ge c 97 le c 122 82 ret true 83 end 84 ret and ge c 48 le c 57 85 end 86 87 note fk_hcopy: append header value i (1..16 bytes of [a-z0-9]) to fkpath at p; the new end, 88 note or 0 when the value is not such a name 89 fn fk_hcopy cs edit ulong * io edit uchar * i ulong p ulong to ulong 90 o = hhvoff cs i 91 n = hhvlen cs i 92 if or eq n 0 gt n 16 93 ret 0 94 end 95 for j ulong n 96 c = get io add o j 97 if not fk_namec c 98 ret 0 99 end 100 put fkpath add p j c 101 end 102 ret add p n 103 end 104 105 note fk_dir: fkpath = DIR/ ; the length 106 fn fk_dir to ulong 107 p = get fkdirn 0 108 for i ulong p 109 put fkpath i get fkdir i 110 end 111 ret fk_text fkslash p 112 end 113 114 note fk_setlang: fklang = fkpath[s..p) 115 fn fk_setlang s ulong p ulong to void 116 for i ulong sub p s 117 put fklang i get fkpath add s i 118 end 119 put fklangn 0 sub p s 120 end 121 122 note fk_path: fkpath = DIR/TASK/(reference.|mutant.)LANG for sel 1 / 0, the language 123 note into fklang; the path length or 0 for a missing or bad header 124 fn fk_path cs edit ulong * io edit uchar * sel ulong to ulong 125 ti = hhfind cs io fkhtask 126 if lt ti 0 127 ret 0 128 end 129 p = fk_dir 130 p = fk_hcopy cs io ulong ti p 131 if eq p 0 132 ret 0 133 end 134 p = fk_text fkslash p 135 if eq sel 1 136 p = fk_text fkref p 137 else 138 p = fk_text fkmut p 139 end 140 li = hhfind cs io fkhlang 141 if lt li 0 142 ret 0 143 end 144 s = p 145 p = fk_hcopy cs io ulong li p 146 if eq p 0 147 ret 0 148 end 149 fk_setlang s p 150 ret p 151 end 152 153 note fk_load: read fkpath[0..n) into fkfile; false when it cannot be read whole 154 fn fk_load n ulong to bool 155 fd = fopen fkpath 0 n 0 0 156 if lt fd 0 157 ret false 158 end 159 got = ulong 0 160 note every pass adds at least one byte or leaves the loop 161 while lt got 65536 bound 70000 162 k = read int fd fkfile got sub 65536 got 163 if le k 0 164 break 165 end 166 got = add got ulong k 167 end 168 c = fclose int fd 169 put fkfilen 0 got 170 ret lt got 65536 171 end 172 173 note fk_nmsgs: the element count of the root object's "messages" array, jsnone when absent 174 fn fk_nmsgs s view uchar * t view uint * to ulong 175 if ne js_type t 0 jsobj 176 ret jsnone 177 end 178 m = js_first t 0 179 while ne m jsnone 180 if js_streq s js_off t m fkmsgs 181 v = add m 1 182 if ne js_type t v jsarr 183 ret jsnone 184 end 185 ret js_nkids t v 186 end 187 m = js_mnext t m 188 end 189 ret jsnone 190 end 191 192 fn fk_key ob edit uchar * t view uchar * to void 193 js_wsbuf ob t 0 len t 194 end 195 196 note fk_content: the content string: one fence around fkfile (sel 0 or 1) or the refusal (2) 197 fn fk_content ob edit uchar * sel ulong to void 198 js_wsbeg ob 199 for i ulong len fkfence 200 js_wsb ob get fkfence i 201 end 202 if ne sel 2 203 for i ulong get fklangn 0 204 js_wsb ob get fklang i 205 end 206 end 207 js_wsb ob 10 208 if eq sel 2 209 for i ulong len fkrefus 210 js_wsb ob get fkrefus i 211 end 212 else 213 for i ulong get fkfilen 0 214 js_wsb ob get fkfile i 215 end 216 end 217 for i ulong len fkfence 218 js_wsb ob get fkfence i 219 end 220 js_wsb ob 10 221 js_wsend ob 222 end 223 224 note fk_send: the 200 reply carrying content sel 225 fn fk_send cs edit ulong * io edit uchar * sel ulong to long 226 ob = new uchar 525328 0 227 r = js_winit ob 228 if lt r 0 229 ret hrsperr cs io 500 230 end 231 js_wobj ob 232 fk_key ob fkid 233 fk_key ob fkidv 234 fk_key ob fkobj 235 fk_key ob fkobjv 236 fk_key ob fkmodel 237 fk_key ob fkmodv 238 fk_key ob fkchoic 239 js_warr ob 240 js_wobj ob 241 fk_key ob fkindex 242 js_wulong ob 0 243 fk_key ob fkmessg 244 js_wobj ob 245 fk_key ob fkrole 246 fk_key ob fkasst 247 fk_key ob fkcont 248 fk_content ob sel 249 js_wobje ob 250 fk_key ob fkfin 251 fk_key ob fkstop 252 js_wobje ob 253 js_warre ob 254 fk_key ob fkusage 255 js_wobj ob 256 fk_key ob fkptok 257 js_wulong ob 111 258 fk_key ob fkctok 259 js_wulong ob 37 260 fk_key ob fkttok 261 js_wulong ob 148 262 js_wobje ob 263 js_wobje ob 264 jl = js_wdone ob 265 if lt jl 0 266 ret hrsperr cs io 500 267 end 268 r = hrspst cs io 200 269 r = hfe r hhname cs io fkctype 270 r = hfe r hhval cs io fkjson 271 r = hfe r hhend cs io 0 ulong jl 272 r = hfe r hput cs io view part ob jswh ulong jl 273 ret hfe r hwfin cs io 274 end 275 276 note fk_chat: one POST /v1/chat/completions 277 fn fk_chat cs edit ulong * io edit uchar * to long 278 body = new uchar 983040 0 279 tape = new uint 65536 0 280 put cs HBCAP 983040 281 n = hbodyall cs io body 282 if lt n 0 283 if eq n HEBIG 284 ret hrsperr cs io 413 285 end 286 ret hrsperr cs io 400 287 end 288 if eq n 0 289 ret hrsperr cs io 400 290 end 291 r = js_init tape ulong n 64 292 if lt r 0 293 ret hrsperr cs io 400 294 end 295 r = js_parse body tape ulong n 296 if lt r 0 297 ret hrsperr cs io 400 298 end 299 nm = fk_nmsgs body tape 300 if or eq nm jsnone eq nm 0 301 ret hrsperr cs io 400 302 end 303 md = get fkmode 0 304 if eq md 5 305 ret hrsperr cs io 503 306 end 307 if eq md 4 308 k = get fkcnt 0 309 put fkcnt 0 add k 1 310 if eq rem k 2 0 311 ret hrsperr cs io 503 312 end 313 end 314 sel = ulong 1 315 if eq md 1 316 sel = 0 317 end 318 if and eq md 2 lt nm 3 319 sel = 0 320 end 321 p = fk_path cs io sel 322 if eq p 0 323 ret hrsperr cs io 400 324 end 325 if eq md 3 326 ret fk_send cs io 2 327 end 328 if not fk_load p 329 ret hrsperr cs io 404 330 end 331 ret fk_send cs io sel 332 end 333 334 fn fk_serve1 lf int cs edit ulong * io edit uchar * to long 335 c = haccept lf `30000000000` 336 if lt c 0 337 ret c 338 end 339 r = hinit cs io int c 1 340 if lt r 0 341 x = hclose cs 342 ret 0 343 end 344 hsettmo cs `10000000000` `10000000000` 345 hsetbdl cs `20000000000` 346 for it ulong 100 347 r = hreqrd cs io 348 if le r 0 349 if lt r 0 350 x = hreject cs io r 351 end 352 break 353 end 354 if hispath cs io fkchat 355 if hismeth cs io fkpost 356 r = fk_chat cs io 357 else 358 r = hrsperr cs io 405 359 end 360 else 361 r = hrsperr cs io 404 362 end 363 if lt r 0 364 break 365 end 366 if eq hnext cs io 0 367 break 368 end 369 end 370 r = hclose cs 371 ret 0 372 end 373 374 fn fk_putport v ulong to void 375 d = new uchar 32 0 376 for i ulong len fkportl 377 put d i get fkportl i 378 end 379 q = new uchar 24 0 380 i = ulong 24 381 x = v 382 for it ulong 21 383 i = sub i 1 384 put q i uchar add rem x 10 48 385 x = div x 10 386 if eq x 0 387 break 388 end 389 end 390 p = len fkportl 391 for j ulong sub 24 i 392 put d add p j get q add i j 393 end 394 p = add p sub 24 i 395 put d p 10 396 w = write 1 d 0 add p 1 397 end 398 399 fn main to int 400 cs = new ulong 320 0 401 io = new uchar 131072 0 402 a = new uchar 16 0 403 ab = new uchar 32 0 404 na = argcnt 405 if or lt na 3 gt na 4 406 ret 2 407 end 408 n = argread 1 ab 0 32 409 if lt n 0 410 ret 2 411 end 412 md = ulong 9 413 if heq view part ab 0 ulong n fkgood 414 md = 0 415 end 416 if heq view part ab 0 ulong n fkbad 417 md = 1 418 end 419 if heq view part ab 0 ulong n fkbtg 420 md = 2 421 end 422 if heq view part ab 0 ulong n fkrefm 423 md = 3 424 end 425 if heq view part ab 0 ulong n fkbusy 426 md = 4 427 end 428 if heq view part ab 0 ulong n fkdown 429 md = 5 430 end 431 if eq md 9 432 ret 2 433 end 434 put fkmode 0 md 435 n = argread 2 fkdir 0 4000 436 if or le n 0 ge n 4000 437 ret 2 438 end 439 put fkdirn 0 ulong n 440 mc = ulong 1000 441 if eq na 4 442 n = argread 3 ab 0 32 443 if le n 0 444 ret 2 445 end 446 if not hdigits view part ab 0 ulong n 447 ret 2 448 end 449 mc = hdecv view part ab 0 ulong n 450 end 451 r = haddr4 a `2130706433` 0 452 lf = hlisten a 16 453 if lt lf 0 454 ret 3 455 end 456 fk_putport hport a 457 for i ulong mc 458 r = fk_serve1 int lf cs io 459 if lt r 0 460 break 461 end 462 end 463 c = fclose int lf 464 ret 0 465 end