diff --git a/app/common/singleton_abstract.py b/app/common/singleton_abstract.py deleted file mode 100644 index ef3b65a4..00000000 --- a/app/common/singleton_abstract.py +++ /dev/null @@ -1,18 +0,0 @@ -from abc import ABCMeta - - -class SingletonABCMeta(ABCMeta): - _instances = {} - - def __call__(cls, *args, **kwargs): - if cls not in cls._instances: - # Ensure the class implements __call__ if it's not the ABC itself - # This checks if '__call__' is implemented directly in the subclass - if "__call__" in cls.__dict__: - instance = super().__call__(*args, **kwargs) - cls._instances[cls] = instance - else: - raise NotImplementedError( - f"{cls.__name__} must implement the __call__ method." - ) - return cls._instances[cls] diff --git a/app/domain/pipeline_execution_dto.py b/app/domain/pipeline_execution_dto.py index 8482e7d9..282b3a97 100644 --- a/app/domain/pipeline_execution_dto.py +++ b/app/domain/pipeline_execution_dto.py @@ -1,7 +1,11 @@ -from pydantic import BaseModel +from typing import List + +from pydantic import BaseModel, Field from domain.pipeline_execution_settings_dto import PipelineExecutionSettingsDTO +from domain.status.stage_dto import StageDTO class PipelineExecutionDTO(BaseModel): settings: PipelineExecutionSettingsDTO + initial_stages: List[StageDTO] = Field(alias="initialStages") diff --git a/app/domain/pipeline_execution_settings_dto.py b/app/domain/pipeline_execution_settings_dto.py index a7f69cec..9b77c84f 100644 --- a/app/domain/pipeline_execution_settings_dto.py +++ b/app/domain/pipeline_execution_settings_dto.py @@ -6,3 +6,4 @@ class PipelineExecutionSettingsDTO(BaseModel): authentication_token: str = Field(alias="authenticationToken") allowed_models: List[str] = Field(alias="allowedModels") + artemis_base_url: str = Field(alias="artemisBaseUrl") diff --git a/app/domain/tutor_chat/tutor_chat_pipeline_execution_dto.py b/app/domain/tutor_chat/tutor_chat_pipeline_execution_dto.py index cfa8f465..e52d10aa 100644 --- a/app/domain/tutor_chat/tutor_chat_pipeline_execution_dto.py +++ b/app/domain/tutor_chat/tutor_chat_pipeline_execution_dto.py @@ -1,7 +1,8 @@ from typing import List -from pydantic import BaseModel, Field +from pydantic import Field +from domain import PipelineExecutionDTO from domain.data.course_dto import CourseDTO from domain.data.message_dto import MessageDTO from domain.data.programming_exercise_dto import ProgrammingExerciseDTO @@ -9,7 +10,7 @@ from domain.data.submission_dto import SubmissionDTO -class TutorChatPipelineExecutionDTO(BaseModel): +class TutorChatPipelineExecutionDTO(PipelineExecutionDTO): latest_submission: SubmissionDTO = Field(alias="latestSubmission") exercise: ProgrammingExerciseDTO course: CourseDTO diff --git a/app/pipeline/pipeline.py b/app/pipeline/pipeline.py index e330f51a..a7cc4be6 100644 --- a/app/pipeline/pipeline.py +++ b/app/pipeline/pipeline.py @@ -1,7 +1,7 @@ -from app.common.singleton_abstract import SingletonABCMeta +from abc import ABCMeta -class Pipeline(metaclass=SingletonABCMeta): +class Pipeline(metaclass=ABCMeta): """Abstract class for all pipelines""" implementation_id: str diff --git a/app/web/routers/pipelines.py b/app/web/routers/pipelines.py index 15246c7b..3dd70188 100644 --- a/app/web/routers/pipelines.py +++ b/app/web/routers/pipelines.py @@ -5,6 +5,7 @@ TutorChatPipelineExecutionDTO, ) from app.pipeline.chat.tutor_chat_pipeline import TutorChatPipeline +from web.status.status_update import TutorChatStatusCallback router = APIRouter(prefix="/api/v1/pipelines", tags=["pipelines"]) logger = logging.getLogger(__name__) @@ -12,8 +13,9 @@ @router.post("/tutor-chat/{variant}/run", status_code=status.HTTP_202_ACCEPTED) def run_pipeline(variant: str, dto: TutorChatPipelineExecutionDTO): - pipeline = TutorChatPipeline() - pipeline(wrapper=dto, callback=None) + callback = TutorChatStatusCallback(run_id=dto.settings.authentication_token) + pipeline = TutorChatPipeline(callback=callback) + pipeline(dto=dto) @router.get("/{feature}") diff --git a/app/web/status/status_update.py b/app/web/status/status_update.py index 652cc017..dd32fb5a 100644 --- a/app/web/status/status_update.py +++ b/app/web/status/status_update.py @@ -20,9 +20,12 @@ def on_status_update(self, status: Any): class TutorChatStatusCallback(StatusCallback): def __init__(self, run_id: str): url = f"/api/v1/public/pyris/tutorchat/runs/{run_id}/status" + self.run_id = run_id super().__init__(url) def on_status_update(self, status: TutorChatStatusUpdateDTO): requests.post( - self.url, headers={"Content-Type": "application/json"}, json=status.json() + self.url, + headers={"Content-Type": "application/json", "Authorization": self.run_id}, + json=status.json(), )