Spaces:
Running
Running
File size: 828 Bytes
dc124db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | from __future__ import annotations
import json
from typing import List, Any
from quiz.models import Quest
from services.model_router import ModelRouter
from services.json_parser import extract_json
from config.prompts import QUEST_AGENT_SYSTEM
class QuestAgent:
def __init__(self, router: ModelRouter): self._router = router
def generate(self, concepts: Any) -> List[Quest]:
raw = self._router.reason(f"Generate quests from:\n{json.dumps(concepts)}", QUEST_AGENT_SYSTEM)
try:
data = extract_json(raw)
except ValueError as exc:
raise ValueError(f"QuestAgent: {exc}") from exc
return [Quest(name=q["name"], topics=q.get("topics",[]), boss_topic=q.get("boss_topic",""),
difficulty=q.get("difficulty","medium")) for q in data.get("quests",[])]
|