gmail-agent / app /main.py
samvish's picture
some shit2 idk
bb221ae
# app/main.py
import os
import logging
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from .config import Config
from .agent import GmailAgent
# Set up logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
# Log environment variables
logger.debug(f"GOOGLE_API_KEY: {os.getenv('GOOGLE_API_KEY')}")
logger.debug(f"COMPOSIO_API_KEY: {os.getenv('COMPOSIO_API_KEY')}")
# Rest of your existing code...
app = FastAPI(
title="Gmail Agent API",
description="API for Gmail management using Gemini and Composio",
version="1.0.0"
)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=Config.ALLOWED_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Initialize Gmail Agent
gmail_agent = GmailAgent(
google_api_key=Config.GOOGLE_API_KEY,
composio_api_key=Config.COMPOSIO_API_KEY
)
class EmailRequest(BaseModel):
thread_id: str
email_content: str
sender_email: str
@app.get("/")
async def root():
"""
Root endpoint that provides API information and health check
"""
return {
"status": "online",
"version": __version__,
"name": "Gmail Agent API",
"description": "Gmail Agent API using Gemini and Composio"
}
@app.get("/health")
async def health_check():
return {"status": "healthy"}
@app.get("/authenticate")
async def get_auth_url():
try:
auth_url = gmail_agent.authenticate_gmail()
return {"auth_url": auth_url}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.post("/process-email")
async def process_email(request: EmailRequest):
try:
response = await gmail_agent.process_email(
thread_id=request.thread_id,
email_content=request.email_content,
sender_email=request.sender_email
)
return {"response": response}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))