forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (44 loc) · 1.26 KB
/
Copy pathmain.py
File metadata and controls
55 lines (44 loc) · 1.26 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
import os
import warnings
from pathlib import Path
from dotenv import load_dotenv
# Load .env from the demo project root (one level up from agent/) BEFORE
# importing src.agent — that import constructs ChatOpenAI at module load,
# which needs OPENAI_API_KEY in the environment already.
_demo_root = Path(__file__).parent.parent
for env_path in (_demo_root / ".env", Path(".env")):
if env_path.is_file():
load_dotenv(env_path)
break
else:
load_dotenv()
from fastapi import FastAPI
import uvicorn
from src.agent import graph
from copilotkit import LangGraphAGUIAgent
from ag_ui_langgraph import add_langgraph_fastapi_endpoint
app = FastAPI()
@app.get("/health")
async def health():
return {"status": "ok"}
add_langgraph_fastapi_endpoint(
app=app,
agent=LangGraphAGUIAgent(
name="sample_agent",
description="An example agent to use as a starting point for your own agent.",
graph=graph,
),
path="/",
)
def main():
"""Run the uvicorn server."""
port = int(os.getenv("PORT", "8123"))
uvicorn.run(
"main:app",
host="0.0.0.0",
port=port,
reload=True,
)
warnings.filterwarnings("ignore", category=UserWarning, module="pydantic")
if __name__ == "__main__":
main()