Spaces:
Sleeping
Sleeping
File size: 1,135 Bytes
402298d |
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 |
"""Helper functions for building API responses"""
from typing import Optional, List, Dict, Any
from app.models.jira_schema import QueryResponse, ChartData
def build_query_response(
answer: str,
chart_type: Optional[str] = None,
chart_data: Optional[List[Dict]] = None,
sources: Optional[List[str]] = None
) -> QueryResponse:
"""Build a structured query response"""
chart = None
if chart_type and chart_data:
chart = ChartData(type=chart_type, data=chart_data)
return QueryResponse(
answer=answer,
chart=chart,
sources=sources
)
def extract_chart_intent(query: str) -> Optional[str]:
"""Determine if query requires visualization"""
chart_keywords = {
"bar": ["compare", "by project", "breakdown", "distribution"],
"line": ["trend", "over time", "timeline", "progress"],
"pie": ["percentage", "proportion", "share"]
}
query_lower = query.lower()
for chart_type, keywords in chart_keywords.items():
if any(keyword in query_lower for keyword in keywords):
return chart_type
return None
|