File size: 1,879 Bytes
560d5c2
 
 
 
 
 
f6375d6
 
 
560d5c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import uvicorn
from copilotkit import CopilotKitRemoteEndpoint, LangGraphAgent
from copilotkit.integrations.fastapi import add_fastapi_endpoint
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from app.agent.graph import graph
from app.api import insights
from app.db.database import Base, engine

# Create database tables
Base.metadata.create_all(bind=engine)

app = FastAPI(
    title="InsightCopilot API", description="API for extracting insights from the Sakila database", version="1.0.0"
)

# Configure CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # In production, replace with specific origins
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Initialize CopilotKit SDK
sdk = CopilotKitRemoteEndpoint(
    agents=[
        LangGraphAgent(
            name="insight_copilot_agent",
            description="A copilot agent that can extract insights from the Sakila database",
            graph=graph,
        )
    ],
)

# Add CopilotKit endpoint
add_fastapi_endpoint(app, sdk, "/copilotkit", use_thread_pool=False)

# Include routers
app.include_router(insights.router, prefix="/api/v1", tags=["insights"])


@app.get("/")
async def root():
    return {
        "message": "Welcome to InsightCopilot API",
        "version": "1.0.0",
        "docs_url": "/docs",
        "endpoints": {
            "insights": {
                "top_films": "/api/v1/insights/top-films",
                "category_performance": "/api/v1/insights/category-performance",
                "customer_activity": "/api/v1/insights/customer-activity",
                "store_performance": "/api/v1/insights/store-performance",
                "actor_popularity": "/api/v1/insights/actor-popularity",
            }
        },
    }


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)