Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions web/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pypdf import PdfReader
import httpx

from models import (
from web.backend.models import (
SignupRequest,
LoginRequest,
Upload,
Expand All @@ -20,24 +20,24 @@
QuizResult,
QuizResultRequest,
)
from database import (
from web.backend.database import (
get_users_collection,
get_uploads_collection,
get_chat_history_collection,
get_quiz_results_collection,
)
from auth_utils import (
from web.backend.auth_utils import (
hash_password,
verify_password,
create_access_token,
get_current_user_email,
verify_internal_service_key,
)
from routes.chat import router as chat_router
from routes.oauth import router as oauth_router
from routes.quiz import router as quiz_router
from routes.flashcards import router as flashcards_router
from routes.roadmap import router as roadmap_router
from web.backend.routes.chat import router as chat_router
from web.backend.routes.oauth import router as oauth_router
from web.backend.routes.quiz import router as quiz_router
from web.backend.routes.flashcards import router as flashcards_router
from web.backend.routes.roadmap import router as roadmap_router

logger = logging.getLogger("uvicorn")

Expand Down Expand Up @@ -100,13 +100,13 @@ async def process_file_ingestion(file_id: Any, document_id: str, filename: str,
with open(file_path, "rb") as f:
file_bytes = f.read()

async with httpx.AsyncClient(timeout=15) as client:
internal_token = create_access_token(email=user_id)
response = await client.post(
f"{INGESTION_SERVICE_URL.rstrip('/')}/ingest/pdf",
files={"file": (filename, file_bytes, "application/pdf")},
headers={"Authorization": f"Bearer {internal_token}"},
)
async with httpx.AsyncClient(timeout=120) as client:
internal_token = create_access_token(email=user_id)
response = await client.post(
f"{INGESTION_SERVICE_URL.rstrip('/')}/ingest/pdf",
files={"file": (filename, file_bytes, "application/pdf")},
headers={"Authorization": f"Bearer {internal_token}"},
)

if response.status_code == 200:
try:
Expand All @@ -126,11 +126,11 @@ async def process_file_ingestion(file_id: Any, document_id: str, filename: str,
)

except Exception as e:
logger.warning(
f"Ingestion error for {filename} ({document_id}): {e}"
)
error_details = f"{type(e).__name__}: {repr(e)}"
print(f"INGESTION_EXCEPTION: {error_details}", flush=True)
logger.error(f"INGESTION_EXCEPTION: {error_details}", flush=True)
new_status = "Failed"
last_error = str(e)
last_error = error_details
else:
new_status = "Failed"
last_error = "File not found on disk"
Expand Down
Empty file added web/backend/routes/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions web/backend/routes/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def ask(
current_user_email: str = Depends(get_current_user_email),
):
# Strictly derive user_id from the authenticated JWT session (email) only.
resolved_user_id = current_user_email
resolved_user_id = current_user_email.strip().lower()

# Helper to check if user is asking for a general summary/overview
q_lower = request.question.lower().strip()
Expand Down Expand Up @@ -157,4 +157,4 @@ async def ask(
"Chatbot service is currently unavailable. "
"Please make sure it's running and try again."
),
)
)
Loading