From 6227f2a9d4c1c1d5d9d6af245d58f924d9d5e756 Mon Sep 17 00:00:00 2001 From: Abdullah Razzaq Date: Fri, 28 Aug 2026 20:46:28 +0500 Subject: [PATCH] fix(integration): forward bearer token in quiz proxy and sync groq model config --- ai-ml/quiz_generator/app/config.py | 2 +- web/backend/routes/quiz.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ai-ml/quiz_generator/app/config.py b/ai-ml/quiz_generator/app/config.py index 5935e37..ae6acca 100644 --- a/ai-ml/quiz_generator/app/config.py +++ b/ai-ml/quiz_generator/app/config.py @@ -9,7 +9,7 @@ GROQ_API_KEY = os.getenv("GROQ_API_KEY", "") -GROQ_MODEL = "llama-3.3-70b-versatile" +GROQ_MODEL = os.getenv("GROQ_MODEL", "llama-3.1-8b-instant") # ========================================== diff --git a/web/backend/routes/quiz.py b/web/backend/routes/quiz.py index 356f1ec..9478654 100644 --- a/web/backend/routes/quiz.py +++ b/web/backend/routes/quiz.py @@ -5,6 +5,7 @@ import logging from datetime import datetime, timezone from typing import Optional, Dict, Any, List +from auth_utils import get_current_user_email, create_access_token import httpx from fastapi import APIRouter, HTTPException, Request, Depends, Header @@ -38,18 +39,24 @@ async def generate_quiz_proxy( and filters out answers so the frontend receives ONLY questions without answers. """ # Extract user ID if available from auth header or request + # Extract user ID if available from auth header or request auth_header = req.headers.get("Authorization", "") user_id = "anonymous" if auth_header.startswith("Bearer "): try: from auth_utils import decode_access_token token = auth_header.split(" ")[1] - payload = decode_access_token(token) - if payload and "sub" in payload: - user_id = payload["sub"] + payload_token = decode_access_token(token) + if payload_token and "sub" in payload_token: + user_id = payload_token["sub"] except Exception: pass + # Ensure internal token is attached for the AI Quiz Generator service + forward_headers = { + "Authorization": f"Bearer {create_access_token(user_id)}" + } + target_url = f"{QUIZ_SERVICE_URL.rstrip('/')}/generate-quiz" payload = { "topic": body.topic.strip(), @@ -66,7 +73,7 @@ async def generate_quiz_proxy( ) async with httpx.AsyncClient(timeout=timeout) as client: - response = await client.post(target_url, json=payload) + response = await client.post(target_url, json=payload, headers=forward_headers) if response.status_code == 200: data = response.json()