Mrigank005 commited on
Commit
28fb9f7
·
verified ·
1 Parent(s): d6c1365

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +48 -48
app/main.py CHANGED
@@ -1,49 +1,49 @@
1
- from fastapi import FastAPI, HTTPException
2
- from fastapi.middleware.cors import CORSMiddleware
3
- from pydantic import BaseModel
4
-
5
- from app.utils import get_rag_response
6
-
7
- app = FastAPI(
8
- title="Portfolio Chatbot API",
9
- description="RAG-based chatbot for Mrigank Singh's portfolio",
10
- version="1.0.0"
11
- )
12
-
13
- # CORS Middleware
14
- app.add_middleware(
15
- CORSMiddleware,
16
- allow_origins=["https://mrigank-portfolio-website.vercel.app", "https://mrigank-portfolio-website.vercel.app/"],
17
- allow_credentials=True,
18
- allow_methods=["*"],
19
- allow_headers=["*"],
20
- )
21
-
22
-
23
- class ChatRequest(BaseModel):
24
- message: str
25
-
26
-
27
- class ChatResponse(BaseModel):
28
- response: str
29
-
30
-
31
- @app.get("/")
32
- async def health_check():
33
- """Health check endpoint for Render."""
34
- return {"status": "ok"}
35
-
36
-
37
- @app.post("/chat", response_model=ChatResponse)
38
- async def chat(request: ChatRequest):
39
- """
40
- Chat endpoint - processes user message through RAG pipeline.
41
- """
42
- if not request.message.strip():
43
- raise HTTPException(status_code=400, detail="Message cannot be empty")
44
-
45
- try:
46
- response = get_rag_response(request.message)
47
- return ChatResponse(response=response)
48
- except Exception as e:
49
  raise HTTPException(status_code=500, detail=f"Error generating response: {str(e)}")
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+
5
+ from app.utils import get_rag_response
6
+
7
+ app = FastAPI(
8
+ title="Portfolio Chatbot API",
9
+ description="RAG-based chatbot for Mrigank Singh's portfolio",
10
+ version="1.0.0"
11
+ )
12
+
13
+ # CORS Middleware
14
+ app.add_middleware(
15
+ CORSMiddleware,
16
+ allow_origins=["https://mrigank.is-a.dev", "https://mrigank.is-a.dev/"],
17
+ allow_credentials=True,
18
+ allow_methods=["*"],
19
+ allow_headers=["*"],
20
+ )
21
+
22
+
23
+ class ChatRequest(BaseModel):
24
+ message: str
25
+
26
+
27
+ class ChatResponse(BaseModel):
28
+ response: str
29
+
30
+
31
+ @app.get("/")
32
+ async def health_check():
33
+ """Health check endpoint for Render."""
34
+ return {"status": "ok"}
35
+
36
+
37
+ @app.post("/chat", response_model=ChatResponse)
38
+ async def chat(request: ChatRequest):
39
+ """
40
+ Chat endpoint - processes user message through RAG pipeline.
41
+ """
42
+ if not request.message.strip():
43
+ raise HTTPException(status_code=400, detail="Message cannot be empty")
44
+
45
+ try:
46
+ response = get_rag_response(request.message)
47
+ return ChatResponse(response=response)
48
+ except Exception as e:
49
  raise HTTPException(status_code=500, detail=f"Error generating response: {str(e)}")