-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
58 lines (42 loc) · 1.12 KB
/
Copy pathapi.py
File metadata and controls
58 lines (42 loc) · 1.12 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
from fastapi import FastAPI, HTTPException
#cors 에러 방지
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from google.genai._gaos.lib.compat_errors import RateLimitError
from agent import run_agent
app = FastAPI()
#cors 에러 방지
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:5173",
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class AgentRequest(BaseModel):
message: str
@app.get("/")
def root():
return {
"message": "AI Agent API is running"
}
@app.post("/agent")
def agent(request: AgentRequest):
try:
result = run_agent(request.message)
return {
"result": result
}
except RateLimitError:
raise HTTPException(
status_code=429,
detail="Gemini API 일일 요청 한도를 초과했습니다."
)
except Exception as e:
print(f"[Agent Error] {e}")
raise HTTPException(
status_code=500,
detail="Agent 요청 처리 중 오류가 발생했습니다."
)