# Training nibiru-coder

This folder contains everything needed to register a Nibiru-flavoured chat
model on your Ollama server (defaults to `http://localhost:11434`; override
via the `OLLAMA_BASE_URL` env var or in `application/module/ai/settings/ai.production.ini`).

## What the model is

`nibiru-coder` is a **system-prompt-customised** Qwen 2.5 Coder 14B. It's not
a fine-tune in the LoRA sense — it's the same weights as the base model but
with a baked-in system prompt that:

- explains MMVC, modules, the dispatcher, and Nibiru's singletons,
- enforces the framework's conventions (`pageAction`, `navigationAction`,
  `View::assign`, `Form::create`),
- pushes the model toward Nibiru-idiomatic answers instead of generic Laravel
  / Symfony advice.

System-prompt customisation runs **instantly** (no GPU training time) and
gives ~80 % of the value of a real LoRA at zero training cost. When you have
budget for a real LoRA, the
[corpus exporter](/en/ai/corpus/) produces the JSONL you'd train on.

## Build it

```bash
./application/module/ai/training/build.sh           # builds nibiru-coder:1.0
./application/module/ai/training/build.sh 1.1       # bump tag
```

The script:

1. Reads the `Modelfile` next to it.
2. POSTs to `${OLLAMA_BASE_URL}/api/create`.
3. Runs a smoke-test chat call to confirm the new tag responds.

After it succeeds, set the model in `application/module/ai/settings/ai.ini`:

```ini
[AI]
chat.model = "nibiru-coder:1.0"
```

…and every `\Nibiru\Module\Ai\Ai` instance in your app talks to it.

## Iterate on the system prompt

The Modelfile's `SYSTEM """ ... """` block is the lever. Tighten the
conventions, add new examples, or add citations to specific framework files.
Re-run `build.sh` with a new tag (`1.1`, `1.2`) and A/B against the previous
tag in your app.

## Real LoRA path (when you're ready)

1. Run `npm run build:corpus` in `docs/` — produces `dist/corpus/chat.jsonl`.
2. Use Axolotl / Unsloth / LLaMA-Factory with that JSONL as your sharegpt
   training set.
3. Convert the resulting LoRA to GGUF (`llama.cpp`'s `convert-hf-to-gguf.py`).
4. Build an Ollama Modelfile with `FROM ./your-lora.gguf` and re-register
   as `nibiru-coder:2.0`.

The framework code doesn't need to change — flip the model tag in
`ai.ini` and you're on the new weights.
