Async release

This commit is contained in:
Carlos Mesquita
2024-07-23 08:40:35 +01:00
parent a4caecdb4f
commit 3cf9fa5cba
116 changed files with 5609 additions and 30630 deletions

View File

@@ -0,0 +1,19 @@
from .level import ILevelService
from .listening import IListeningService
from .writing import IWritingService
from .speaking import ISpeakingService
from .reading import IReadingService
from .grade import IGradeService
from .training import ITrainingService
from .third_parties import *
__all__ = [
"ILevelService",
"IListeningService",
"IWritingService",
"ISpeakingService",
"IReadingService",
"IGradeService",
"ITrainingService"
]
__all__.extend(third_parties.__all__)

23
app/services/abc/grade.py Normal file
View File

@@ -0,0 +1,23 @@
from abc import ABC, abstractmethod
from typing import Dict, List
class IGradeService(ABC):
@abstractmethod
async def calculate_grading_summary(self, extracted_sections: List):
pass
@abstractmethod
async def _calculate_section_grade_summary(self, section):
pass
@staticmethod
@abstractmethod
def _parse_openai_response(response):
pass
@staticmethod
@abstractmethod
def _parse_bullet_points(bullet_points_str, grade):
pass

24
app/services/abc/level.py Normal file
View File

@@ -0,0 +1,24 @@
from abc import ABC, abstractmethod
class ILevelService(ABC):
@abstractmethod
async def get_level_exam(self):
pass
@abstractmethod
async def get_level_utas(self):
pass
@abstractmethod
async def _gen_multiple_choice_level(self, quantity: int, start_id=1):
pass
@abstractmethod
async def _replace_exercise_if_exists(self, all_exams, current_exercise, current_exam, seen_keys):
pass
@abstractmethod
async def _generate_single_mc_level_question(self):
pass

View File

@@ -0,0 +1,68 @@
from abc import ABC, abstractmethod
from queue import Queue
from typing import Dict
class IListeningService(ABC):
@abstractmethod
async def generate_listening_question(self, section: int, topic: str) -> Dict:
pass
@abstractmethod
async def generate_listening_exercises(
self, section: int, dialog: str,
req_exercises: list[str], exercises_queue: Queue,
start_id: int, difficulty: str
):
pass
@abstractmethod
async def save_listening(self, parts, min_timer, difficulty):
pass
# ==================================================================================================================
# Helpers
# ==================================================================================================================
@abstractmethod
async def _generate_listening_conversation(self, section: int, topic: str) -> Dict:
pass
@abstractmethod
async def _generate_listening_monologue(self, section: int, topic: str) -> Dict:
pass
@abstractmethod
def _get_conversation_voices(self, response: Dict, unique_voices_across_segments: bool):
pass
@staticmethod
@abstractmethod
def _get_random_voice(gender: str):
pass
@abstractmethod
async def _gen_multiple_choice_exercise_listening(
self, dialog_type: str, text: str, quantity: int, start_id, difficulty
):
pass
@abstractmethod
async def _gen_write_blanks_questions_exercise_listening(
self, dialog_type: str, text: str, quantity: int, start_id, difficulty
):
pass
@abstractmethod
async def _gen_write_blanks_notes_exercise_listening(
self, dialog_type: str, text: str, quantity: int, start_id, difficulty
):
pass
@abstractmethod
async def _gen_write_blanks_form_exercise_listening(
self, dialog_type: str, text: str, quantity: int, start_id, difficulty
):
pass

View File

@@ -0,0 +1,49 @@
from abc import ABC, abstractmethod
from queue import Queue
from typing import List
from app.configs.constants import QuestionType
class IReadingService(ABC):
@abstractmethod
async def gen_reading_passage(
self,
passage_id: int,
topic: str,
req_exercises: List[str],
number_of_exercises_q: Queue,
difficulty: str
):
pass
# ==================================================================================================================
# Helpers
# ==================================================================================================================
@abstractmethod
async def generate_reading_passage(self, q_type: QuestionType, topic: str):
pass
@abstractmethod
async def _generate_reading_exercises(
self, passage: str, req_exercises: list, number_of_exercises_q, start_id, difficulty
):
pass
@abstractmethod
async def _gen_summary_fill_blanks_exercise(self, text: str, quantity: int, start_id, difficulty):
pass
@abstractmethod
async def _gen_true_false_not_given_exercise(self, text: str, quantity: int, start_id, difficulty):
pass
@abstractmethod
async def _gen_write_blanks_exercise(self, text: str, quantity: int, start_id, difficulty):
pass
@abstractmethod
async def _gen_paragraph_match_exercise(self, text: str, quantity: int, start_id):
pass

View File

@@ -0,0 +1,57 @@
from abc import ABC, abstractmethod
from typing import List, Dict
class ISpeakingService(ABC):
@abstractmethod
async def get_speaking_task(self, task_id: int, topic: str, difficulty: str):
pass
@abstractmethod
async def grade_speaking_task_1_and_2(
self, task: int, question: str, answer_firebase_path: str, sound_file_name: str
):
pass
@abstractmethod
async def grade_speaking_task_3(self, answers: Dict, task: int = 3):
pass
@abstractmethod
async def create_videos_and_save_to_db(self, exercises: List[Dict], template: Dict, req_id: str):
pass
@abstractmethod
async def generate_speaking_video(self, original_question: str, topic: str, avatar: str, prompts: List[str]):
pass
@abstractmethod
async def generate_interactive_video(self, questions: List[str], avatar: str, topic: str):
pass
# ==================================================================================================================
# Helpers
# ==================================================================================================================
@staticmethod
@abstractmethod
def _zero_rating(comment: str):
pass
@staticmethod
@abstractmethod
def _calculate_overall(response: Dict):
pass
@abstractmethod
async def _get_speaking_corrections(self, text):
pass
@abstractmethod
async def _create_video_per_part(self, exercises: List[Dict], template: Dict, part: int):
pass
@abstractmethod
async def _create_video(self, question: str, avatar: str, error_message: str):
pass

View File

@@ -0,0 +1,13 @@
from .stt import ISpeechToTextService
from .tts import ITextToSpeechService
from .llm import ILLMService
from .vid_gen import IVideoGeneratorService
from .ai_detector import IAIDetectorService
__all__ = [
"ISpeechToTextService",
"ITextToSpeechService",
"ILLMService",
"IVideoGeneratorService",
"IAIDetectorService"
]

View File

@@ -0,0 +1,13 @@
from abc import ABC, abstractmethod
from typing import Dict, Optional
class IAIDetectorService(ABC):
@abstractmethod
async def run_detection(self, text: str):
pass
@abstractmethod
def _parse_detection(self, response: Dict) -> Optional[Dict]:
pass

View File

@@ -0,0 +1,21 @@
from abc import ABC, abstractmethod
from typing import List, Optional
class ILLMService(ABC):
@abstractmethod
async def prediction(
self,
model: str,
messages: List,
fields_to_check: Optional[List[str]],
temperature: float,
check_blacklisted: bool = True,
token_count: int = -1
):
pass
@abstractmethod
async def prediction_override(self, **kwargs):
pass

View File

@@ -0,0 +1,8 @@
from abc import ABC, abstractmethod
class ISpeechToTextService(ABC):
@abstractmethod
async def speech_to_text(self, file_path):
pass

View File

@@ -0,0 +1,22 @@
from abc import ABC, abstractmethod
from typing import Union
class ITextToSpeechService(ABC):
@abstractmethod
async def synthesize_speech(self, text: str, voice: str, engine: str, output_format: str):
pass
@abstractmethod
async def text_to_speech(self, text: Union[list[str], str], file_name: str):
pass
@abstractmethod
async def _conversation_to_speech(self, conversation: list):
pass
@abstractmethod
async def _text_to_speech(self, text: str):
pass

View File

@@ -0,0 +1,10 @@
from abc import ABC, abstractmethod
from app.configs.constants import AvatarEnum
class IVideoGeneratorService(ABC):
@abstractmethod
async def create_video(self, text: str, avatar: str):
pass

View File

@@ -0,0 +1,13 @@
from abc import ABC, abstractmethod
class ITrainingService(ABC):
@abstractmethod
async def fetch_tips(self, context: str, question: str, answer: str, correct_answer: str):
pass
@staticmethod
@abstractmethod
def _get_question_tips(question: str, answer: str, correct_answer: str, context: str = None):
pass

View File

@@ -0,0 +1,32 @@
from abc import ABC, abstractmethod
from typing import Dict
class IWritingService(ABC):
@abstractmethod
async def get_writing_task_general_question(self, task: int, topic: str, difficulty: str):
pass
@abstractmethod
async def grade_writing_task(self, task: int, question: str, answer: str):
pass
# ==================================================================================================================
# Helpers
# ==================================================================================================================
@staticmethod
@abstractmethod
def _get_writing_prompt(task: int, topic: str, difficulty: str):
pass
@staticmethod
@abstractmethod
async def _get_fixed_text(self, text):
pass
@staticmethod
@abstractmethod
def _zero_rating(comment: str):
pass