- Introduced a new `/analyze` endpoint in the analyst API to process analysis requests, allowing users to receive textual interpretations and chart specifications based on provided prompts. - Enhanced `analyst_schemas.py` with `AnalyzeRequest` and `ChartSpec` models to structure analysis requests and validate chart specifications. - Implemented chart validation logic in a new `analyst_chart.py` service, ensuring that chart types and fields are correctly specified and conform to allowed values. - Updated `AnalystAgent` to handle analysis requests, integrating the new logic for generating responses based on user prompts and data availability. - Added unit tests to verify the functionality of the new endpoint and validation mechanisms, ensuring robustness and reliability. This update significantly enhances the analytical capabilities of the application, providing users with improved tools for data interpretation and visualization.
31 lines
840 B
Python
31 lines
840 B
Python
import json
|
|
import sys
|
|
from sqlalchemy import text
|
|
from app.config.database import get_agent_engine
|
|
|
|
hours = int(sys.argv[1]) if len(sys.argv) > 1 else 3
|
|
e = get_agent_engine()
|
|
with e.connect() as c:
|
|
rows = c.execute(
|
|
text(
|
|
"""
|
|
SELECT created_at, trace_id, event_type, agent_type, actor_id, decision, input_summary
|
|
FROM audit_log
|
|
WHERE created_at >= NOW() - INTERVAL :h HOUR
|
|
ORDER BY created_at DESC
|
|
LIMIT 60
|
|
"""
|
|
),
|
|
{"h": hours},
|
|
).mappings().all()
|
|
for row in rows:
|
|
d = dict(row)
|
|
s = d.get("input_summary")
|
|
if isinstance(s, str):
|
|
try:
|
|
s = json.loads(s)
|
|
except json.JSONDecodeError:
|
|
pass
|
|
d["input_summary"] = s
|
|
print(json.dumps(d, ensure_ascii=False, default=str))
|