diff --git a/app/pipeline/chat/course_chat_pipeline.py b/app/pipeline/chat/course_chat_pipeline.py index 1ec558ef..10e6c14f 100644 --- a/app/pipeline/chat/course_chat_pipeline.py +++ b/app/pipeline/chat/course_chat_pipeline.py @@ -111,7 +111,6 @@ def __call__(self, dto: CourseChatPipelineExecutionDTO, **kwargs): :param kwargs: The keyword arguments """ - used_tools = [] # Define tools @tool @@ -127,7 +126,7 @@ def get_exercise_list() -> list[dict]: You see when the student submitted the exercise and what score they got. A 100% score means the student solved the exercise correctly and completed it. """ - used_tools.append("get_exercise_list") + self.callback.in_progress("Reading exercise list ...") current_time = datetime.now(tz=pytz.UTC) exercises = [] for exercise in dto.course.exercises: @@ -144,7 +143,7 @@ def get_course_details() -> dict: Get the following course details: course name, course description, programming language, course start date, and course end date. """ - used_tools.append("get_course_details") + self.callback.in_progress("Reading course details ...") return { "course_name": ( dto.course.name if dto.course else "No course provided" @@ -188,7 +187,7 @@ def get_student_exercise_metrics( submissions of all students in the exercise. - latest_submission_of_student: The relative time of the latest submission of the student. """ - print(dto.metrics) + self.callback.in_progress("Checking your statistics ...") if not dto.metrics or not dto.metrics.exercise_metrics: return "No data available!! Do not requery." metrics = dto.metrics.exercise_metrics @@ -229,7 +228,7 @@ def get_competency_list() -> list: The object describing it also indicates the system-computed confidence at the time when the student added their JoL assessment. """ - used_tools.append("get_competency_list") + self.callback.in_progress("Reading competency list ...") if not dto.metrics or not dto.metrics.competency_metrics: return dto.course.competencies competency_metrics = dto.metrics.competency_metrics @@ -282,7 +281,6 @@ def get_competency_list() -> list: datetime.now(tz=pytz.UTC).strftime("%Y-%m-%d %H:%M:%S"), ) - params = {} if self.variant == "jol": comp = next( ( @@ -366,20 +364,11 @@ def get_competency_list() -> list: self.callback.in_progress() for step in agent_executor.iter(params): print("STEP:", step) - if output := step.get("intermediate_step"): - action, value = output[0] - if action.tool == "get_student_metrics": - self.callback.in_progress("Checking your statistics ...") - elif action.tool == "get_exercise_list": - self.callback.in_progress("Reading exercise list ...") - elif action.tool == "get_course_details": - self.callback.in_progress("Reading course details ...") - elif action.tool == "get_competency_list": - self.callback.in_progress("Reading competency list ...") - elif step["output"]: + if step.get('output', None): out = step["output"] - print(out) + self.callback.done("Response created", final_result=out) + suggestions = None try: if out: @@ -388,14 +377,14 @@ def get_competency_list() -> list: last_message=out, ) suggestions = self.suggestion_pipeline(suggestion_dto) + self.callback.done(final_result=None, suggestions=suggestions) except Exception as e: logger.error( "An error occurred while running the course chat interaction suggestion pipeline", exc_info=e, ) traceback.print_exc() - - self.callback.done(None, final_result=out, suggestions=suggestions) + self.callback.error("Generating interaction suggestions failed.") except Exception as e: logger.error( "An error occurred while running the course chat pipeline", exc_info=e diff --git a/app/web/status/status_update.py b/app/web/status/status_update.py index a2f0f934..fd7397dc 100644 --- a/app/web/status/status_update.py +++ b/app/web/status/status_update.py @@ -90,6 +90,8 @@ def done( message: Optional[str] = None, final_result: Optional[str] = None, suggestions: Optional[List[str]] = None, + next_stage_message: Optional[str] = None, + start_next_stage: bool = True ): """ Transition the current stage to DONE and update the status. @@ -99,13 +101,15 @@ def done( if self.stage.state == StageStateEnum.IN_PROGRESS: self.stage.state = StageStateEnum.DONE self.stage.message = message + self.status.result = final_result + self.status.suggestions = suggestions next_stage = self.get_next_stage() if next_stage is not None: self.stage = next_stage - else: - self.status.result = final_result - if (suggestions is not None) and (len(suggestions) > 0): - self.status.suggestions = suggestions + if next_stage_message: + self.stage.message = next_stage_message + if start_next_stage: + self.stage.state = StageStateEnum.IN_PROGRESS self.on_status_update() else: raise ValueError( @@ -160,6 +164,11 @@ def __init__( state=StageStateEnum.NOT_STARTED, name="Thinking", ), + StageDTO( + weight=10, + state=StageStateEnum.NOT_STARTED, + name="Creating suggestions" + ) ] status = CourseChatStatusUpdateDTO(stages=stages) stage = stages[current_stage_index]