From b35600b417bc99b94e67c50723f2c7d7327f9560 Mon Sep 17 00:00:00 2001 From: jaakko Date: Tue, 7 Apr 2026 08:12:25 +0300 Subject: [PATCH] Few-shot esimerkit pipeline-prompteissa: manageri, koodari, QA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pienet mallit tuottavat huomattavasti parempaa koodia kun promptissa on konkreettinen esimerkki oikeasta vastauksesta. Lisätty: - Manageri: esimerkki tiedostolistasta - Koodari: esimerkki main.py ja models.py -tiedostoista - QA: esimerkki pytest + TestClient -testeistä Co-Authored-By: Claude Opus 4.6 (1M context) --- network-poc/static/index.html | 67 ++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/network-poc/static/index.html b/network-poc/static/index.html index 68a8a29..77dd811 100644 --- a/network-poc/static/index.html +++ b/network-poc/static/index.html @@ -2152,7 +2152,11 @@ CONSTRAINTS — the coder can only generate ~400 tokens per file: - Only .py and pyproject.toml files - No directories, no paths, just filenames - List dependencies first, then main app -- Prefer fewer, focused files over many small ones + +EXAMPLE for "FastAPI todo app with SQLite": +pyproject.toml: project metadata and dependencies +models.py: SQLAlchemy models and database setup +main.py: FastAPI app with CRUD endpoints Project: ${task}`; termLog(`\n[1] Manageri — projektin suunnittelu`); @@ -2223,9 +2227,48 @@ start = "uvicorn main:app --reload"`; extraInstructions = '\nList one dependency per line. No version pins unless necessary.'; } + const coderExample = file.name.includes('main') || file.name.includes('app') + ? `\nEXAMPLE output for a main.py: +from fastapi import FastAPI, Depends +from sqlalchemy.orm import Session +from models import get_db, User + +app = FastAPI() + +@app.get("/users") +def list_users(db: Session = Depends(get_db)): + return db.query(User).all() + +@app.post("/users") +def create_user(name: str, db: Session = Depends(get_db)): + user = User(name=name) + db.add(user) + db.commit() + return {"id": user.id, "name": user.name}` + : file.name.includes('model') + ? `\nEXAMPLE output for a models.py: +from sqlalchemy import create_engine, Column, Integer, String +from sqlalchemy.orm import sessionmaker, declarative_base + +engine = create_engine("sqlite:///app.db") +SessionLocal = sessionmaker(bind=engine) +Base = declarative_base() + +class User(Base): + __tablename__ = "users" + id = Column(Integer, primary_key=True) + name = Column(String) + +Base.metadata.create_all(engine) + +def get_db(): + db = SessionLocal() + try: yield db + finally: db.close()` + : ''; const coderPrompt = `${context}Project: ${task} -Write ONLY the file "${file.name}"${file.desc ? ': ' + file.desc : ''}.${extraInstructions} -IMPORTANT: Keep the code SHORT and focused. Max ~50 lines. No comments, no docstrings, no type hints unless essential. Write minimal, working code.`; +Write ONLY the file "${file.name}"${file.desc ? ': ' + file.desc : ''}.${extraInstructions}${coderExample} +IMPORTANT: Keep the code SHORT. Max ~50 lines. No comments, no docstrings. Write minimal, working code. Output ONLY code.`; const code = await kpnRun(agentPrompts.coder.model, coderPrompt); if (!code) { termLog(` ✗ Pipeline keskeytyi (${file.name})`, '#f85149'); @@ -2274,8 +2317,24 @@ Write the corrected code.`; const step5 = fileList.length + (review && !review.toLowerCase().includes('lgtm') ? 5 : 3); termLog(`\n[${step5}] QA — testit`); pipelineStep('qa', 'Testit', 'active', 'Kirjoitetaan testejä'); - const qaPrompt = `Write a short test file (test_app.py) for this project. Use pytest. Max 3 test functions. Keep it minimal. + const qaPrompt = `Write test_app.py using pytest and FastAPI TestClient. Max 3 tests. Output ONLY code. +EXAMPLE: +from fastapi.testclient import TestClient +from main import app + +client = TestClient(app) + +def test_create(): + r = client.post("/users", params={"name": "Test"}) + assert r.status_code == 200 + +def test_list(): + r = client.get("/users") + assert r.status_code == 200 + assert isinstance(r.json(), list) + +PROJECT CODE: ${Object.entries(generatedFiles).map(([n, c]) => `--- ${n} ---\n${c}`).join('\n\n')}`; const tests = await kpnRun(agentPrompts.qa.model, qaPrompt, false, 512); if (tests) generatedFiles['test_app.py'] = tests;