checking system…
Docs / back / src/maf/dashboard/routers/wizard.py · line 23
Python · 49 lines
 1"""Wizard endpoint — scaffold a new arena from an LLM-planned description."""
 2
 3from __future__ import annotations
 4
 5import logging
 6from typing import Any
 7
 8from fastapi import APIRouter, HTTPException
 9from pydantic import BaseModel
10
11from maf.dashboard import state
12
13logger = logging.getLogger(__name__)
14
15router = APIRouter()
16
17
18class WizardRequest(BaseModel):
19    description: str
20
21
22@router.post("/api/wizard")
23async def wizard_create(req: WizardRequest) -> dict[str, Any]:
24    """Plan-and-scaffold a new arena from a free-text description."""
25    maf_app = state.require_maf_app()
26
27    from maf.llm.factory import LLMFactory
28    from maf.wizard.planner import ArenaWizard
29    from maf.wizard.scaffolder import ArenaScaffolder
30
31    try:
32        llm_factory = LLMFactory(maf_app.config.llm)
33        llm = llm_factory("deep")
34        wizard = ArenaWizard(llm)
35        config = await wizard.plan_and_validate(req.description)
36
37        scaffolder = ArenaScaffolder()
38        files = scaffolder.scaffold(config)
39
40        return {
41            "arena_name": config.name,
42            "description": config.description,
43            "phases": len(config.phases),
44            "files_created": {k: str(v) for k, v in files.items()},
45        }
46    except Exception as exc:
47        logger.exception("Wizard failed")
48        raise HTTPException(500, str(exc))