From cc8d56aa8ebe799ec35ffb1065e06d76a03f8197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20=C3=87ayl=C4=B1?= <38523756+kaancayli@users.noreply.github.com> Date: Fri, 1 Mar 2024 08:24:38 +0100 Subject: [PATCH] Fix fields in dtos --- .gitignore | 1 - app/domain/data/course_dto.py | 2 +- app/domain/data/programming_exercise_dto.py | 4 ++-- app/domain/pipeline_execution_dto.py | 6 ++++-- app/domain/pipeline_execution_settings_dto.py | 2 +- .../tutor_chat_pipeline_execution_dto.py | 2 +- app/pipeline/chat/tutor_chat_pipeline.py | 6 +++--- app/web/routers/pipelines.py | 2 ++ app/web/status/status_update.py | 19 ++++++++++++++----- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 664a65d0..2dc53ca3 100644 --- a/.gitignore +++ b/.gitignore @@ -158,4 +158,3 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ -/app/pipeline_playground.py diff --git a/app/domain/data/course_dto.py b/app/domain/data/course_dto.py index e4266767..fb0877ec 100644 --- a/app/domain/data/course_dto.py +++ b/app/domain/data/course_dto.py @@ -4,4 +4,4 @@ class CourseDTO(BaseModel): id: int name: str - description: str + description: str | None = None diff --git a/app/domain/data/programming_exercise_dto.py b/app/domain/data/programming_exercise_dto.py index eac216da..195f3127 100644 --- a/app/domain/data/programming_exercise_dto.py +++ b/app/domain/data/programming_exercise_dto.py @@ -26,5 +26,5 @@ class ProgrammingExerciseDTO(BaseModel): solution_repository: Dict[str, str] = Field(alias="solutionRepository") test_repository: Dict[str, str] = Field(alias="testRepository") problem_statement: str = Field(alias="problemStatement") - start_date: datetime = Field(alias="startDate") - end_date: datetime = Field(alias="endDate") + start_date: datetime | None = Field(alias="startDate") + end_date: datetime | None = Field(alias="endDate") diff --git a/app/domain/pipeline_execution_dto.py b/app/domain/pipeline_execution_dto.py index 22a1e287..3f384b05 100644 --- a/app/domain/pipeline_execution_dto.py +++ b/app/domain/pipeline_execution_dto.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from pydantic import BaseModel, Field @@ -8,4 +8,6 @@ class PipelineExecutionDTO(BaseModel): settings: PipelineExecutionSettingsDTO - initial_stages: List[StageDTO] = Field(alias="initialStages") + initial_stages: Optional[List[StageDTO]] = Field( + default=None, alias="initialStages" + ) diff --git a/app/domain/pipeline_execution_settings_dto.py b/app/domain/pipeline_execution_settings_dto.py index 9b77c84f..5fc014ed 100644 --- a/app/domain/pipeline_execution_settings_dto.py +++ b/app/domain/pipeline_execution_settings_dto.py @@ -5,5 +5,5 @@ class PipelineExecutionSettingsDTO(BaseModel): authentication_token: str = Field(alias="authenticationToken") - allowed_models: List[str] = Field(alias="allowedModels") + allowed_model_identifiers: List[str] = Field(alias="allowedModelIdentifiers") 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 b17c9e8b..0ad23578 100644 --- a/app/domain/tutor_chat/tutor_chat_pipeline_execution_dto.py +++ b/app/domain/tutor_chat/tutor_chat_pipeline_execution_dto.py @@ -11,7 +11,7 @@ class TutorChatPipelineExecutionDTO(PipelineExecutionDTO): - latest_submission: SubmissionDTO = Field(alias="latestSubmission") + submission: SubmissionDTO exercise: ProgrammingExerciseDTO course: CourseDTO chat_history: List[MessageDTO] = Field(alias="chatHistory") diff --git a/app/pipeline/chat/tutor_chat_pipeline.py b/app/pipeline/chat/tutor_chat_pipeline.py index 7f5c8ddc..59da5857 100644 --- a/app/pipeline/chat/tutor_chat_pipeline.py +++ b/app/pipeline/chat/tutor_chat_pipeline.py @@ -94,12 +94,12 @@ def __call__(self, dto: TutorChatPipelineExecutionDTO, **kwargs): logger.debug("Running tutor chat pipeline...") logger.debug(f"DTO: {dto}") history: List[MessageDTO] = dto.chat_history[:-1] - build_logs = dto.latest_submission.build_log_entries + build_logs = dto.submission.build_log_entries query: IrisMessage = dto.chat_history[-1].convert_to_iris_message() problem_statement: str = dto.exercise.problem_statement exercise_title: str = dto.exercise.name message = query.text - file_map = dto.latest_submission.repository + file_map = dto.submission.repository programming_language = dto.exercise.programming_language.value.lower() if not message: raise ValueError("IrisMessage must not be empty") @@ -115,7 +115,7 @@ def __call__(self, dto: TutorChatPipelineExecutionDTO, **kwargs): } ) logger.debug(f"Response from tutor chat pipeline: {response}") - stages = dto.initial_stages + stages = dto.initial_stages or [] stages.append( StageDTO( name="Final Stage", diff --git a/app/web/routers/pipelines.py b/app/web/routers/pipelines.py index bcbf0e45..2686c7ba 100644 --- a/app/web/routers/pipelines.py +++ b/app/web/routers/pipelines.py @@ -1,4 +1,5 @@ import logging +import traceback from threading import Thread from fastapi import APIRouter, status, Response, Depends @@ -22,6 +23,7 @@ def run_tutor_chat_pipeline_worker(dto): pipeline(dto=dto) except Exception as e: logger.error(f"Error running tutor chat pipeline: {e}") + logger.error(traceback.format_exc()) @router.post( diff --git a/app/web/status/status_update.py b/app/web/status/status_update.py index 60cf8f45..4425ca93 100644 --- a/app/web/status/status_update.py +++ b/app/web/status/status_update.py @@ -4,6 +4,9 @@ from abc import ABC, abstractmethod from ...domain.tutor_chat.tutor_chat_status_update_dto import TutorChatStatusUpdateDTO +import logging + +logger = logging.getLogger(__name__) class StatusCallback(ABC): @@ -26,8 +29,14 @@ def __init__(self, run_id: str, base_url: str): super().__init__(url) def on_status_update(self, status: TutorChatStatusUpdateDTO): - requests.post( - self.url, - headers={"Content-Type": "application/json", "Authorization": self.run_id}, - json=status.dict(by_alias=True), - ) + try: + requests.post( + self.url, + headers={ + "Content-Type": "application/json", + "Authorization": self.run_id, + }, + json=status.dict(by_alias=True), + ).raise_for_status() + except requests.exceptions.RequestException as e: + logger.error(f"Error sending status update: {e}")