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
8 changes: 1 addition & 7 deletions ai-ml/quiz_generator/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@

GROQ_API_KEY = os.getenv("GROQ_API_KEY", "")

GROQ_MODEL = "openai/gpt-oss-120b"
# NOTE: llama-3.3-70b-versatile has been deprecated by Groq and no
# longer resolves (404 model_not_found). openai/gpt-oss-120b is
# Groq's current recommended general-purpose/reasoning replacement
# as of this writing. This was silently breaking all live quiz
# generation (MCQ, true/false, fill-blank, short-answer all share
# this config) until fixed.
GROQ_MODEL = os.getenv("GROQ_MODEL", "llama-3.1-8b-instant")


# ==========================================
Expand Down
15 changes: 11 additions & 4 deletions web/backend/routes/quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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()
Expand Down
Loading