import json import logging import litellm from app.config import settings logger = logging.getLogger(__name__) def _proxy_model(model_id: str) -> str: """Always prefix model with openai/ when using a proxy. The proxy (Bifrost) expects provider/model format; litellm strips ONE openai/ prefix before sending to OpenAI-compatible endpoints, so we wrap with an extra openai/.""" if settings.LITELLM_API_BASE: 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": ["