code wiki / _hdl_build / nx_llm_provider.nx
nx_llm_provider.nx source
↩ module page · 86 lines · 4585 B
1// nx_llm_provider.nx -- a BACKUP to Claude for the LLM-rung work (operator: "figure out a plan to have
2// a backup to you that actually can do that like maybe diffbot or something"). For the work the team
3// cannot yet do sovereignly -- semantic prose->claims EXTRACT, semantic EMBEDDINGS, prose authoring --
4// the team ROUTES to the most-preferred AVAILABLE provider, so Claude becomes a fallback, not the
5// default:
6// 1. NISHI-LLM (the future custom model -- fully sovereign, the end goal)
7// 2. EXTERNAL (a configured 3rd-party: Diffbot for extraction, an embedding API for semantics) =
8// the BACKUP that reduces Claude dependence today
9// 3. CLAUDE (current fallback when nothing else is available)
10// This is the routing/governance LAYER the team owns; the external calls are HTTPS (env-gated like all
11// live reach). Honest: EXTERNAL is paid + not sovereign -- a stepping stone, not the destination.
12// license_tier: ORIGINAL Pairs with nx_llm_gap_registry (what still needs the rung) + nx_teacher.
13
14import "nx_syscalls.nx"
15
16const LP_NONE: i64 = 0
17const LP_NISHI_LLM: i64 = 1 // sovereign custom model (preferred)
18const LP_EXTERNAL: i64 = 2 // Diffbot / embedding API -- the backup to Claude
19const LP_CLAUDE: i64 = 3 // current fallback
20
21// LLM-rung task kinds
22const LP_TASK_EXTRACT: i64 = 1 // semantic prose -> verified claims
23const LP_TASK_EMBED: i64 = 2 // semantic embeddings for retrieval
24const LP_TASK_PROSE: i64 = 3 // natural-language authoring
25
26// the external service that backs each task kind
27const LP_SVC_NONE: i64 = 0
28const LP_SVC_DIFFBOT: i64 = 10 // Diffbot Article/Knowledge-Graph extraction
29const LP_SVC_EMBED_API: i64 = 11 // an embedding API / local sentence-transformer
30
31// route an LLM-rung task to the most-preferred AVAILABLE provider.
32func lp_route(nishi_ready: i64, external_configured: i64) -> i64 {
33 if nishi_ready == 1 { return LP_NISHI_LLM }
34 if external_configured == 1 { return LP_EXTERNAL }
35 return LP_CLAUDE
36}
37
38// does this route REDUCE dependence on Claude? (the goal -- anything but Claude)
39func lp_reduces_claude(provider: i64) -> i64 { if provider == LP_CLAUDE { return 0 } return 1 }
40
41// is the rung fully SOVEREIGN? (only the custom Nishi LLM -- the destination)
42func lp_sovereign(provider: i64) -> i64 { if provider == LP_NISHI_LLM { return 1 } return 0 }
43
44// which external backup serves this task kind?
45func lp_external_service(task: i64) -> i64 {
46 if task == LP_TASK_EXTRACT { return LP_SVC_DIFFBOT }
47 if task == LP_TASK_EMBED { return LP_SVC_EMBED_API }
48 return LP_SVC_NONE
49}
50
51// when the custom Nishi LLM passes its gate it RETIRES Claude on that rung (the handoff completes).
52func lp_retires_claude(nishi_ready: i64) -> i64 { if nishi_ready == 1 { return 1 } return 0 }
53
54// ===== LOCAL backup tier (operator: "identify the local backup option") ===========================
55// A self-hosted model on OUR OWN 16GB hardware: free (no per-call cost), private (no data leaves), and
56// a stepping stone to the sovereign Nishi LLM -- so it is PREFERRED over a paid external API.
57const LP_LOCAL: i64 = 4
58// identified concrete local backups (run on the RTX 5080 box):
59const LP_LOCAL_MINILM: i64 = 20 // all-MiniLM-L6-v2 (~22M params, ~80MB, CPU/GPU) -- local EMBEDDINGS
60const LP_LOCAL_BGE: i64 = 21 // bge-small-en-v1.5 -- stronger local embeddings, still tiny
61const LP_LOCAL_EXTRACT: i64 = 22 // a small local instruct model (Qwen/Llama) for prose->claims EXTRACT
62
63// preferred routing WITH a local tier: NISHI-LLM > LOCAL (self-hosted) > EXTERNAL (paid API) > CLAUDE.
64func lp_route_local(nishi_ready: i64, local_available: i64, external_configured: i64) -> i64 {
65 if nishi_ready == 1 { return LP_NISHI_LLM }
66 if local_available == 1 { return LP_LOCAL }
67 if external_configured == 1 { return LP_EXTERNAL }
68 return LP_CLAUDE
69}
70
71// local is FREE (no per-call cost) and PRIVATE -- the reasons to prefer it over a paid API.
72func lp_local_is_free(provider: i64) -> i64 { if provider == LP_LOCAL { return 1 } return 0 }
73
74// the identified local backup model per task: MiniLM for embeddings, a small instruct model for extract.
75func lp_local_model(task: i64) -> i64 {
76 if task == LP_TASK_EMBED { return LP_LOCAL_MINILM }
77 if task == LP_TASK_EXTRACT { return LP_LOCAL_EXTRACT }
78 return LP_SVC_NONE
79}
80
81// does the route stay off Claude AND off paid APIs? (local or sovereign)
82func lp_is_sovereign_ish(provider: i64) -> i64 {
83 if provider == LP_NISHI_LLM { return 1 }
84 if provider == LP_LOCAL { return 1 }
85 return 0
86}