forked from tavily-ai/meeting-prep-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (56 loc) · 2.24 KB
/
Copy pathapp.py
File metadata and controls
73 lines (56 loc) · 2.24 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
70
71
72
73
import json
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import StreamingResponse
from pydantic import BaseModel
from backend.agent import MeetingPlanner
app = FastAPI()
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"], # Vite's default port
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class DateRequest(BaseModel):
date: str
@app.post("/api/analyze-meetings")
async def analyze_meetings(request: DateRequest):
try:
# Create and initialize the meeting planner
planner = MeetingPlanner()
# Build the graph
graph = planner.build_graph()
async def event_generator():
# Run the graph with the given date and stream events
async for event in graph.astream_events({"date": request.date}):
kind = event["event"]
tags = event.get("tags", [])
if kind == "on_chat_model_stream":
content = event["data"]["chunk"].content
if "streaming" in tags:
yield json.dumps(
{"type": "streaming", "content": content}
) + "\n"
print(content)
elif kind == "on_custom_event":
event_name = event["name"]
if event_name in [
"calendar_status",
"calendar_parser_status",
"react_status",
"markdown_formatter_status",
"company_event",
]:
yield json.dumps(
{"type": event_name, "content": event["data"]}
) + "\n"
# if event_name == "company_event":
# print(f"Company Event Data: {event['data']}")
return StreamingResponse(event_generator(), media_type="application/json")
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5000)