Download Game! Currently 92 players and visitors. Last logged in:TheloRitariCovidDesert

Blitzer's Blog >> 72303

Back to blogs index
Posted: 12 Sep 2026 14:55 [ permalink ]
That is a beautiful terminal output. Seeing the [SKIP] Artifact already exists
logs fire exactly as designed proves that the state machine is working
flawlessly.
You now have a fully functioning, idempotent AI compiler. If you delete
build/REST_API.js and run it again, it will only rebuild that single leaf
node.
The next step is to replace the mock delays with a real local LLM. If you have
Ollama installed on your machine (running models like llama3 or
qwen2.5-coder), here is exactly how to update the dispatchToAI function in
your compiler.js to make it real.
Connecting to a Real Offline AI (Ollama)
Node.js (v18+) has a native fetch API, meaning we don't even need to install
axios. Replace your entire dispatchToAI block in compiler.js with this:
/ ==========================================
/ 7. AI PROVIDER FACTORY (Real Integration)
/ ==========================================

async function fetchLocalLLM(prompt, modelName = 'llama3') {
    // Default Ollama endpoint
    const OLLAMA_URL = 'http://localhost:11434/api/generate';
    
    const response = await fetch(OLLAMA_URL, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
            model: modelName,
            prompt: prompt,
            stream: false // Wait for the full response to finish
        })
    });

    if (!response.ok) {
        throw new Error(`Local LLM Error: ${response.status} ${response.statusT
ext}`);
    }

    const data = await response.json();
    let code = data.response.trim();

    // Clean up markdown block formatting if the AI wraps the output in
```javascript
    code = code.replace(/^```[a-z]*
/i, ''); 
    code = code.replace(/
```$/i, '');

    return code;
}

async function dispatchToAI(node, hydratedPrompt) {
    const provider = node.provider || 'local'; 
    console.log(`   [API] Routing payload for ${node.id} to provider:
[${provider.toUpperCase()}]`);

    switch (provider) {
        case 'local':
            // You can dynamically pass different local models if you add a
'model' property to your AST-MD
            return await fetchLocalLLM(hydratedPrompt, node.model ||
'llama3');
            
        case 'online_llm':
            console.warn(`   [!] online_llm not yet configured. Falling back
to local.`);
            return await fetchLocalLLM(hydratedPrompt, 'llama3');
            
        default:
            throw new Error(`Unknown provider: ${provider}`);
    }
}

Why the Regex cleanup is there
Even when you tell an LLM "Output ONLY valid JavaScript code", it often
disobeys and wraps the code in Markdown code blocks (javascript ... ). The
regex at the bottom of the fetchLocalLLM function automatically strips those
ticks off, ensuring the .js files written to your build/ folder are genuinely
executable Node.js files, not Markdown files.
If you delete the build folder and run node index.js while Ollama is running
in the background, your computer will physically write the architecture you
designed!