-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ingestion status callback update (#142)
- Loading branch information
Showing
11 changed files
with
192 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import List, Optional | ||
|
||
from pydantic import Field | ||
|
||
from app.domain import PipelineExecutionDTO, PipelineExecutionSettingsDTO | ||
from app.domain.data.lecture_unit_dto import LectureUnitDTO | ||
from app.domain.status.stage_dto import StageDTO | ||
|
||
|
||
class LecturesDeletionExecutionDto(PipelineExecutionDTO): | ||
lecture_units: List[LectureUnitDTO] = Field(..., alias="pyrisLectureUnits") | ||
settings: Optional[PipelineExecutionSettingsDTO] | ||
initial_stages: Optional[List[StageDTO]] = Field( | ||
default=None, alias="initialStages" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
from typing import List | ||
from typing import List, Optional | ||
|
||
from pydantic import Field | ||
|
||
from app.domain import PipelineExecutionDTO | ||
from app.domain import PipelineExecutionDTO, PipelineExecutionSettingsDTO | ||
from app.domain.data.lecture_unit_dto import LectureUnitDTO | ||
from app.domain.status.stage_dto import StageDTO | ||
|
||
|
||
class IngestionPipelineExecutionDto(PipelineExecutionDTO): | ||
lecture_units: List[LectureUnitDTO] = Field( | ||
..., alias="pyrisLectureUnitWebhookDTOS" | ||
lecture_unit: LectureUnitDTO = Field(..., alias="pyrisLectureUnit") | ||
settings: Optional[PipelineExecutionSettingsDTO] | ||
initial_stages: Optional[List[StageDTO]] = Field( | ||
default=None, alias="initialStages" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
|
||
class IngestionStatusUpdateDTO(StatusUpdateDTO): | ||
result: Optional[str] = None | ||
id: Optional[int] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import json | ||
from urllib.parse import unquote | ||
|
||
from fastapi import APIRouter, status, Response, Depends | ||
from fastapi.params import Query | ||
from weaviate.collections.classes.filters import Filter | ||
|
||
from app.dependencies import TokenValidator | ||
from ...vector_database.database import VectorDatabase | ||
from ...vector_database.lecture_schema import LectureSchema | ||
from enum import Enum | ||
|
||
router = APIRouter(prefix="/api/v1", tags=["ingestion_status"]) | ||
|
||
|
||
class IngestionState(str, Enum): | ||
DONE = "DONE" | ||
NOT_STARTED = "NOT_STARTED" | ||
|
||
|
||
@router.get( | ||
"/courses/{course_id}/lectures/{lecture_id}/lectureUnits/{lecture_unit_id}/ingestion-state", | ||
dependencies=[Depends(TokenValidator())], | ||
) | ||
def get_lecture_unit_ingestion_state( | ||
course_id: int, lecture_id: int, lecture_unit_id: int, base_url: str = Query(...) | ||
): | ||
""" | ||
:param course_id: | ||
:param lecture_id: | ||
:param lecture_unit_id: | ||
:param base_url: | ||
:return: | ||
""" | ||
db = VectorDatabase() | ||
decoded_base_url = unquote(base_url) | ||
result = db.lectures.query.fetch_objects( | ||
filters=( | ||
Filter.by_property(LectureSchema.BASE_URL.value).equal(decoded_base_url) | ||
& Filter.by_property(LectureSchema.COURSE_ID.value).equal(course_id) | ||
& Filter.by_property(LectureSchema.LECTURE_ID.value).equal(lecture_id) | ||
& Filter.by_property(LectureSchema.LECTURE_UNIT_ID.value).equal( | ||
lecture_unit_id | ||
) | ||
), | ||
limit=1, | ||
return_properties=[LectureSchema.LECTURE_UNIT_NAME.value], | ||
) | ||
|
||
if len(result.objects) > 0: | ||
return Response( | ||
status_code=status.HTTP_200_OK, | ||
content=json.dumps({"state": IngestionState.DONE.value}), | ||
media_type="application/json", | ||
) | ||
else: | ||
return Response( | ||
status_code=status.HTTP_200_OK, | ||
content=json.dumps({"state": IngestionState.NOT_STARTED.value}), | ||
media_type="application/json", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import List | ||
|
||
from .status_update import StatusCallback | ||
from ...domain.ingestion.ingestion_status_update_dto import IngestionStatusUpdateDTO | ||
from ...domain.status.stage_state_dto import StageStateEnum | ||
from ...domain.status.stage_dto import StageDTO | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class LecturesDeletionStatusCallback(StatusCallback): | ||
""" | ||
Callback class for updating the status of a Tutor Chat pipeline run. | ||
""" | ||
|
||
def __init__( | ||
self, run_id: str, base_url: str, initial_stages: List[StageDTO] = None | ||
): | ||
url = f"{base_url}/api/public/pyris/webhooks/ingestion/runs/{run_id}/status" | ||
|
||
current_stage_index = len(initial_stages) if initial_stages else 0 | ||
stages = initial_stages or [] | ||
stages += [ | ||
StageDTO( | ||
weight=100, state=StageStateEnum.NOT_STARTED, name="Slides removal" | ||
), | ||
] | ||
status = IngestionStatusUpdateDTO(stages=stages) | ||
stage = stages[current_stage_index] | ||
super().__init__(url, run_id, status, stage, current_stage_index) |
Empty file.