|
|
from fastapi import FastAPI, Depends, HTTPException |
|
|
from fastapi.middleware.cors import CORSMiddleware |
|
|
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials |
|
|
import uvicorn |
|
|
from typing import Dict, Any |
|
|
import logging |
|
|
|
|
|
|
|
|
from .routers import ( |
|
|
document_router, |
|
|
rag_router, |
|
|
agent_router, |
|
|
prompt_router |
|
|
) |
|
|
|
|
|
|
|
|
security = HTTPBearer() |
|
|
|
|
|
|
|
|
app = FastAPI( |
|
|
title="Lattice API", |
|
|
description="API for Lattice AI Development Platform", |
|
|
version="1.0.0" |
|
|
) |
|
|
|
|
|
|
|
|
app.add_middleware( |
|
|
CORSMiddleware, |
|
|
allow_origins=["*"], |
|
|
allow_credentials=True, |
|
|
allow_methods=["*"], |
|
|
allow_headers=["*"], |
|
|
) |
|
|
|
|
|
|
|
|
async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)): |
|
|
try: |
|
|
|
|
|
token = credentials.credentials |
|
|
|
|
|
return token |
|
|
except Exception as e: |
|
|
raise HTTPException( |
|
|
status_code=401, |
|
|
detail="Invalid authentication credentials" |
|
|
) |
|
|
|
|
|
|
|
|
app.include_router( |
|
|
document_router.router, |
|
|
prefix="/api/v1/document", |
|
|
tags=["Document Processing"], |
|
|
dependencies=[Depends(verify_token)] |
|
|
) |
|
|
|
|
|
app.include_router( |
|
|
rag_router.router, |
|
|
prefix="/api/v1/rag", |
|
|
tags=["RAG"], |
|
|
dependencies=[Depends(verify_token)] |
|
|
) |
|
|
|
|
|
app.include_router( |
|
|
agent_router.router, |
|
|
prefix="/api/v1/agent", |
|
|
tags=["Agents"], |
|
|
dependencies=[Depends(verify_token)] |
|
|
) |
|
|
|
|
|
app.include_router( |
|
|
prompt_router.router, |
|
|
prefix="/api/v1/prompt", |
|
|
tags=["Prompts"], |
|
|
dependencies=[Depends(verify_token)] |
|
|
) |
|
|
|
|
|
@app.get("/health") |
|
|
async def health_check(): |
|
|
"""Health check endpoint""" |
|
|
return { |
|
|
"status": "healthy", |
|
|
"version": "1.0.0" |
|
|
} |
|
|
|
|
|
@app.get("/components") |
|
|
async def list_components(): |
|
|
"""List available components and their capabilities""" |
|
|
return { |
|
|
"components": [ |
|
|
{ |
|
|
"name": "document", |
|
|
"version": "1.0.0", |
|
|
"status": "available" |
|
|
}, |
|
|
{ |
|
|
"name": "rag", |
|
|
"version": "1.0.0", |
|
|
"status": "available" |
|
|
}, |
|
|
{ |
|
|
"name": "agent", |
|
|
"version": "1.0.0", |
|
|
"status": "available" |
|
|
}, |
|
|
{ |
|
|
"name": "prompt", |
|
|
"version": "1.0.0", |
|
|
"status": "available" |
|
|
} |
|
|
] |
|
|
} |
|
|
|
|
|
if __name__ == "__main__": |
|
|
uvicorn.run(app, host="0.0.0.0", port=8000) |