import json import logging import litellm from app.config import settings logger = logging.getLogger(__name__) def _proxy_model(model_id: str) -> str: """Prefix model with openai/ if using a LiteLLM proxy and no provider is specified.""" if settings.LITELLM_API_BASE and "/" not in model_id: return f"openai/{model_id}" return model_id EXTRACTION_PROMPT = """You are extracting questions from a PREP (Pediatric Review and Education Program) exam PDF. These PDFs have questions with a clinical vignette, followed by five answer options A-E. Some PDFs include "Correct Answer: X" or "Preferred Response: X" right after the options. Some PDFs have the correct answers only at the END of the document — in that case correct_answer will be null. Return ONLY a JSON object: {{"questions": [ {{ "item_number": "", "question_text": "", "question_type": "mcq", "options": ["