code wiki / _hdl_build / nx_llm_provider_local_test.nx

nx_llm_provider_local_test.nx source

↩ module page · 36 lines · 3067 B

1// nx_llm_provider_local_test.nx -- the identified LOCAL backup is preferred over paid APIs. With a 2// self-hosted model available (all-MiniLM-L6-v2 for embeddings on the 16GB box), the team routes LOCAL 3// (free, private) BEFORE a paid external API, and only falls to Claude when nothing else exists. 4// Exit 0 on 6/6. license_tier: ORIGINAL 5 6import "nx_llm_provider.nx" 7import "nx_syscalls.nx" 8 9func pt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 10func pt_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(1,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 } 11 12func main() -> i64 { 13 pt_puts("=== LOCAL backup identified: self-hosted preferred over paid API ===\n" as *u8) 14 let r_local: i64 = lp_route_local(0, 1, 1) // local available + external too -> prefer LOCAL 15 let r_ext: i64 = lp_route_local(0, 0, 1) // no local, external configured -> EXTERNAL 16 let r_claude:i64 = lp_route_local(0, 0, 0) // nothing -> Claude fallback 17 let r_nishi: i64 = lp_route_local(1, 1, 1) // Nishi LLM ready -> sovereign 18 let emb_model: i64 = lp_local_model(LP_TASK_EMBED) 19 20 pt_puts(" local+external -> provider=" as *u8); pt_num(r_local); pt_puts(" (4=LOCAL) free=" as *u8); pt_num(lp_local_is_free(r_local)); pt_puts(" sovereign-ish=" as *u8); pt_num(lp_is_sovereign_ish(r_local)); pt_puts("\n" as *u8) 21 pt_puts(" identified local EMBED model = " as *u8); pt_num(emb_model); pt_puts(" (20=all-MiniLM-L6-v2, ~80MB, runs on the 16GB box)\n" as *u8) 22 pt_puts(" no-local,external -> " as *u8); pt_num(r_ext); pt_puts(" (2=EXTERNAL API) nothing -> " as *u8); pt_num(r_claude); pt_puts(" (3=CLAUDE) nishi-ready -> " as *u8); pt_num(r_nishi); pt_puts(" (1=NISHI)\n" as *u8) 23 24 let r: *i64 = sys_mmap(8 * 8) as *i64 25 r[0] = 0; if r_local == LP_LOCAL { r[0] = 1 } // local preferred over paid API 26 r[1] = 0; if lp_local_is_free(r_local) == 1 { r[1] = 1 } // local is free 27 r[2] = 0; if lp_is_sovereign_ish(r_local) == 1 { r[2] = 1 } // local counts as sovereign-ish 28 r[3] = 0; if emb_model == LP_LOCAL_MINILM { r[3] = 1 } // the identified local embed model 29 r[4] = 0; if r_ext == LP_EXTERNAL { if r_claude == LP_CLAUDE { r[4] = 1 } } // correct fallbacks 30 r[5] = 0; if r_nishi == LP_NISHI_LLM { r[5] = 1 } // sovereign still wins overall 31 var pass: i64 = 0; var i: i64 = 0 32 while i < 6 { pass = pass + r[i]; i = i + 1 } 33 pt_puts("----\n passed " as *u8); pt_num(pass); pt_puts("/6\n" as *u8) 34 if pass == 6 { pt_puts(" LOCAL BACKUP: all-MiniLM-L6-v2 self-hosted (free, private, fits 16GB) is the embed backup, preferred over Diffbot/paid APIs; Claude only when nothing local/external exists.\n" as *u8); sys_exit(0); return 0 } 35 pt_puts(" FAIL\n" as *u8); sys_exit(1); return 1 36}