Leftover from merge, updated readme

This commit is contained in:
Carlos-Mesquita
2024-11-06 02:07:46 +00:00
parent f02a34fda2
commit e51cd891d2
8 changed files with 52 additions and 1316 deletions

View File

@@ -1,49 +1,26 @@
Latest refactor from develop's branch commit 5d5cd21 2024-08-28
# Endpoints
| Method | ielts-be | This one |
|--------|--------------------------------------|---------------------------------------------|
| GET | /healthcheck | /api/healthcheck |
| GET | /listening_section_1 | /api/listening/section/1 |
| GET | /listening_section_2 | /api/listening/section/2 |
| GET | /listening_section_3 | /api/listening/section/3 |
| GET | /listening_section_4 | /api/listening/section/4 |
| POST | /listening | /api/listening |
| POST | /writing_task1 | /api/grade/writing/1 |
| POST | /writing_task2 | /api/grade/writing/2 |
| GET | /writing_task1_general | /api/writing/1 |
| GET | /writing_task2_general | /api/writing/2 |
| POST | /speaking_task_1 | /api/grade/speaking/1 |
| POST | /speaking_task_2 | /api/grade/speaking/2 |
| POST | /speaking_task_3 | /api/grade/speaking/3 |
| GET | /speaking_task_1 | /api/speaking/1 |
| GET | /speaking_task_2 | /api/speaking/2 |
| GET | /speaking_task_3 | /api/speaking/3 |
| POST | /speaking | /api/speaking |
| POST | /speaking/generate_speaking_video | /api/speaking/generate_speaking_video |
| POST | /speaking/generate_interactive_video | /api/speaking/generate_interactive_video |
| GET | /reading_passage_1 | /api/reading/passage/1 |
| GET | /reading_passage_2 | /api/reading/passage/2 |
| GET | /reading_passage_3 | /api/reading/passage/3 |
| GET | /level | /api/level |
| GET | /level_utas | /api/level/utas |
| POST | /fetch_tips | /api/training/tips |
| POST | /grading_summary | /api/grade/summary |
| POST | /grade_short_answers | /api/grade/short_answers |
| POST | /upload_level | /api/level/upload |
| POST | /training_content | /api/training/ |
| POST | /custom_level | /api/level/custom |
# Run the app # Run the app
This is for Windows, creating venv and activating it may differ based on your OS 1. pip install poetry
2. poetry install
3. python app.py
1. python -m venv env # Modules
2. env\Scripts\activate
3. pip install poetry
4. poetry install
5. python app.py
- api -> endpoints
- configs -> app configs and constants
- controllers -> meant for handling exceptions, transforming data or orchestrate complex use cases with several services, for now mostly just calls services directly
- dtos -> pydantic models used for receiving data and for validation
- exceptions -> if custom exceptions are needed to throw in services so they can be handled in the controllers to construct some specific http response
- helpers -> a bunch of lightweight functions grouped by some kind of logic
- mappers -> to map complex data
- middlewares -> classes that are run before executing the endpoint code
- repositories -> interfaces with data stores
- services -> all the business logic goes here
- utils -> loose functions used on one-off occasions
# Dependency injection
If you want to add new controllers/services/repositories you will have to change
app/configs/dependency_injection.py
Also make sure you have @inject on your endpoint when calling these.

File diff suppressed because it is too large Load Diff

View File

@@ -2,12 +2,10 @@ from .file import FileHelper
from .text import TextHelper from .text import TextHelper
from .token_counter import count_tokens from .token_counter import count_tokens
from .exercises import ExercisesHelper from .exercises import ExercisesHelper
from .logger import LoggerHelper
__all__ = [ __all__ = [
"FileHelper", "FileHelper",
"TextHelper", "TextHelper",
"count_tokens", "count_tokens",
"ExercisesHelper", "ExercisesHelper",
"LoggerHelper"
] ]

View File

@@ -1,23 +0,0 @@
import logging
from functools import wraps
class LoggerHelper:
@staticmethod
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

View File

@@ -8,11 +8,12 @@ import pdfplumber
from fastapi import UploadFile from fastapi import UploadFile
from app.services.abc import ILLMService from app.services.abc import ILLMService
from app.helpers import LoggerHelper, FileHelper from app.helpers import FileHelper
from app.mappers import LevelMapper from app.mappers import LevelMapper
from app.dtos.exams.level import Exam from app.dtos.exams.level import Exam
from app.dtos.sheet import Sheet from app.dtos.sheet import Sheet
from app.utils import suppress_loggers
class UploadLevelModule: class UploadLevelModule:
@@ -42,7 +43,7 @@ class UploadLevelModule:
return None return None
@staticmethod @staticmethod
@LoggerHelper.suppress_loggers() @suppress_loggers()
def _check_pdf_for_images(pdf_path: str) -> bool: def _check_pdf_for_images(pdf_path: str) -> bool:
with pdfplumber.open(pdf_path) as pdf: with pdfplumber.open(pdf_path) as pdf:
for page in pdf.pages: for page in pdf.pages:

View File

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

20
app/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

View File

@@ -12,11 +12,11 @@ python-dotenv = "^1.0.1"
aioboto3 = "^13.1.1" aioboto3 = "^13.1.1"
httpx = "^0.27.0" httpx = "^0.27.0"
fastapi = "^0.111.1" fastapi = "^0.111.1"
nltk = "^3.8.1" nltk = "3.9.1"
firebase-admin = "^6.5.0" firebase-admin = "^6.5.0"
wonderwords = "^2.2.0" wonderwords = "^2.2.0"
dependency-injector = "^4.41.0" dependency-injector = "^4.41.0"
openai = "^1.37.0" openai = "1.50.2"
python-multipart = "0.0.9" python-multipart = "0.0.9"
faiss-cpu = "1.8.0.post1" faiss-cpu = "1.8.0.post1"
pypandoc = "1.13" pypandoc = "1.13"
@@ -24,10 +24,11 @@ pdfplumber = "0.11.3"
numpy = "1.26.4" numpy = "1.26.4"
pillow = "10.4.0" pillow = "10.4.0"
sentence-transformers = "3.0.1" sentence-transformers = "3.0.1"
openai-whisper = "20231117" openai-whisper = "20240930"
motor = "3.6.0" motor = "3.6.0"
shortuuid = "1.0.13" shortuuid = "1.0.13"
pandas = "2.2.3" pandas = "2.2.3"
tiktoken = "0.7.0"
[build-system] [build-system]