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 follow a strict format: 1. A numbered question with a clinical vignette (patient scenario) 2. Five answer options labeled A, B, C, D, E 3. A line "Correct Answer: X" or "Preferred Response: X" where X is the letter of the correct option 4. An explanation paragraph 5. A "Critique:" section with detailed reasoning 6. A "Content Specifications:" section listing the learning objectives Your task: extract every question and return ONLY a JSON object in this exact format: {{"questions": [ {{ "item_number": "", "question_text": "", "question_type": "mcq", "options": ["