Brushed up the backend, added writing task 1 academic prompt gen and grading ENCOA-274
This commit is contained in:
48
ielts_be/services/impl/exam/writing/academic.py
Normal file
48
ielts_be/services/impl/exam/writing/academic.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from base64 import b64encode
|
||||
from typing import List, Dict
|
||||
|
||||
from fastapi.datastructures import UploadFile
|
||||
|
||||
|
||||
async def get_writing_args_academic(task: int, attachment: UploadFile) -> 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'
|
||||
'3. 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.")
|
||||
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": writing_args[str(task)]["prompt"]
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": writing_args[str(task)]["instructions"]
|
||||
}
|
||||
]
|
||||
|
||||
if task == 1:
|
||||
attachment_bytes = await attachment.read()
|
||||
messages.append({
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": f"data:image/{attachment.filename.split('.')[-1]};base64,{b64encode(attachment_bytes).decode('utf-8')}"
|
||||
}
|
||||
})
|
||||
|
||||
return messages
|
||||
Reference in New Issue
Block a user