This commit is contained in:
team3
2026-06-04 15:24:33 +02:00
parent d08878289e
commit 1aef82ec40
17 changed files with 440 additions and 117 deletions

View File

@@ -6,7 +6,8 @@ from datetime import datetime, timezone
from fastapi import APIRouter, HTTPException
from fastapi.responses import FileResponse
from config import FORMAT_META, PROJECTS_DIR
from agents import provider_available
from config import FORMAT_META, PROJECTS_DIR, PROVIDERS
from database import (
create_guide, delete_guide, get_guide, list_guides,
create_baustein as db_create_baustein, list_bausteine, get_baustein, delete_baustein as db_delete_baustein,
@@ -19,7 +20,7 @@ from models import (
BausteinCreateRequest, BausteinReworkRequest, BausteinSortRequest, BausteinResponse, SuggestionResponse,
TopicSuggestRequest, TopicSuggestion,
GuideChatRequest, GuideChatResponse,
ProgressUpdate, ProgressResponse, ProjectResponse,
ProgressUpdate, ProgressResponse, ProjectResponse, ProviderInfo,
)
from paths import final_paths, project_dir, project_cache_path
@@ -31,6 +32,11 @@ async def get_formats():
return FORMAT_META
@router.get("/providers", response_model=list[ProviderInfo])
async def get_providers():
return [{"id": pid, "available": provider_available(pid)} for pid in PROVIDERS]
def _safe_project_name(name: str) -> str:
if not name or "/" in name or "\\" in name or ".." in name or "\x00" in name:
raise HTTPException(400, "Ungültiger Projektname")
@@ -63,7 +69,7 @@ async def remove_project(name: str):
async def topic_suggestions(req: TopicSuggestRequest):
guides = await list_guides()
existing_topics = sorted({g["topic"] for g in guides})
return await suggest_topics(req.problem.strip(), existing_topics)
return await suggest_topics(req.problem.strip(), existing_topics, provider=req.provider)
@router.post("/guides", response_model=GuideResponse)
@@ -80,7 +86,7 @@ async def create(req: GuideCreateRequest):
"updated_at": now,
}
await create_guide(guide)
asyncio.create_task(generate_guide(guide["id"], guide["topic"], guide["format"], guide["instructions"], req.reindex))
asyncio.create_task(generate_guide(guide["id"], guide["topic"], guide["format"], guide["instructions"], req.reindex, req.provider))
return guide
@@ -117,7 +123,7 @@ async def rework(guide_id: str, req: GuideReworkRequest):
raise HTTPException(404, "Guide nicht gefunden")
if guide["status"] != "done":
raise HTTPException(400, "Guide muss fertig sein")
asyncio.create_task(rework_guide(guide_id, guide["topic"], guide["format"], req.instructions.strip()))
asyncio.create_task(rework_guide(guide_id, guide["topic"], guide["format"], req.instructions.strip(), req.provider))
return {"ok": True}
@@ -129,6 +135,7 @@ async def guide_chat(guide_id: str, req: GuideChatRequest):
reply = await chat_with_guide(
guide["topic"], guide["format"], req.section, req.outline,
[m.model_dump() for m in req.messages],
provider=req.provider,
)
return {"reply": reply}
@@ -205,7 +212,7 @@ async def add_baustein(req: BausteinCreateRequest):
"updated_at": now,
}
await db_create_baustein(baustein)
asyncio.create_task(generate_baustein_detail(baustein["id"], baustein["topic"], baustein["title"], req.instructions.strip()))
asyncio.create_task(generate_baustein_detail(baustein["id"], baustein["topic"], baustein["title"], req.instructions.strip(), req.provider))
return baustein
@@ -233,7 +240,7 @@ async def rework_baustein_route(baustein_id: str, req: BausteinReworkRequest):
"purpose": b.get("purpose", ""),
"examples": examples,
}
asyncio.create_task(rework_baustein(baustein_id, b["topic"], b["title"], current, req.instructions.strip()))
asyncio.create_task(rework_baustein(baustein_id, b["topic"], b["title"], current, req.instructions.strip(), req.provider))
return {"ok": True}
@@ -244,7 +251,7 @@ async def sort_bausteine_route(topic: str, req: BausteinSortRequest):
bausteine = await list_bausteine(topic)
if not bausteine:
return {"ok": True}
asyncio.create_task(sort_bausteine(topic, bausteine, req.instructions.strip()))
asyncio.create_task(sort_bausteine(topic, bausteine, req.instructions.strip(), req.provider))
return {"ok": True}
@@ -261,7 +268,9 @@ async def get_suggestions(topic: str):
@router.post("/bausteine/suggestions/generate")
async def trigger_suggestions(topic: str):
async def trigger_suggestions(topic: str, provider: str = "claude"):
if provider not in PROVIDERS:
raise HTTPException(400, "Unbekannter Provider")
if is_suggestions_generating(topic):
return {"ok": True, "status": "already_generating"}
guides = await list_guides()
@@ -271,7 +280,7 @@ async def trigger_suggestions(topic: str):
html_path, _ = final_paths(g["topic"], g["format"])
if html_path.exists():
html_paths.append(html_path)
asyncio.create_task(generate_suggestions(topic, html_paths))
asyncio.create_task(generate_suggestions(topic, html_paths, provider))
return {"ok": True}