File size: 1,041 Bytes
0c36a84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from agents.question_agent import suggest_questions
from agents.rag_agent import answer_question

app = FastAPI()

# --- CORS ์„ค์ • ์ถ”๊ฐ€ ---
origins = [
    "http://localhost:5173",  # Vite ๊ธฐ๋ณธ ํฌํŠธ
    "http://127.0.0.1:5173",
    "*",                      # ๊ฐœ๋ฐœ ๋‹จ๊ณ„์—์„œ๋Š” ์ „์ฒด ํ—ˆ์šฉ ๊ฐ€๋Šฅ
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)
# ------------------------


@app.get("/health")
def health():
    return {"status": "ok"}

@app.post("/suggest")
def suggest(data: dict):
    print(f"๐Ÿ“ฅ [POST /suggest] Request Body: {data}")
    return suggest_questions(data["user_message"], data.get("user_profile", {}))

@app.post("/answer")
def answer(data: dict):
    print(f"๐Ÿ“ฅ [POST /answer] Request Body: {data}")
    return answer_question(data["selected_question"], data.get("user_profile", {}))