Brushed up the backend, added writing task 1 academic prompt gen and grading ENCOA-274

This commit is contained in:
Carlos-Mesquita
2024-12-10 22:24:40 +00:00
parent 68cab80851
commit 6982068864
167 changed files with 1411 additions and 1229 deletions

View File

@@ -0,0 +1,7 @@
from .handle_exception import handle_exception
from .logger import suppress_loggers
__all__ = [
"handle_exception",
"suppress_loggers"
]

View File

@@ -0,0 +1,15 @@
import functools
from typing import Callable, Any
from fastapi import Response
def handle_exception(status_code: int = 500):
def decorator(func: Callable) -> Callable:
@functools.wraps(func)
async def wrapper(*args: Any, **kwargs: Any) -> Any:
try:
return await func(*args, **kwargs)
except Exception as e:
return Response(content=str(e), status_code=status_code)
return wrapper
return decorator

View File

@@ -0,0 +1,10 @@
def _b64_vision_images(path: str):
for filename in os.listdir(path):
if filename.startswith("cv-") and filename.endswith(".png"):
cv_dict.append({
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{_encode_image(os.path.join(path, filename))}"
}
})
return cv_dict

20
ielts_be/utils/logger.py Normal file
View File

@@ -0,0 +1,20 @@
import logging
from functools import wraps
def suppress_loggers():
def decorator(f):
@wraps(f)
def wrapped(*args, **kwargs):
root_logger = logging.getLogger()
original_level = root_logger.level
root_logger.setLevel(logging.ERROR)
try:
return f(*args, **kwargs)
finally:
root_logger.setLevel(original_level)
return wrapped
return decorator