Spaces:
Paused
Paused
File size: 1,676 Bytes
5eb4857 | 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 | from typing import Any, Dict, List
from langchain_core.prompts import ChatPromptTemplate
from core.llm import get_llm
from datetime import datetime
ANALYTICS_PROMPT = """
You are a Senior Service Delivery Manager. Analyze the FOLLOWING metrics and recent ticket data (last 48h).
Generate a concise, high-impact "Executive Health Narrative" for the workspace lead.
Current Metrics:
- SLA Compliance: {sla_rate}%
- Breached Count: {breaches}
- Analyzed Tickets: {ticket_count}
Ticket Data:
{ticket_data}
REPORT RULES:
1. MAXIMUM 4-5 LINES total.
2. Structure: One sentence on Overall Health (Green/Amber/Red), one on the primary volume/breach driver, and one on a specific tactical recommendation.
3. Use bolding to highlight critical metrics or actions. Professional Markdown format.
"""
async def generate_service_insights(metrics: Dict[str, Any], tickets: List[Dict[str, Any]]) -> str:
"""
Generates an executive summary of service performance using LLM analytics.
"""
llm = get_llm()
# Format ticket data for analysis (Privacy-Safe: No Titles)
formatted_data = "\n".join([
f"- [{t['priority']}] Category: {t.get('category' or 'General')} (Active for {t['duration_mins']:.1f}m)"
for t in tickets
])
prompt = ChatPromptTemplate.from_template(ANALYTICS_PROMPT)
chain = prompt | llm
response = await chain.ainvoke({
"sla_rate": round(metrics.get("sla_compliance_rate", 0) * 100, 1),
"breaches": metrics.get("breached_tickets", 0),
"ticket_count": len(tickets),
"ticket_data": formatted_data or "No recent ticket data available."
})
return response.content
|