Skip to content

Commit

Permalink
Do not throw ValueError when calling callback.done()
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelOwenDyer committed Aug 9, 2024
1 parent 117a6e2 commit a202b2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
10 changes: 5 additions & 5 deletions app/pipeline/competency_extraction_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def __call__(
competency = competency[start:end]
try:
competency = self.output_parser.parse(competency)
logger.debug(f"Generated competency: {competency}")
generated_competencies.append(competency)
self.callback.done(final_result=generated_competencies)
except Exception as e:
logger.debug(f"Error generating competency: {e}")
self.callback.error(f"Error generating competency: {e}")
logger.debug(f"Error parsing competency: {e}")
continue
logger.debug(f"Generated competency: {competency}")
generated_competencies.append(competency)
self.callback.done(final_result=generated_competencies)
# Mark all remaining competencies as skipped
for i in range(len(generated_competencies), len(competencies)):
self.callback.skip(f"Skipping competency {i + 1}")
32 changes: 13 additions & 19 deletions app/web/status/status_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,19 @@ def done(
If there is a next stage, set the current
stage to the next stage.
"""
if self.stage.state == StageStateEnum.IN_PROGRESS:
self.stage.state = StageStateEnum.DONE
self.stage.message = message
self.status.result = final_result
if hasattr(self.status, "suggestions"):
self.status.suggestions = suggestions
next_stage = self.get_next_stage()
if next_stage is not None:
self.stage = next_stage
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(
"Invalid state transition to done. current state is ", self.stage.state
)
self.stage.state = StageStateEnum.DONE
self.stage.message = message
self.status.result = final_result
if hasattr(self.status, "suggestions"):
self.status.suggestions = suggestions
next_stage = self.get_next_stage()
if next_stage is not None:
self.stage = next_stage
if next_stage_message:
self.stage.message = next_stage_message
if start_next_stage:
self.stage.state = StageStateEnum.IN_PROGRESS
self.on_status_update()

def error(self, message: str, exception=None):
"""
Expand All @@ -131,7 +126,6 @@ def error(self, message: str, exception=None):
self.stage.state = StageStateEnum.ERROR
self.stage.message = message
self.status.result = None
self.stage.suggestions = None
# Set all subsequent stages to SKIPPED if an error occurs
rest_of_index = (
self.current_stage_index + 1
Expand Down

0 comments on commit a202b2c

Please sign in to comment.