Spaces:
Sleeping
Sleeping
Update gaia_api.py
Browse files- gaia_api.py +83 -18
gaia_api.py
CHANGED
|
@@ -1,40 +1,105 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
-
from app import run_agent
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class GaiaRequest(BaseModel):
|
| 8 |
prompt: str
|
| 9 |
-
|
| 10 |
class GaiaResponse(BaseModel):
|
| 11 |
output: str
|
| 12 |
|
| 13 |
@app.post("/predict", response_model=GaiaResponse)
|
| 14 |
-
def predict(
|
| 15 |
"""
|
| 16 |
-
GAIA evaluation
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
try:
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
@app.get("/health")
|
| 26 |
-
def health_check():
|
| 27 |
"""Health check endpoint"""
|
| 28 |
-
return {
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
@app.get("/")
|
| 31 |
-
def root():
|
| 32 |
-
"""Root endpoint with
|
| 33 |
return {
|
| 34 |
"name": "GAIA Test Agent",
|
| 35 |
-
"description": "AI
|
| 36 |
"endpoints": {
|
| 37 |
-
"predict": "/predict",
|
| 38 |
-
"health": "/health"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
+
from app import run_agent # Import from your main app
|
| 4 |
+
import logging
|
| 5 |
|
| 6 |
+
# Set up logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO)
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
app = FastAPI(
|
| 11 |
+
title="GAIA Test Agent API",
|
| 12 |
+
description="API endpoint for GAIA benchmark evaluation",
|
| 13 |
+
version="1.0.0"
|
| 14 |
+
)
|
| 15 |
|
| 16 |
class GaiaRequest(BaseModel):
|
| 17 |
prompt: str
|
| 18 |
+
|
| 19 |
class GaiaResponse(BaseModel):
|
| 20 |
output: str
|
| 21 |
|
| 22 |
@app.post("/predict", response_model=GaiaResponse)
|
| 23 |
+
async def predict(request: GaiaRequest):
|
| 24 |
"""
|
| 25 |
+
Main prediction endpoint for GAIA evaluation
|
| 26 |
+
This is the endpoint that GAIA will call to get answers
|
| 27 |
"""
|
| 28 |
try:
|
| 29 |
+
logger.info(f"Received question: {request.prompt[:100]}...")
|
| 30 |
+
|
| 31 |
+
# Get answer from your agent
|
| 32 |
+
answer = run_agent(request.prompt)
|
| 33 |
+
|
| 34 |
+
logger.info(f"Generated answer: {answer[:100]}...")
|
| 35 |
+
|
| 36 |
+
return GaiaResponse(output=answer)
|
| 37 |
+
|
| 38 |
except Exception as e:
|
| 39 |
+
logger.error(f"Error processing request: {str(e)}")
|
| 40 |
+
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
| 41 |
|
| 42 |
@app.get("/health")
|
| 43 |
+
async def health_check():
|
| 44 |
"""Health check endpoint"""
|
| 45 |
+
return {
|
| 46 |
+
"status": "healthy",
|
| 47 |
+
"message": "GAIA Test Agent is running"
|
| 48 |
+
}
|
| 49 |
|
| 50 |
@app.get("/")
|
| 51 |
+
async def root():
|
| 52 |
+
"""Root endpoint with API information"""
|
| 53 |
return {
|
| 54 |
"name": "GAIA Test Agent",
|
| 55 |
+
"description": "AI Agent for GAIA Benchmark Evaluation",
|
| 56 |
"endpoints": {
|
| 57 |
+
"predict": "/predict - Main prediction endpoint (POST)",
|
| 58 |
+
"health": "/health - Health check (GET)",
|
| 59 |
+
"docs": "/docs - Interactive API documentation (GET)"
|
| 60 |
+
},
|
| 61 |
+
"usage": {
|
| 62 |
+
"predict": {
|
| 63 |
+
"method": "POST",
|
| 64 |
+
"body": {
|
| 65 |
+
"prompt": "Your question here"
|
| 66 |
+
},
|
| 67 |
+
"response": {
|
| 68 |
+
"output": "Agent's answer"
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
@app.get("/info")
|
| 75 |
+
async def info():
|
| 76 |
+
"""Get agent information"""
|
| 77 |
+
return {
|
| 78 |
+
"agent_type": "General AI Assistant",
|
| 79 |
+
"model": "DeepSeek V3.1 Terminus via OpenRouter",
|
| 80 |
+
"capabilities": [
|
| 81 |
+
"General question answering",
|
| 82 |
+
"Mathematical calculations",
|
| 83 |
+
"Factual queries",
|
| 84 |
+
"Yes/No questions",
|
| 85 |
+
"Reasoning tasks"
|
| 86 |
+
],
|
| 87 |
+
"optimized_for": "GAIA benchmark evaluation"
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
# For debugging - remove in production
|
| 91 |
+
@app.get("/test")
|
| 92 |
+
async def test_endpoint():
|
| 93 |
+
"""Test endpoint to verify the agent works"""
|
| 94 |
+
try:
|
| 95 |
+
test_answer = run_agent("What is 2 + 2?")
|
| 96 |
+
return {
|
| 97 |
+
"test_question": "What is 2 + 2?",
|
| 98 |
+
"test_answer": test_answer,
|
| 99 |
+
"status": "Agent working correctly"
|
| 100 |
+
}
|
| 101 |
+
except Exception as e:
|
| 102 |
+
return {
|
| 103 |
+
"status": "Error",
|
| 104 |
+
"error": str(e)
|
| 105 |
+
}
|