Skip to content

Commit

Permalink
send suggestions with status
Browse files Browse the repository at this point in the history
  • Loading branch information
bassner committed Jun 22, 2024
1 parent 41f3a66 commit 8b432b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
29 changes: 9 additions & 20 deletions app/pipeline/chat/course_chat_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def __call__(self, dto: CourseChatPipelineExecutionDTO, **kwargs):
:param kwargs: The keyword arguments
"""

used_tools = []

# Define tools
@tool
Expand All @@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
(
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
17 changes: 13 additions & 4 deletions app/web/status/status_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 8b432b2

Please sign in to comment.