Fixed grading ENCOA-274

This commit is contained in:
Carlos-Mesquita
2024-12-11 16:51:18 +00:00
parent fa028aa0e7
commit e076eaaeb7
5 changed files with 17 additions and 12 deletions

View File

@@ -23,7 +23,6 @@ async def grade_writing_task(
return await grade_controller.grade_writing_task(task, data, background_tasks)
@grade_router.post(
'/speaking/{task}',
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]

View File

@@ -106,6 +106,7 @@ class FilePaths:
FIREBASE_LISTENING_AUDIO_FILES_PATH = 'listening_recordings/'
VIDEO_FILES_PATH = 'download-video/'
FIREBASE_SPEAKING_VIDEO_FILES_PATH = 'speaking_videos/'
WRITING_ATTACHMENTS = 'writing_attachments/'
class TemperatureSettings:

View File

@@ -25,7 +25,7 @@ class GradeController(IGradeController):
self,
task: int, dto: WritingGradeTaskDTO, background_tasks: BackgroundTasks
):
if task == 1 and dto.type == "academic" and dto.attachment is None:
if task == 1 and dto.attachment is None:
raise HTTPException(status_code=400, detail="Academic writing task requires a picture!")
await self._evaluation_service.create_evaluation(

View File

@@ -9,4 +9,4 @@ class WritingGradeTaskDTO(BaseModel):
exerciseId: str
question: str
answer: str
attachment: Optional[str]
attachment: Optional[str] = None

View File

@@ -1,8 +1,9 @@
import asyncio
import os
from typing import Dict, Optional
from uuid import uuid4
from ielts_be.configs.constants import GPTModels, TemperatureSettings
from ielts_be.configs.constants import GPTModels, TemperatureSettings, FilePaths
from ielts_be.helpers import TextHelper, ExercisesHelper, FileHelper
from ielts_be.repositories import IFileStorage
from ielts_be.services import ILLMService, IAIDetectorService
@@ -54,19 +55,23 @@ class GradeWriting:
})
else:
uuid = str(uuid4())
name = attachment.split('/')[-1]
name = attachment.split('%2F')[-1].split('?')[0]
os.makedirs(f'./tmp/{uuid}/', exist_ok=True)
out_path = f'./tmp/{uuid}/{name}'
path = await self._file_storage.download_firebase_file(attachment, out_path)
path = await self._file_storage.download_firebase_file(f'{FilePaths.WRITING_ATTACHMENTS}{name}', out_path)
b64_image = await FileHelper.encode_image(path)
messages.append(
{
"role": "user",
"content": {
"type": "image_url",
"image_url": {
"url": f"data:image/{name.split('.')[-1]};base64,{FileHelper.encode_image(path)}"
}
"content": [{
"type": "image_url",
"image_url": {
"url": f"data:image/{name.split('.')[-1]};base64,{b64_image}"
}
}]
}
})
)
FileHelper.remove_directory(f'./tmp/{uuid}')
temperature = (
TemperatureSettings.GRADING_TEMPERATURE