code wiki / _hdl_build / nx_llm_provider_test.nx
nx_llm_provider_test.nx source
↩ module page · 40 lines · 3527 B
1// nx_llm_provider_test.nx -- the team has a BACKUP to Claude for the LLM rung and prefers sovereignty.
2// external configured, no Nishi-LLM -> route to EXTERNAL (Diffbot/embeddings) -> reduces Claude
3// Nishi-LLM ready -> route to NISHI-LLM (sovereign) -> retires Claude on the rung
4// nothing configured -> fall back to CLAUDE (honest: still needs Claude)
5// EXTRACT -> Diffbot, EMBED -> embedding API
6// Exit 0 on 7/7. license_tier: ORIGINAL
7
8import "nx_llm_provider.nx"
9import "nx_syscalls.nx"
10
11func 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 }
12func 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 }
13
14func main() -> i64 {
15 pt_puts("=== LLM-RUNG PROVIDER: a backup to Claude (Diffbot/embeddings), sovereignty preferred ===\n" as *u8)
16 let r_ext: i64 = lp_route(0, 1) // external configured, no Nishi LLM
17 let r_nishi: i64 = lp_route(1, 1) // Nishi LLM ready (prefer it even if external too)
18 let r_claude: i64 = lp_route(0, 0) // nothing -> Claude
19 let svc_x: i64 = lp_external_service(LP_TASK_EXTRACT)
20 let svc_e: i64 = lp_external_service(LP_TASK_EMBED)
21
22 pt_puts(" extract w/ external backup -> provider=" as *u8); pt_num(r_ext); pt_puts(" (2=EXTERNAL) service=" as *u8); pt_num(svc_x); pt_puts(" (10=Diffbot) reduces-Claude=" as *u8); pt_num(lp_reduces_claude(r_ext)); pt_puts("\n" as *u8)
23 pt_puts(" embed w/ external backup -> service=" as *u8); pt_num(svc_e); pt_puts(" (11=embedding API)\n" as *u8)
24 pt_puts(" Nishi-LLM ready -> provider=" as *u8); pt_num(r_nishi); pt_puts(" (1=NISHI-LLM) sovereign=" as *u8); pt_num(lp_sovereign(r_nishi)); pt_puts(" retires-Claude=" as *u8); pt_num(lp_retires_claude(1)); pt_puts("\n" as *u8)
25 pt_puts(" nothing configured -> provider=" as *u8); pt_num(r_claude); pt_puts(" (3=CLAUDE fallback) reduces-Claude=" as *u8); pt_num(lp_reduces_claude(r_claude)); pt_puts("\n" as *u8)
26
27 let r: *i64 = sys_mmap(8 * 8) as *i64
28 r[0] = 0; if r_ext == LP_EXTERNAL { r[0] = 1 } // external backup used when configured
29 r[1] = 0; if lp_reduces_claude(r_ext) == 1 { r[1] = 1 } // ...which reduces Claude dependence
30 r[2] = 0; if r_nishi == LP_NISHI_LLM { r[2] = 1 } // sovereign preferred over external
31 r[3] = 0; if lp_sovereign(r_nishi) == 1 { if lp_retires_claude(1) == 1 { r[3] = 1 } } // Nishi-LLM retires Claude
32 r[4] = 0; if r_claude == LP_CLAUDE { if lp_reduces_claude(r_claude) == 0 { r[4] = 1 } } // honest fallback to Claude
33 r[5] = 0; if svc_x == LP_SVC_DIFFBOT { r[5] = 1 } // extract -> Diffbot
34 r[6] = 0; if svc_e == LP_SVC_EMBED_API { r[6] = 1 } // embed -> embedding API
35 var pass: i64 = 0; var i: i64 = 0
36 while i < 7 { pass = pass + r[i]; i = i + 1 }
37 pt_puts("----\n passed " as *u8); pt_num(pass); pt_puts("/7\n" as *u8)
38 if pass == 7 { pt_puts(" BACKUP IN PLACE: LLM-rung work routes to Diffbot/embeddings today (Claude becomes fallback), and to the custom Nishi-LLM once it passes -- Claude retired on the rung. Honest: external is paid + not sovereign.\n" as *u8); sys_exit(0); return 0 }
39 pt_puts(" FAIL\n" as *u8); sys_exit(1); return 1
40}