ENCOA-311

This commit is contained in:
Carlos-Mesquita
2025-01-13 01:13:28 +00:00
parent 8550b520e1
commit b32e38156c
27 changed files with 126 additions and 62 deletions

View File

@@ -1,3 +1,4 @@
import random
from typing import List, Dict, Optional
from fastapi import UploadFile
@@ -16,7 +17,8 @@ class WritingService(IWritingService):
self._llm = llm
self._grade = GradeWriting(llm, file_storage, ai_detector)
async def get_writing_task_general_question(self, task: int, topic: str, difficulty: str):
async def get_writing_task_general_question(self, task: int, topic: str, difficulty: List[str]):
diff = difficulty[0] if len(difficulty) == 1 else random.choice(difficulty)
messages = [
{
"role": "system",
@@ -24,7 +26,7 @@ class WritingService(IWritingService):
'You are a helpful assistant designed to output JSON on this format: {"prompt": "prompt content"}'
)
},
*get_writing_args_general(task, topic, difficulty)
*get_writing_args_general(task, topic, diff)
]
llm_model = GPTModels.GPT_3_5_TURBO if task == 1 else GPTModels.GPT_4_O
@@ -40,11 +42,12 @@ class WritingService(IWritingService):
return {
"question": self._add_newline_before_hyphen(question) if task == 1 else question,
"difficulty": difficulty,
"topic": topic
"topic": topic,
"difficulty": diff
}
async def get_writing_task_academic_question(self, task: int, file: UploadFile, difficulty: str):
async def get_writing_task_academic_question(self, task: int, file: UploadFile, difficulty: List[str]):
diff = difficulty[0] if len(difficulty) == 1 else random.choice(difficulty)
messages = [
{
"role": "system",
@@ -52,7 +55,7 @@ class WritingService(IWritingService):
'You are a helpful assistant designed to output JSON on this format: {"prompt": "prompt content"}'
)
},
*(await get_writing_args_academic(task, file))
*(await get_writing_args_academic(task, file, diff))
]
response = await self._llm.prediction(
@@ -66,7 +69,7 @@ class WritingService(IWritingService):
return {
"question": self._add_newline_before_hyphen(question) if task == 1 else question,
"difficulty": difficulty,
"difficulty": diff,
}
async def grade_writing_task(self, task: int, question: str, answer: str, attachment: Optional[str] = None):

View File

@@ -4,7 +4,7 @@ from typing import List, Dict
from fastapi.datastructures import UploadFile
async def get_writing_args_academic(task: int, attachment: UploadFile) -> List[Dict]:
async def get_writing_args_academic(task: int, attachment: UploadFile, difficulty: str) -> List[Dict]:
writing_args = {
"1": {
"prompt": (
@@ -16,7 +16,8 @@ async def get_writing_args_academic(task: int, attachment: UploadFile) -> List[D
'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'
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."'
)
},