Merged in release/async (pull request #45)
Fixed grading ENCOA-274 Approved-by: Tiago Ribeiro
This commit is contained in:
@@ -27,6 +27,7 @@ RUN apt update && apt install -y \
|
||||
texlive-xetex \
|
||||
pandoc \
|
||||
librsvg2-bin \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - \
|
||||
|
||||
@@ -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]))]
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -25,9 +25,6 @@ class GradeController(IGradeController):
|
||||
self,
|
||||
task: int, dto: WritingGradeTaskDTO, background_tasks: BackgroundTasks
|
||||
):
|
||||
if task == 1 and dto.type == "academic" and dto.attachment is None:
|
||||
raise HTTPException(status_code=400, detail="Academic writing task requires a picture!")
|
||||
|
||||
await self._evaluation_service.create_evaluation(
|
||||
dto.userId, dto.sessionId, dto.exerciseId, EvaluationType.WRITING, task
|
||||
)
|
||||
|
||||
@@ -9,4 +9,4 @@ class WritingGradeTaskDTO(BaseModel):
|
||||
exerciseId: str
|
||||
question: str
|
||||
answer: str
|
||||
attachment: Optional[str]
|
||||
attachment: Optional[str] = None
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user