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

@@ -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