Spaces:
Runtime error

File size: 1,941 Bytes
64fb1e7
6e978f7
 
64fb1e7
 
 
 
 
 
 
6e978f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64fb1e7
6e978f7
64fb1e7
6e978f7
64fb1e7
 
 
6e978f7
 
64fb1e7
6e978f7
 
64fb1e7
 
6e978f7
64fb1e7
 
 
6e978f7
64fb1e7
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import logging
from fastapi import APIRouter, HTTPException

from coaching import coaching_manager

logger = logging.getLogger(__name__)

router = APIRouter()


# ── Voice AI coaching (primary) ───────────────────────────────────────────────

@router.get("/api/coaching/voice-ai/stats")
async def voice_ai_stats():
    """Aggregate performance stats for all Voice AI scored calls."""
    try:
        return await coaching_manager.get_voice_ai_stats()
    except Exception as e:
        logger.error(f"Error fetching Voice AI coaching stats: {e}")
        raise HTTPException(status_code=500, detail=str(e))


@router.get("/api/coaching/voice-ai/packs")
async def voice_ai_packs():
    """Return all Voice AI coaching packs, newest first."""
    try:
        return await coaching_manager.get_voice_ai_packs()
    except Exception as e:
        logger.error(f"Error fetching Voice AI coaching packs: {e}")
        raise HTTPException(status_code=500, detail=str(e))


@router.post("/api/coaching/voice-ai/generate")
async def generate_voice_ai_pack():
    """
    Generate a new Voice AI coaching pack from the most recent scored calls.
    Requires >= 3 scored Voice AI calls (agent_id IS NULL in eval_scores).
    """
    try:
        return await coaching_manager.generate_voice_ai_pack()
    except ValueError as e:
        raise HTTPException(status_code=422, detail=str(e))
    except Exception as e:
        logger.error(f"Error generating Voice AI coaching pack: {e}")
        raise HTTPException(status_code=500, detail=str(e))


@router.get("/api/coaching/pack/{pack_id}")
async def get_coaching_pack(pack_id: str):
    """Return a single coaching pack by ID."""
    pack = await coaching_manager.get_pack_by_id(pack_id)
    if not pack:
        raise HTTPException(status_code=404, detail="Coaching pack not found")
    return pack