UI:n system prompt ja sampling-parametrit välittyvät inferenssiin asti

Frontend lähettää agentin asetukset (system_prompt, temperature, top_k,
max_tokens, repeat_penalty, stop) API:lle. Hub välittää ne solmulle.
Native-node ja Wasm-coder käyttävät välitettyjä arvoja hardkoodattujen
sijaan.
This commit is contained in:
Jaakko Vanhala
2026-04-12 07:39:41 +03:00
parent e272b0d124
commit 5f00582053
5 changed files with 88 additions and 30 deletions

View File

@@ -486,7 +486,7 @@ OUTPUT FORMAT:
// === kpnRun: lähettää promptin mallille ===
const activeStreams = {};
async function kpnRun(model, prompt, silent) {
async function kpnRun(model, prompt, silent, agentOpts) {
const taskId = crypto.randomUUID();
const statusDiv = document.createElement('div');
statusDiv.className = 'terminal-line';
@@ -511,10 +511,24 @@ OUTPUT FORMAT:
statusDiv.innerHTML = ` <span style="color:#8b949e">→ <span style="color:var(--accent)">${model}</span> käsittelee...</span>`;
// Rakennetaan pyyntö: agentin asetukset tai globaalit oletukset
const opts = agentOpts || {};
const payload = {
model,
prompt,
task_id: taskId,
system_prompt: opts.systemPrompt || settings.systemPrompt || undefined,
temperature: opts.temperature ?? settings.temperature ?? undefined,
top_k: opts.topK ?? settings.topK ?? undefined,
max_tokens: opts.maxTokens ?? settings.maxTokens ?? undefined,
repeat_penalty: opts.repeatPenalty ?? settings.repeatPenalty ?? undefined,
stop: settings.stopSequences ? settings.stopSequences.split('\\n').filter(Boolean) : undefined,
};
const res = await fetch('/api/v1/chat/completions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model, prompt, task_id: taskId }),
body: JSON.stringify(payload),
});
if (res.status === 503 && !wasmNodeStarted) {
@@ -792,7 +806,7 @@ OUTPUT FORMAT:
prompt += fileDef.instructions + '\n';
prompt += 'Adapt the example to match the project description. Import from already written files. Write ONLY the code, no explanations.';
const code = await kpnRun(fileAgent.model, prompt);
const code = await kpnRun(fileAgent.model, prompt, false, fileAgent);
if (!code) {
termLog(` ✗ Keskeytyi (${fileName})`, '#f85149');
return;
@@ -817,7 +831,7 @@ OUTPUT FORMAT:
else explainStep('Uudelleentarkistus', `${tst.name} tarkistaa korjaukset.`);
const reviewPrompt = (tst.prompt ? tst.prompt+'\n\n' : '') + `Review this project:\n\n${currentCode}`;
const review = await kpnRun(tst.model, reviewPrompt);
const review = await kpnRun(tst.model, reviewPrompt, false, tst);
stepN++;
// LGTM → ei korjauksia tarvita
@@ -832,7 +846,7 @@ OUTPUT FORMAT:
explainStep('Korjaus', `${tst.name} löysi ongelmia. ${cdr.name} saa palautteen ja korjaa.`);
const fixPrompt = `${cdr.prompt ? cdr.prompt+'\n\n' : ''}Fix these issues:\n${review}\n\nCurrent code:\n${currentCode}\n\nWrite ALL corrected files. Start each file with: --- filename.py ---`;
const fixedCode = await kpnRun(cdr.model, fixPrompt);
const fixedCode = await kpnRun(cdr.model, fixPrompt, false, cdr);
// Parsitaan korjatut tiedostot takaisin files-objektiin
if (fixedCode) {
@@ -858,7 +872,7 @@ OUTPUT FORMAT:
highlightAgent('qa');
explainStep('Testit', `${qaAgent.name} kirjoittaa pytest-testit korjatulle koodille.`);
const qaPrompt = (qaAgent.prompt ? qaAgent.prompt+'\n\n' : '') + `Write pytest tests for this project:\n\n${updatedCode}\n\nWrite a complete test_main.py file with TestClient.`;
const tests = await kpnRun(qaAgent.model, qaPrompt);
const tests = await kpnRun(qaAgent.model, qaPrompt, false, qaAgent);
if (tests) files['test_main.py'] = tests;
stepN++;
}
@@ -878,7 +892,7 @@ OUTPUT FORMAT:
`- Expose port 8000\n` +
`- CMD: uv run uvicorn main:app --host 0.0.0.0 --port 8000\n` +
`\nWrite ONLY the Dockerfile, no explanations.`;
const dockerfile = await kpnRun(tst.model, dockerPrompt);
const dockerfile = await kpnRun(tst.model, dockerPrompt, false, tst);
if (dockerfile) files['Dockerfile'] = dockerfile;
stepN++;
@@ -913,7 +927,7 @@ OUTPUT FORMAT:
`## Architecture\nDescribe the project structure and design decisions.\n\n` +
`## Risk Assessment\n| Severity | Issue |\n|----------|-------|\n| ... | ... |\n\n` +
`Project code:\n${finalCode}`;
const readme = await kpnRun(obs.model, obsPrompt);
const readme = await kpnRun(obs.model, obsPrompt, false, obs);
if (readme) {
files['README.md'] = readme;
// Tallennetaan raportti globaalisti jotta tarkkailija-klikkaus avaa sen