samvish commited on
Commit
515e2a7
·
verified ·
1 Parent(s): 37a6f1f

Delete app

Browse files
Files changed (4) hide show
  1. app/__init__.py +0 -5
  2. app/agent.py +0 -52
  3. app/config.py +0 -10
  4. app/main.py +0 -78
app/__init__.py DELETED
@@ -1,5 +0,0 @@
1
- """
2
- Gmail Agent API using Gemini and Composio
3
- """
4
-
5
- __version__ = "1.0.0"
 
 
 
 
 
 
app/agent.py DELETED
@@ -1,52 +0,0 @@
1
- # app/agent.py
2
- from llama_index.core import Settings
3
- from llama_index.llms.gemini import Gemini
4
- from llama_index.core.agent import FunctionCallingAgentWorker
5
- from composio_llamaindex import ComposioToolSet, App
6
- from llama_index.core.llms import ChatMessage
7
-
8
- class GmailAgent:
9
- def __init__(self, google_api_key: str, composio_api_key: str):
10
- # Set up Gemini LLM
11
- Settings.llm = Gemini(
12
- model="models/gemini-1.5-pro",
13
- api_key=google_api_key
14
- )
15
-
16
- # Initialize Composio ToolSet
17
- self.composio_toolset = ComposioToolSet(api_key=composio_api_key)
18
- self.gmail_tools = self.composio_toolset.get_tools(apps=[App.GMAIL])
19
-
20
- # Set up agent
21
- prefix_messages = [
22
- ChatMessage(
23
- role="system",
24
- content="""You are a Gmail Assistant that can:
25
- - Read and analyze email content
26
- - Draft professional replies
27
- - Manage email threads
28
- Use the available Gmail tools to perform these actions."""
29
- )
30
- ]
31
-
32
- agent_worker = FunctionCallingAgentWorker.from_tools(
33
- tools=self.gmail_tools,
34
- prefix_messages=prefix_messages,
35
- verbose=True
36
- )
37
- self.agent = agent_worker.as_agent()
38
-
39
- def authenticate_gmail(self):
40
- request = self.composio_toolset.initiate_connection(app=App.GMAIL)
41
- return request.redirectUrl
42
-
43
- async def process_email(self, thread_id: str, email_content: str, sender_email: str):
44
- prompt = f"""Analyze this email and create an appropriate reply:
45
- Thread ID: {thread_id}
46
- Sender: {sender_email}
47
- Content: {email_content}
48
-
49
- Please draft a professional response and use the appropriate Gmail tool to send it."""
50
-
51
- response = await self.agent.achat(prompt)
52
- return str(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/config.py DELETED
@@ -1,10 +0,0 @@
1
- # app/config.py
2
- import os
3
- from dotenv import load_dotenv
4
-
5
- load_dotenv()
6
-
7
- class Config:
8
- GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
9
- COMPOSIO_API_KEY = os.getenv("COMPOSIO_API_KEY")
10
- ALLOWED_ORIGINS = ["*"] # Adjust for production
 
 
 
 
 
 
 
 
 
 
 
app/main.py DELETED
@@ -1,78 +0,0 @@
1
- # app/main.py
2
- import os
3
- import logging
4
- from fastapi import FastAPI, HTTPException
5
- from fastapi.middleware.cors import CORSMiddleware
6
- from pydantic import BaseModel
7
- from .config import Config
8
- from .agent import GmailAgent
9
- # Set up logging
10
- logging.basicConfig(level=logging.DEBUG)
11
- logger = logging.getLogger(__name__)
12
-
13
- # Log environment variables
14
- logger.debug(f"GOOGLE_API_KEY: {os.getenv('GOOGLE_API_KEY')}")
15
- logger.debug(f"COMPOSIO_API_KEY: {os.getenv('COMPOSIO_API_KEY')}")
16
-
17
- # Rest of your existing code...
18
- app = FastAPI(
19
- title="Gmail Agent API",
20
- description="API for Gmail management using Gemini and Composio",
21
- version="1.0.0"
22
- )
23
-
24
- # Add CORS middleware
25
- app.add_middleware(
26
- CORSMiddleware,
27
- allow_origins=Config.ALLOWED_ORIGINS,
28
- allow_credentials=True,
29
- allow_methods=["*"],
30
- allow_headers=["*"],
31
- )
32
-
33
- # Initialize Gmail Agent
34
- gmail_agent = GmailAgent(
35
- google_api_key=Config.GOOGLE_API_KEY,
36
- composio_api_key=Config.COMPOSIO_API_KEY
37
- )
38
-
39
- class EmailRequest(BaseModel):
40
- thread_id: str
41
- email_content: str
42
- sender_email: str
43
-
44
- @app.get("/")
45
- async def root():
46
- """
47
- Root endpoint that provides API information and health check
48
- """
49
- return {
50
- "status": "online",
51
- "version": __version__,
52
- "name": "Gmail Agent API",
53
- "description": "Gmail Agent API using Gemini and Composio"
54
- }
55
-
56
- @app.get("/health")
57
- async def health_check():
58
- return {"status": "healthy"}
59
-
60
- @app.get("/authenticate")
61
- async def get_auth_url():
62
- try:
63
- auth_url = gmail_agent.authenticate_gmail()
64
- return {"auth_url": auth_url}
65
- except Exception as e:
66
- raise HTTPException(status_code=500, detail=str(e))
67
-
68
- @app.post("/process-email")
69
- async def process_email(request: EmailRequest):
70
- try:
71
- response = await gmail_agent.process_email(
72
- thread_id=request.thread_id,
73
- email_content=request.email_content,
74
- sender_email=request.sender_email
75
- )
76
- return {"response": response}
77
- except Exception as e:
78
- raise HTTPException(status_code=500, detail=str(e))