-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (58 loc) · 1.9 KB
/
main.py
File metadata and controls
69 lines (58 loc) · 1.9 KB
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
66
67
68
69
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
import os
from dotenv import load_dotenv
from notion_client import Client
import logging
from routers import vector_router, waha_router, chatery_router
from security import Secured
# Load environment variables
load_dotenv()
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Initialize FastAPI app
app = FastAPI(
title="Cloud Brain API",
description="FastAPI application to interact with Notion API and provide RAG capabilities",
version="1.0.0"
)
# Include routers
app.include_router(vector_router.router)
app.include_router(waha_router.router)
app.include_router(chatery_router.router)
# Add CORS middleware
cors_allow_origins = os.getenv("CORS_ALLOW_ORIGINS", "*")
allow_origins = [origin.strip() for origin in cors_allow_origins.split(",")]
app.add_middleware(
CORSMiddleware,
allow_origins=allow_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Initialize Notion client
notion_api_key = os.getenv("NOTION_API_KEY")
if not notion_api_key:
raise ValueError("NOTION_API_KEY environment variable is required")
notion = Client(auth=notion_api_key)
# Dependency to get Notion client
def get_notion_client():
return notion
@app.get("/")
async def root():
"""Root endpoint"""
return {"message": "Cloud Brain API is running"}
@app.get("/health", dependencies=[Secured])
async def health_check():
"""Health check endpoint"""
try:
# Test Notion API connection
notion.users.me()
return {"status": "healthy", "notion_api": "connected"}
except Exception as e:
logger.error(f"Health check failed: {str(e)}")
raise HTTPException(status_code=503, detail="Service unavailable")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)