code wiki / _hdl_build / nx_llm_probe.nx

nx_llm_probe.nx source

↩ module page · 76 lines · 3610 B

1// nx_llm_probe.nx -- one-shot probe of the LIVE sovereign LLM seat (127.0.0.1:11434) to MEASURE whether the 2// real trained model can translate a full sentence the 9-word CONNECT lexicon cannot. Honest gate on a real 3// claim: I will not wire the model into CONNECT translation until I have SEEN it produce a real translation. 4// Usage: nx_llm_probe "<instruction>" (defaults to an EN->RU sentence translation) 5// license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_connect.nx" // bounded connect: a raw sys_connect hangs ~127s on a black-holed host 8const K_MAGIC_8192: i64 = 8192 9const K_MAGIC_16384: i64 = 16384 10const K_MAGIC_65536: i64 = 65536 11const K_MAGIC_65535: i64 = 65535 12 13func lp_puts(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 14func lp_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 15func lp_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off+i]=s[i]; i=i+1} return off+i } 16func lp_catn(dst: *u8, off: i64, v: i64) -> i64 { 17 var o: i64=off 18 if v==0 { dst[o]=48 as u8; return o+1 } 19 var d: i64=1 20 var m: i64=v 21 while m>=10 { d=d*10; m=m/10 } 22 var x: i64=v 23 while d>0 { let q: i64=x/d; dst[o]=(48+q) as u8; o=o+1; x=x-(q*d); d=d/10 } 24 return o 25} 26 27func main(argc: i64, argv: *i64) -> i64 { 28 var instr: *u8 = "Translate this English sentence to Russian and reply with ONLY the translation: I would like to learn your language, can we practice together this week?" as *u8 29 if argc >= 2 { instr = argv[1] as *u8 } 30 31 // sockaddr_in 127.0.0.1:11434 (port 11434 = 0x2CAE) 32 let addr: *u8 = sys_mmap(16) 33 addr[0]=2 as u8; addr[1]=0 as u8 34 addr[2]=0x2C as u8; addr[3]=0xAE as u8 35 addr[4]=127 as u8; addr[5]=0 as u8; addr[6]=0 as u8; addr[7]=1 as u8 36 var z: i64=8 37 while z<16 { addr[z]=0 as u8; z=z+1 } 38 39 let fd: i64 = sys_socket(AF_INET, SOCK_STREAM, 0) 40 if fd<0 { lp_puts(1,"PROBE-FAIL socket\n" as *u8); return 1 } 41 sys_set_socket_timeout(fd, 60) // the model is slow; give it a minute 42 if nx_connect_bounded(fd, addr, 16, NX_CONN_DEFAULT_MS)<0 { lp_puts(1,"PROBE-FAIL connect (is :11434 up?)\n" as *u8); return 2 } 43 44 // JSON body: {"messages":[{"role":"user","content":"<instr>"}],"max_tokens":80} 45 let body: *u8 = sys_mmap(K_MAGIC_8192) 46 var b: i64 = lp_cat(body, 0, "{\"messages\":[{\"role\":\"user\",\"content\":\"" as *u8) 47 b = lp_cat(body, b, instr) 48 b = lp_cat(body, b, "\"}],\"max_tokens\":80}" as *u8) 49 let blen: i64 = b 50 51 let req: *u8 = sys_mmap(K_MAGIC_16384) 52 var r: i64 = lp_cat(req, 0, "POST /chat HTTP/1.1\r\nHost: x\r\nContent-Type: application/json\r\nContent-Length: " as *u8) 53 r = lp_catn(req, r, blen) 54 r = lp_cat(req, r, "\r\nConnection: close\r\n\r\n" as *u8) 55 var i: i64=0 56 while i<blen { req[r+i]=body[i]; i=i+1 } 57 r = r + blen 58 59 var w: i64=0 60 while w<r { let k: i64 = sys_write(fd,(req as i64+w) as *u8, r-w); if k<=0 { lp_puts(1,"PROBE-FAIL send\n" as *u8); return 3 } w=w+k } 61 62 lp_puts(1, "--- LLM seat raw response (127.0.0.1:11434 /chat) ---\n" as *u8) 63 let buf: *u8 = sys_mmap(K_MAGIC_65536) 64 var tot: i64=0 65 var go: i64=1 66 while go==1 { 67 let n: i64 = sys_read(fd, (buf as i64+tot) as *u8, K_MAGIC_65535-tot) 68 if n<=0 { go=0 } else { tot=tot+n; if tot>=K_MAGIC_65535 { go=0 } } 69 } 70 sys_close(fd) 71 sys_write(1, buf, tot) 72 lp_puts(1, "\n--- end (bytes=" as *u8) 73 let nb: *u8 = sys_mmap(28); let e: i64 = lp_catn(nb,0,tot); nb[e]=0 as u8; lp_puts(1,nb) 74 lp_puts(1, ") ---\n" as *u8) 75 return 0 76}