Release Cognitive Agent Evaluator v2.0 (10-axis biases, Plotly radar, burnout & psychological safety telemetry)
c6c178c verified Download src/api.py from neurodeveloper/cognitive-agent-evaluator: direct link, hf CLI and curl.
- Browser
- Download file 3.2 kB
-
https://huggingface.co/spaces/neurodeveloper/cognitive-agent-evaluator/resolve/main/src/api.py
- Command line
-
hf download hf://spaces/neurodeveloper/cognitive-agent-evaluator/src/api.py
-
curl -L -o api.py https://huggingface.co/spaces/neurodeveloper/cognitive-agent-evaluator/resolve/main/src/api.py
3.2 kB
| """ | |
| FastAPI REST API and Interactive Dashboard for Cognitive Agent Evaluator. | |
| """ | |
| from typing import List, Dict, Any | |
| from fastapi import FastAPI, HTTPException, status | |
| from fastapi.responses import HTMLResponse | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from src.schemas import EvaluationRequest, EvaluationResult | |
| from src.agent import CognitiveEvaluationAgent | |
| from src.biases import BIAS_DEFINITIONS | |
| from src.ui import HTML_DASHBOARD | |
| agent = CognitiveEvaluationAgent() | |
| app = FastAPI( | |
| title="Cognitive Agent Evaluator & Behavioral Telemetry API", | |
| description="Autonomous Agent for evaluating cognitive biases, emotional valence, and psychometric alignment in human & LLM reasoning. Engineered by Fabio Torres (neurodeveloper11).", | |
| version="1.0.0", | |
| docs_url="/docs", | |
| redoc_url="/redoc" | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| async def root_ui(): | |
| """ | |
| Serves the modern, intuitive interactive dashboard for testing the agent live. | |
| """ | |
| return HTMLResponse(content=HTML_DASHBOARD) | |
| async def api_info(): | |
| """ | |
| Returns JSON metadata about the project and endpoints. | |
| """ | |
| return { | |
| "project": "Cognitive Agent Evaluator & Behavioral Telemetry Engine", | |
| "author": "Fabio Torres (neurodeveloper11)", | |
| "docs": "/docs", | |
| "health": "/health", | |
| "status": "operational" | |
| } | |
| async def health_check(): | |
| return { | |
| "status": "healthy", | |
| "agent": agent.agent_name, | |
| "supported_biases": list(BIAS_DEFINITIONS.keys()) | |
| } | |
| async def evaluate_text(payload: EvaluationRequest): | |
| """ | |
| Submits a text trace or LLM output for cognitive bias detection, | |
| psychometric telemetry scoring, and alignment mitigation. | |
| """ | |
| try: | |
| return await agent.evaluate(payload) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def get_bias_taxonomy() -> Dict[str, Any]: | |
| """ | |
| Returns the supported cognitive bias taxonomy, heuristics, and severity levels. | |
| """ | |
| return { | |
| bias: { | |
| "severity": meta["severity"], | |
| "explanation": meta["explanation"] | |
| } | |
| for bias, meta in BIAS_DEFINITIONS.items() | |
| } | |
| async def batch_evaluate(requests: List[EvaluationRequest]): | |
| """ | |
| Batch processes multiple text traces for benchmark evaluation. | |
| """ | |
| if len(requests) > 50: | |
| raise HTTPException(status_code=400, detail="Maximum batch size is 50 requests.") | |
| results: List[EvaluationResult] = [] | |
| for req in requests: | |
| res = await agent.evaluate(req) | |
| results.append(res) | |
| return results | |