Merged in release/async (pull request #37)
Remove unnecessary section id's from reading and listening to retrieve questions since context is already on the post dto Approved-by: Tiago Ribeiro
This commit is contained in:
@@ -52,13 +52,12 @@ async def generate_mp3(
|
|||||||
|
|
||||||
|
|
||||||
@listening_router.post(
|
@listening_router.post(
|
||||||
'/{section}',
|
'/',
|
||||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||||
)
|
)
|
||||||
@inject
|
@inject
|
||||||
async def generate_listening_exercise(
|
async def generate_listening_exercise(
|
||||||
dto: GenerateListeningExercises,
|
dto: GenerateListeningExercises,
|
||||||
section: int = Path(..., ge=1, le=4),
|
|
||||||
listening_controller: IListeningController = Depends(Provide[controller])
|
listening_controller: IListeningController = Depends(Provide[controller])
|
||||||
):
|
):
|
||||||
return await listening_controller.get_listening_question(section, dto)
|
return await listening_controller.get_listening_question(dto)
|
||||||
|
|||||||
@@ -40,13 +40,12 @@ async def generate_passage(
|
|||||||
return await reading_controller.generate_reading_passage(passage, topic, word_count)
|
return await reading_controller.generate_reading_passage(passage, topic, word_count)
|
||||||
|
|
||||||
@reading_router.post(
|
@reading_router.post(
|
||||||
'/{passage}',
|
'/',
|
||||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||||
)
|
)
|
||||||
@inject
|
@inject
|
||||||
async def generate_reading(
|
async def generate_reading(
|
||||||
dto: ReadingDTO,
|
dto: ReadingDTO,
|
||||||
passage: int = Path(..., ge=1, le=3),
|
|
||||||
reading_controller: IReadingController = Depends(Provide[controller])
|
reading_controller: IReadingController = Depends(Provide[controller])
|
||||||
):
|
):
|
||||||
return await reading_controller.generate_reading_exercises(passage, dto)
|
return await reading_controller.generate_reading_exercises(dto)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class IListeningController(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def get_listening_question(self, section: int, dto):
|
async def get_listening_question(self, dto):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@@ -15,6 +15,6 @@ class IReadingController(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def generate_reading_exercises(self, passage: int, dto):
|
async def generate_reading_exercises(self, dto):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ class ListeningController(IListeningController):
|
|||||||
async def generate_listening_dialog(self, section_id: int, topic: str, difficulty: str):
|
async def generate_listening_dialog(self, section_id: int, topic: str, difficulty: str):
|
||||||
return await self._service.generate_listening_dialog(section_id, topic, difficulty)
|
return await self._service.generate_listening_dialog(section_id, topic, difficulty)
|
||||||
|
|
||||||
async def get_listening_question(self, section: int, dto: GenerateListeningExercises):
|
async def get_listening_question(self, dto: GenerateListeningExercises):
|
||||||
return await self._service.get_listening_question(section, dto)
|
return await self._service.get_listening_question(dto)
|
||||||
|
|
||||||
async def generate_mp3(self, dto: Dialog):
|
async def generate_mp3(self, dto: Dialog):
|
||||||
mp3 = await self._service.generate_mp3(dto)
|
mp3 = await self._service.generate_mp3(dto)
|
||||||
|
|||||||
@@ -24,5 +24,5 @@ class ReadingController(IReadingController):
|
|||||||
async def generate_reading_passage(self, passage: int, topic: Optional[str], word_count: Optional[int]):
|
async def generate_reading_passage(self, passage: int, topic: Optional[str], word_count: Optional[int]):
|
||||||
return await self._service.generate_reading_passage(passage, topic, word_count)
|
return await self._service.generate_reading_passage(passage, topic, word_count)
|
||||||
|
|
||||||
async def generate_reading_exercises(self, passage: int, dto: ReadingDTO):
|
async def generate_reading_exercises(self, dto: ReadingDTO):
|
||||||
return await self._service.generate_reading_exercises(dto)
|
return await self._service.generate_reading_exercises(dto)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class IListeningService(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def get_listening_question(self, section: int, dto):
|
async def get_listening_question(self, dto):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ class ListeningService(IListeningService):
|
|||||||
async def generate_listening_dialog(self, section: int, topic: str, difficulty: str):
|
async def generate_listening_dialog(self, section: int, topic: str, difficulty: str):
|
||||||
return await self._sections[f'section_{section}']["generate_dialogue"](section, topic)
|
return await self._sections[f'section_{section}']["generate_dialogue"](section, topic)
|
||||||
|
|
||||||
|
# TODO: When mp3 editor
|
||||||
async def get_dialog_from_audio(self, upload: UploadFile):
|
async def get_dialog_from_audio(self, upload: UploadFile):
|
||||||
ext, path_id = await FileHelper.save_upload(upload)
|
ext, path_id = await FileHelper.save_upload(upload)
|
||||||
dialog = await self._stt.speech_to_text(f'./tmp/{path_id}/upload.{ext}')
|
dialog = await self._stt.speech_to_text(f'./tmp/{path_id}/upload.{ext}')
|
||||||
@@ -100,8 +101,7 @@ class ListeningService(IListeningService):
|
|||||||
async def generate_mp3(self, dto: Dialog) -> bytes:
|
async def generate_mp3(self, dto: Dialog) -> bytes:
|
||||||
return await self._tts.text_to_speech(dto)
|
return await self._tts.text_to_speech(dto)
|
||||||
|
|
||||||
async def get_listening_question(self, section: int, dto: GenerateListeningExercises):
|
async def get_listening_question(self, dto: GenerateListeningExercises):
|
||||||
dialog_type = self._sections[f'section_{section}']["type"]
|
|
||||||
start_id = 1
|
start_id = 1
|
||||||
exercise_tasks = []
|
exercise_tasks = []
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ class ListeningService(IListeningService):
|
|||||||
exercise_tasks.append(
|
exercise_tasks.append(
|
||||||
self._generate_exercise(
|
self._generate_exercise(
|
||||||
req_exercise,
|
req_exercise,
|
||||||
dialog_type,
|
"dialog or monologue",
|
||||||
dto.text,
|
dto.text,
|
||||||
start_id,
|
start_id,
|
||||||
dto.difficulty
|
dto.difficulty
|
||||||
|
|||||||
Reference in New Issue
Block a user