nx_forge_model.nx
buildroot/runtime/nx_forge_model.nx
about
nx_forge_model.nx -- FORGE F3 rung 2: the MODEL BACKEND for the driver. Turns a model serve's
HTTP /gen response into a candidate .nx file, and composes the prompt the model sees. Same loop
as rung 1 -- the backend just PRODUCES the candidate that fg_run then judges byte-exact.
fm_compose_prompt(pack, task, repair, out, cap) pack v1 + task statement + (optional) the
verbatim repair context from a prior failed cycle -> prompt file.
fm_build_gen_body(prompt, plen, max_new, mode, out) the serve's POST /gen JSON body.
fm_post_gen(a,b,c,d, port, body, blen, resp, rescap) TCP POST /gen to a.b.c.d:port over the
proven nx_http_client primitives; returns response bytes (header+body).
fm_extract_text(resp, rlen, out, cap) pull the JSON "text" value, unescaping \n \t \" \\ \/
\r and \uXXXX (low byte) -> the raw model output. -1 if absent.
fm_strip_fences(src, n, out) drop a leading ```lang fence line + trailing ``` (the pilot's
hand extraction stage, now an organ). Idempotent on unfenced text.
fm_stub_serve_once(port, respfile) an in-process single-shot serve (gate fixture): binds,
accepts one client, replies with respfile's bytes as a /gen JSON -> lets
the gate prove the REAL loopback round-trip with no external model.
Rung 2 proves the model-stage mechanics sovereignly; pointing fm_post_gen at 127.0.0.1:11434
(the no-float serve) or an API egress is a live address swap, not new logic.
license_tier: ORIGINAL
dependencies 3 imports · 3 importers
imports: nx_forge.nxnx_connect.nxnx_http_client.nx
imported by: nx_code_index.nxnx_forge_loop.nxnx_forge_model_gate.nx
structs
| none |
consts
| none |
functions
| 23 | func fm_hexval(c: i64) -> i64 called by 1: fm_extract_text |
| 31 | func fm_compose_prompt(packpath: *u8, task: *u8, repairpath: *u8, out: *u8, cap: i64) -> i64 |
| 70 | func fm_build_gen_body(prompt: *u8, plen: i64, max_new: i64, mode: i64, out: *u8) -> i64 |
| 92 | func fc_json_esc_bytes(dst: *u8, off: i64, src: *u8, n: i64) -> i64 |
| 109 | func fm_extract_text(resp: *u8, rlen: i64, out: *u8, cap: i64) -> i64 |
| 182 | func fm_strip_fences(src: *u8, n: i64, out: *u8) -> i64 |
| 230 | func fm_post_gen(a: i64, b: i64, c: i64, d: i64, port: i64, body: *u8, blen: i64, resp: *u8, rescap: i64) -> i64 |
| 249 | func fm_stub_serve_once(port: i64, respfile: *u8) -> i64 |