from base64 import b64encode from typing import List, Dict from fastapi.datastructures import UploadFile async def get_writing_args_academic(task: int, attachment: UploadFile, difficulty: str) -> List[Dict]: writing_args = { "1": { "prompt": ( 'Analyze the uploaded image and create a detailed IELTS Writing Task 1 Academic prompt.\n' 'Based on the visual data presented, craft a prompt that accurately reflects the image\'s ' 'content, complexity, and academic nature.\n' ), "instructions": ( 'The generated prompt must:\n' '1. Clearly describe the type of visual representation in the image\n' '2. Provide a concise context for the data shown\n' f'3. Be adequate for {difficulty} CEFR level users\n' '4. End with the standard IELTS Task 1 Academic instruction:\n' '"Summarise the information by selecting and reporting the main features, and make comparisons where relevant."' ) }, } if task == 2: raise NotImplemented("Task 2 academic isn't implemented yet, current implementation still uses General Task 2 prompts.") attachment_bytes = await attachment.read() messages = [ { "role": "user", "content": writing_args[str(task)]["prompt"] }, { "role": "user", "content": [ { "type": "text", "text": writing_args[str(task)]["instructions"], }, { "type": "image_url", "image_url": { "url": f"data:image/{attachment.filename.split('.')[-1]};base64,{b64encode(attachment_bytes).decode('utf-8')}" } } ] } ] return messages