MM58-crypto commited on
Commit
9be91cf
Β·
1 Parent(s): 1214561

wooo another commit

Browse files
Files changed (1) hide show
  1. main.py +9 -4
main.py CHANGED
@@ -39,7 +39,7 @@ import requests
39
  import uuid
40
  from dotenv import load_dotenv
41
  from datetime import datetime
42
-
43
  load_dotenv()
44
 
45
  try:
@@ -148,6 +148,11 @@ def run_query(message: str, intent: str, session_id: str) -> str:
148
  app = FastAPI(title="Sebayhi", description="Arabic Grammar Education Tutor")
149
  app.mount("/static", StaticFiles(directory="static"), name="static")
150
 
 
 
 
 
 
151
  # fastapi middleware here --> cookies / session generation logic
152
  @app.middleware("http")
153
  async def user_session_management(request: Request, call_next):
@@ -158,7 +163,7 @@ async def user_session_management(request: Request, call_next):
158
 
159
  # this if statement is not running OR session_id is never saved and found on mongodb
160
  if session_id:
161
- retrieved_session = collection.find_one({"session_id": session_id})
162
  print("FOUND SESSION:", session is not None)
163
  if retrieved_session:
164
  collection.update_one(
@@ -209,8 +214,8 @@ class ChatRequest(BaseModel):
209
  # ── Routes ────────────────────────────────────────────────────────────────────
210
 
211
  @app.get("/")
212
- async def serve_ui(request: Request):
213
- session = request.state.session
214
  return FileResponse("static/index.html")
215
 
216
 
 
39
  import uuid
40
  from dotenv import load_dotenv
41
  from datetime import datetime
42
+ from fastapi.middleware.cors import CORSMiddleware
43
  load_dotenv()
44
 
45
  try:
 
148
  app = FastAPI(title="Sebayhi", description="Arabic Grammar Education Tutor")
149
  app.mount("/static", StaticFiles(directory="static"), name="static")
150
 
151
+ app.add_middleware(
152
+ allow_credentials=True,
153
+ allow_methods=["*"],
154
+ allow_headers=["*"]
155
+ )
156
  # fastapi middleware here --> cookies / session generation logic
157
  @app.middleware("http")
158
  async def user_session_management(request: Request, call_next):
 
163
 
164
  # this if statement is not running OR session_id is never saved and found on mongodb
165
  if session_id:
166
+ retrieved_session = collection.find_one({"_id": session_id})
167
  print("FOUND SESSION:", session is not None)
168
  if retrieved_session:
169
  collection.update_one(
 
214
  # ── Routes ────────────────────────────────────────────────────────────────────
215
 
216
  @app.get("/")
217
+ async def serve_ui():
218
+
219
  return FileResponse("static/index.html")
220
 
221