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/seed/node/infer.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 / seed / node / infer.om` 609 lines ยท 13019 bytes Raw Blame History 1 note Omega Node inference adapter (DRA-290): one bounded completion from the 2 note own model's ollm serve (aien-train, DRA-119) over loopback, turned into a 3 note versioned typed record. Composition, OM-2: 4 note { printf 'om2\n'; cat seed/json/json.om seed/json/jsonw.om 5 note seed/net/http.om seed/net/notls.om seed/node/infer.om; } | omc 6 note Usage: omnode-infer PORT MAXTOK DEADLINE_S PROMPT [TESTOUT] 7 note It connects only to 127.0.0.1 (offline-local: no other host, no TLS, no 8 note credential) and refuses port 18091. POST /v1/completions with the prompt 9 note as the whole template, greedy (top_p 0), seed 1, stream false. TESTOUT 10 note is sent as ollm_test_output, which only a server started with test=1 11 note honours; the Node's workflow never passes it. 12 note The whole exchange (connect, request, generation, response) has one 13 note deadline. A caller cancels by killing the process group; the server 14 note sees the connection close and stops generating. 15 note Record on stdout, exit 0: one line 16 note OMNI1 kind fin ptok ctok plen olen nlen tlen 17 note then the path, old, new and raw text bytes back to back. kind: 1 18 note read_file, 2 omega_check, 3 replace_text, 4 the answer Tests passed., 19 note 5 the answer File not found., 9 the text is not a protocol action (the 20 note model's turn is returned, never repaired). fin: 1 stop, 2 length, 0 21 note other. The action is the text before the first newline-Done., trimmed, 22 note as the round40 repair protocol reads it: a JSON object of exactly 23 note {tool,path} for read_file and omega_check, or {tool,path,old,new} for 24 note replace_text; path 1..128 bytes, old 1..40, new 0..40, no NUL byte. 25 note Other exits: 2 usage, 3 prompt (1..3800 bytes, no NUL), 4 connect, 5 26 note deadline, 6 HTTP status other than 200 (OMNE1 status, then the body 27 note head, on stdout), 7 malformed response, 8 server busy (503) until less 28 note than 2 s of the deadline is left: a busy server (one request at a time, 29 note for example still stopping a cancelled one) is asked again every second. 30 text ipath "/v1/completions" 31 text imeth "POST" 32 text ihost "Host" 33 text ihostv "127.0.0.1" 34 text ictype "Content-Type" 35 text ijson "application/json" 36 text kmodel "model" 37 text vollm "ollm" 38 text kprompt "prompt" 39 text kmaxt "max_tokens" 40 text ktopp "top_p" 41 text kseed "seed" 42 text kstream "stream" 43 text ktout "ollm_test_output" 44 text kobj "object" 45 text vtcomp "text_completion" 46 text kchoi "choices" 47 text ktext "text" 48 text kfin "finish_reason" 49 text kusage "usage" 50 text kpt "prompt_tokens" 51 text kct "completion_tokens" 52 text vstop "stop" 53 text vlen "length" 54 text ktool "tool" 55 text kpath "path" 56 text kold "old" 57 text knew "new" 58 text tread "read_file" 59 text tcheck "omega_check" 60 text trepl "replace_text" 61 text apass "Tests passed." 62 text amiss "File not found." 63 text tdone "\nDone." 64 text irec "OMNI1 " 65 text ierr "OMNE1 " 66 67 note The decimal value of a[0, n), or -1 when it is not 1..9 digits. 68 fn ia_dec a view uchar * n ulong to long 69 if or eq n 0 gt n 9 70 ret neg long 1 71 end 72 v = ulong 0 73 for i ulong n 74 c = ulong get a i 75 if or lt c 48 gt c 57 76 ret neg long 1 77 end 78 v = add mul v 10 sub c 48 79 end 80 ret long v 81 end 82 83 note Argument i as a number, -1 when it is not one. 84 fn ia_num i ulong to long 85 b = new uchar 16 0 86 n = argread i b 0 16 87 if lt n 0 88 ret neg long 1 89 end 90 ret ia_dec b ulong n 91 end 92 93 note Append the decimal v to o at p; the new end. 94 fn ia_put o edit uchar 8192 p ulong v ulong to ulong 95 d = new uchar 24 0 96 k = ulong 0 97 x = v 98 for i ulong 24 99 put d k uchar add 48 rem x 10 100 k = add k 1 101 x = div x 10 102 if eq x 0 103 break 104 end 105 end 106 for j ulong k 107 put o add p j get d sub sub k j 1 108 end 109 ret add p k 110 end 111 112 note Append a[0, n) to o at p; the new end. 113 fn ia_cat o edit uchar 8192 p ulong a view uchar * s ulong n ulong to ulong 114 for i ulong n 115 put o add p i get a add s i 116 end 117 ret add p n 118 end 119 120 fn ia_out o view uchar 8192 n ulong to void 121 p = ulong 0 122 for it ulong 64 123 if ge p n 124 ret 125 end 126 r = write 1 o p sub n p 127 if le r 0 128 ret 129 end 130 p = add p ulong r 131 end 132 end 133 134 note The request body into ob (jsonw); its length, or a negative refusal. 135 fn ia_body ob edit uchar 16384 pr view uchar 4096 pn ulong mt ulong to long 136 tb = new uchar 4096 0 137 x = js_winit ob 138 js_wobj ob 139 js_wsbuf ob kmodel 0 len kmodel 140 js_wsbuf ob vollm 0 len vollm 141 js_wsbuf ob kprompt 0 len kprompt 142 js_wsbuf ob pr 0 pn 143 js_wsbuf ob kmaxt 0 len kmaxt 144 js_wulong ob mt 145 js_wsbuf ob ktopp 0 len ktopp 146 js_wulong ob 0 147 js_wsbuf ob kseed 0 len kseed 148 js_wulong ob 1 149 js_wsbuf ob kstream 0 len kstream 150 js_wbool ob false 151 if gt argcnt 5 152 tn = argread 5 tb 0 4096 153 if lt tn 0 154 ret neg long 1 155 end 156 js_wsbuf ob ktout 0 len ktout 157 js_wsbuf ob tb 0 ulong tn 158 end 159 js_wobje ob 160 ret js_wdone ob 161 end 162 163 note Connect, send the request, read the status. The status, or negative. 164 fn ia_send cs edit ulong 320 io edit uchar 131072 ob view uchar 16384 bn ulong port ulong dl long to long 165 a = new uchar 16 0 166 r = haddr4 a `2130706433` port 167 fd = hdial a `5000000000` 168 if lt fd 0 169 ret neg long 1000 170 end 171 r = hinit cs io int fd 0 172 hsettmo cs dl dl 173 hsetbdl cs dl 174 r = hreqst cs io imeth 175 r = hfe r hreqtg cs io ipath 176 r = hfe r hhname cs io ihost 177 r = hfe r hhval cs io ihostv 178 r = hfe r hhname cs io ictype 179 r = hfe r hhval cs io ijson 180 r = hfe r hhend cs io 0 bn 181 r = hfe r hput cs io view part ob 1040 bn 182 r = hfe r hwfin cs io 183 if lt r 0 184 ret r 185 end 186 ret hrsprd cs io 187 end 188 189 note Member key in object o of the parsed src, its value token or jsnone. 190 fn ia_mem src view uchar * tp view uint 65536 o ulong key view uchar * to ulong 191 if ne js_type tp o 1 192 ret jsnone 193 end 194 k = js_first tp o 195 for it ulong js_nkids tp o 196 if eq k jsnone 197 break 198 end 199 if js_streq src js_off tp k key 200 ret add k 1 201 end 202 k = js_mnext tp k 203 end 204 ret jsnone 205 end 206 207 note An unsigned member of object o, or -1. 208 fn ia_umem src view uchar 16384 tp view uint 65536 o ulong key view uchar * to long 209 v = ia_mem src tp o key 210 if eq v jsnone 211 ret neg long 1 212 end 213 if or ne js_type tp v 7 not js_isu src js_off tp v 214 ret neg long 1 215 end 216 ret long js_tou src js_off tp v 217 end 218 219 note fin from token v: 1 stop, 2 length, 0 other. 220 fn ia_fin src view uchar 16384 tp view uint 65536 v ulong to ulong 221 if eq v jsnone 222 ret 0 223 end 224 if ne js_type tp v 6 225 ret 0 226 end 227 if js_streq src js_off tp v vstop 228 ret 1 229 end 230 if js_streq src js_off tp v vlen 231 ret 2 232 end 233 ret 0 234 end 235 236 note Usage of the parsed response into m[2] prompt and m[3] completion 237 note tokens; false when either is missing. 238 fn ia_use rb view uchar 16384 tp view uint 65536 m edit ulong 8 to bool 239 us = ia_mem rb tp 0 kusage 240 pt = ia_umem rb tp us kpt 241 ct = ia_umem rb tp us kct 242 if or lt pt 0 lt ct 0 243 ret false 244 end 245 put m 2 ulong pt 246 put m 3 ulong ct 247 ret true 248 end 249 250 note The response body rb[0, rn): the text into tx, and m[0] text length, 251 note m[1] fin, m[2] prompt tokens, m[3] completion tokens. 0 or 7. 252 fn ia_resp rb view uchar 16384 rn ulong tx edit uchar 8192 m edit ulong 8 to ulong 253 tp = new uint 65536 0 254 x = js_init tp 16384 16 255 r = js_parse rb tp rn 256 if lt r 0 257 ret 7 258 end 259 ob = ia_mem rb tp 0 kobj 260 if or eq ob jsnone ne js_type tp ob 6 261 ret 7 262 end 263 if not js_streq rb js_off tp ob vtcomp 264 ret 7 265 end 266 ch = ia_mem rb tp 0 kchoi 267 if or eq ch jsnone ne js_type tp ch 3 268 ret 7 269 end 270 c0 = js_first tp ch 271 if eq c0 jsnone 272 ret 7 273 end 274 t = ia_mem rb tp c0 ktext 275 if or eq t jsnone ne js_type tp t 6 276 ret 7 277 end 278 n = js_sget rb js_off tp t tx 279 if lt n 0 280 ret 7 281 end 282 put m 0 ulong n 283 put m 1 ia_fin rb tp ia_mem rb tp c0 kfin 284 if not ia_use rb tp m 285 ret 7 286 end 287 ret 0 288 end 289 290 note true when tx[i, n) starts with a newline then Done. 291 fn ia_done tx view uchar 8192 i ulong n ulong to bool 292 if gt add i 6 n 293 ret false 294 end 295 for j ulong 6 296 if ne get tx add i j get tdone j 297 ret false 298 end 299 end 300 ret true 301 end 302 303 note The action text of tx[0, n): before the first newline-Done., trimmed of 304 note ASCII white space. Its start in m[4] and length in m[5]. 305 fn ia_trim tx view uchar 8192 n ulong m edit ulong 8 to void 306 e = n 307 for i ulong n 308 if ia_done tx i n 309 e = i 310 break 311 end 312 end 313 s = ulong 0 314 for j ulong e 315 if gt get tx s 32 316 break 317 end 318 s = add s 1 319 end 320 for k ulong sub e s 321 if gt get tx sub e 1 32 322 break 323 end 324 e = sub e 1 325 end 326 put m 4 s 327 put m 5 sub e s 328 end 329 330 note true when tx[s, s + n) equals text t. 331 fn ia_is tx view uchar 8192 s ulong n ulong t view uchar * to bool 332 if ne n len t 333 ret false 334 end 335 for i ulong n 336 if ne get tx add s i get t i 337 ret false 338 end 339 end 340 ret true 341 end 342 343 note Field f of the action object o (0 path at d[0], at most 128 bytes; 1 344 note old at d[128], 40; 2 new at d[192], 40), a string decoded into d with 345 note no NUL byte. Its length, or -1. 346 fn ia_sfld src view uchar 8192 tp view uint 65536 o ulong f ulong d edit uchar 8192 to long 347 v = ulong jsnone 348 fo = ulong 0 349 mx = ulong 128 350 if eq f 0 351 v = ia_mem src tp o kpath 352 end 353 if eq f 1 354 v = ia_mem src tp o kold 355 fo = 128 356 mx = 40 357 end 358 if eq f 2 359 v = ia_mem src tp o knew 360 fo = 192 361 mx = 40 362 end 363 if eq v jsnone 364 ret neg long 1 365 end 366 if ne js_type tp v 6 367 ret neg long 1 368 end 369 n = js_sget src js_off tp v part d fo mx 370 if lt n 0 371 ret neg long 1 372 end 373 for i ulong ulong n 374 if eq get d add fo i 0 375 ret neg long 1 376 end 377 end 378 ret n 379 end 380 381 note Classify the action at a[0, an): kind (1..3, 9), the fields into d at 382 note 0 (path), 128 (old), 192 (new) with lengths in m[1..3]. 383 fn ia_json a view uchar 8192 an ulong d edit uchar 8192 m edit ulong 8 to ulong 384 tp = new uint 65536 0 385 x = js_init tp 8192 4 386 r = js_parse a tp an 387 if lt r 0 388 ret 9 389 end 390 if ne js_type tp 0 1 391 ret 9 392 end 393 tv = ia_mem a tp 0 ktool 394 if or eq tv jsnone ne js_type tp tv 6 395 ret 9 396 end 397 k = ulong 9 398 nk = ulong 2 399 if js_streq a js_off tp tv tread 400 k = 1 401 end 402 if js_streq a js_off tp tv tcheck 403 k = 2 404 end 405 if js_streq a js_off tp tv trepl 406 k = 3 407 nk = 4 408 end 409 if or eq k 9 ne js_nkids tp 0 nk 410 ret 9 411 end 412 pl = ia_sfld a tp 0 0 d 413 if lt pl 1 414 ret 9 415 end 416 put m 1 ulong pl 417 if ne k 3 418 ret k 419 end 420 ol = ia_sfld a tp 0 1 d 421 nl = ia_sfld a tp 0 2 d 422 if or lt ol 1 lt nl 0 423 ret 9 424 end 425 put m 2 ulong ol 426 put m 3 ulong nl 427 ret 3 428 end 429 430 note Write the record for text tx[0, m0) with response fields m to stdout. 431 fn ia_emit tx view uchar 8192 m edit ulong 8 to void 432 o = new uchar 8192 0 433 d = new uchar 8192 0 434 a = new uchar 8192 0 435 ia_trim tx get m 0 m 436 s = get m 4 437 n = get m 5 438 for i ulong n 439 put a i get tx add s i 440 end 441 ac = new ulong 8 0 442 k = ulong 9 443 if ia_is tx s n apass 444 k = 4 445 end 446 if ia_is tx s n amiss 447 k = 5 448 end 449 if eq k 9 450 k = ia_json a n d ac 451 end 452 p = ia_cat o 0 irec 0 len irec 453 p = ia_put o p k 454 put o p 32 455 p = ia_put o add p 1 get m 1 456 put o p 32 457 p = ia_put o add p 1 get m 2 458 put o p 32 459 p = ia_put o add p 1 get m 3 460 put o p 32 461 p = ia_put o add p 1 get ac 1 462 put o p 32 463 p = ia_put o add p 1 get ac 2 464 put o p 32 465 p = ia_put o add p 1 get ac 3 466 put o p 32 467 p = ia_put o add p 1 get m 0 468 put o p 10 469 p = ia_cat o add p 1 d 0 get ac 1 470 p = ia_cat o p d 128 get ac 2 471 p = ia_cat o p d 192 get ac 3 472 p = ia_cat o p tx 0 get m 0 473 ia_out o p 474 end 475 476 note An HTTP error: OMNE1 status, then up to 512 bytes of the body. 477 fn ia_herr cs edit ulong 320 io edit uchar 131072 st long to int 478 o = new uchar 8192 0 479 b = new uchar 512 0 480 n = hbodyrd cs io b 481 p = ia_cat o 0 ierr 0 len ierr 482 p = ia_put o p ulong st 483 put o p 10 484 p = add p 1 485 if gt n 0 486 p = ia_cat o p b 0 ulong n 487 end 488 ia_out o p 489 x = hclose cs 490 if eq st 503 491 ret 8 492 end 493 ret 6 494 end 495 496 note The prompt (argument 4) into pr; its length, or -1 when it is empty, 497 note over 3800 bytes or holds a NUL byte. 498 fn ia_prompt pr edit uchar 4096 to long 499 n = argread 4 pr 0 3800 500 if lt n 1 501 ret neg long 1 502 end 503 for i ulong ulong n 504 if eq get pr i 0 505 ret neg long 1 506 end 507 end 508 ret n 509 end 510 511 note Arguments PORT MAXTOK DEADLINE_S into a[0..2]; false when one is out of 512 note range (port 1..65535 but never 18091, 1..256 tokens, 1..3600 s). 513 fn ia_args a edit ulong 4 to bool 514 if or lt argcnt 5 gt argcnt 6 515 ret false 516 end 517 port = ia_num 1 518 mt = ia_num 2 519 ds = ia_num 3 520 if or or lt port 1 gt port 65535 eq port 18091 521 ret false 522 end 523 if or lt mt 1 gt mt 256 524 ret false 525 end 526 if or lt ds 1 gt ds 3600 527 ret false 528 end 529 put a 0 ulong port 530 put a 1 ulong mt 531 put a 2 ulong ds 532 ret true 533 end 534 535 note After the status st: the record, or the exit code of a failure. 536 fn ia_recv cs edit ulong 320 io edit uchar 131072 st long to int 537 rb = new uchar 16384 0 538 tx = new uchar 8192 0 539 m = new ulong 8 0 540 if eq st neg long 1000 541 ret 4 542 end 543 if eq st HETIME 544 x = hclose cs 545 ret 5 546 end 547 if lt st 0 548 x = hclose cs 549 ret 4 550 end 551 if ne st 200 552 ret ia_herr cs io st 553 end 554 rn = hbodyall cs io rb 555 x = hclose cs 556 if eq rn HETIME 557 ret 5 558 end 559 if lt rn 0 560 ret 7 561 end 562 e = ia_resp rb ulong rn tx m 563 if ne e 0 564 ret 7 565 end 566 ia_emit tx m 567 ret 0 568 end 569 570 fn ia_main to int 571 cs = new ulong 320 0 572 io = new uchar 131072 0 573 pr = new uchar 4096 0 574 ob = new uchar 16384 0 575 a = new ulong 4 0 576 if not ia_args a 577 ret 2 578 end 579 pn = ia_prompt pr 580 if lt pn 1 581 ret 3 582 end 583 bn = ia_body ob pr ulong pn get a 1 584 if lt bn 0 585 ret 3 586 end 587 ret ia_ask cs io ob ulong bn get a 0 long mul get a 2 `1000000000` 588 end 589 590 note The exchange within dl ns from now; a 503 is asked again every second 591 note while at least 2 s are left. The record, or the exit code of a failure. 592 fn ia_ask cs edit ulong 320 io edit uchar 131072 ob view uchar 16384 bn ulong po ulong dl long to int 593 t0 = monons 594 st = ia_send cs io ob bn po dl 595 for it ulong 3600 596 left = sub dl long sub monons t0 597 if or ne st 503 lt left `2000000000` 598 ret ia_recv cs io st 599 end 600 x = hclose cs 601 r = sleepns `1000000000` 602 st = ia_send cs io ob bn po sub left `1000000000` 603 end 604 ret ia_recv cs io st 605 end 606 607 fn main to int 608 ret ia_main 609 end