diff --git a/network-poc/static/index.html b/network-poc/static/index.html index c89790f..a674065 100644 --- a/network-poc/static/index.html +++ b/network-poc/static/index.html @@ -2450,23 +2450,73 @@ IMPORTANT: Only list pip-installable packages. NEVER include Python stdlib modul } const coderExample = file.name.includes('main') || file.name.includes('app') - ? `\nEXAMPLE output for a main.py: -from fastapi import FastAPI, Depends + ? `\nEXAMPLE output for a main.py (CRUD + HTML UI): +from fastapi import FastAPI, Depends, HTTPException +from fastapi.responses import FileResponse from sqlalchemy.orm import Session -from models import get_db, User +from models import get_db, Base, engine, User +Base.metadata.create_all(engine) app = FastAPI() -@app.get("/users") +@app.get("/") +def index(): + return FileResponse("index.html") + +@app.get("/api/users") def list_users(db: Session = Depends(get_db)): return db.query(User).all() -@app.post("/users") +@app.post("/api/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}` + return {"id": user.id, "name": user.name} + +@app.put("/api/users/{user_id}") +def update_user(user_id: int, name: str, db: Session = Depends(get_db)): + user = db.query(User).get(user_id) + if not user: raise HTTPException(404) + user.name = name + db.commit() + return {"id": user.id, "name": user.name} + +@app.delete("/api/users/{user_id}") +def delete_user(user_id: int, db: Session = Depends(get_db)): + user = db.query(User).get(user_id) + if not user: raise HTTPException(404) + db.delete(user) + db.commit() + return {"ok": True}` + : file.name.includes('index.html') + ? `\nEXAMPLE output for index.html (simple CRUD UI): + +App + +

Users

+ + +` : file.name.includes('model') ? `\nEXAMPLE output for a models.py: from sqlalchemy import create_engine, Column, Integer, String, Boolean, Text @@ -2490,7 +2540,7 @@ def get_db(): : ''; const coderPrompt = `${context}Project: ${task} 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.`; +IMPORTANT: Keep the code SHORT. Max ~60 lines. No comments, no docstrings. Write minimal, working code. Output ONLY code. Serve index.html at / using FileResponse. Use /api/ prefix for JSON endpoints.`; const code = await kpnRun(agentPrompts.coder.model, coderPrompt); if (!code) { termLog(` ✗ Pipeline keskeytyi (${file.name})`, '#f85149'); @@ -3197,7 +3247,7 @@ ${filesHtml} 'kpn run coder-3b': ['"binary search tree in rust"', '"REST API with Flask"', '"async web scraper in python"'], 'kpn run manager': ['"suunnittele REST API"', '"priorisoi tiimin tehtävät"'], 'kpn run tester': ['"testaa login-toiminto"'], - 'kpn project': ['"FastAPI + SQLite REST API for users with HTML UI at /"', '"Flask todo app with Jinja2 templates and form UI"', '"FastAPI bookmark manager with HTML frontend and search"'], + 'kpn project': ['"FastAPI + SQLite CRUD API for users (create, list, update, delete) with HTML form UI served at /"', '"FastAPI todo app with SQLite: CRUD (add, list, toggle done, delete) with simple HTML UI at /"', '"FastAPI bookmark manager with SQLite: CRUD (add, list, edit, delete) with HTML search UI at /"'], 'kpn pipeline': ['"rakenna todo-sovellus"', '"tee laskin pythonilla"'], };