From 5175ca2d37e819a0ecafe21f79375546a49b5728 Mon Sep 17 00:00:00 2001 From: Maximilian Kimmich <maximilian.kimmich@ims.uni-stuttgart.de> Date: Fri, 11 Oct 2024 19:31:42 +0200 Subject: [PATCH] Fix crash which occurred when no prompt could be extracted from evolution --- evoprompt/evolution/evolution.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/evoprompt/evolution/evolution.py b/evoprompt/evolution/evolution.py index b5d71f9..7eae7c2 100644 --- a/evoprompt/evolution/evolution.py +++ b/evoprompt/evolution/evolution.py @@ -426,6 +426,13 @@ class DifferentialEvolution(EvolutionAlgorithm): if evolved_prompt is None: logger.info(f"Could not extract prompt from response: {evolved_prompt}") + + # no prompt was returned (e.g., evolved prompt could not be extracted), therefore, for DE, we use the basic prompt + return ( + prompts_current_evolution[current_iteration].content, + [judgement], + usage, + ) else: logger.info( "DE-evolved prompts '%s', '%s' and '%s' with basic prompt '%s' into '%s'", @@ -569,6 +576,13 @@ class DifferentialEvolutionWithCot(DifferentialEvolution): if evolved_prompt is None: logger.info(f"Could not extract prompt from response: {evolved_prompt}") + + # no prompt was returned (e.g., evolved prompt could not be extracted), therefore, for DE, we use the basic prompt + return ( + prompts_current_evolution[current_iteration].content, + judgements, + usage, + ) else: logger.info( "DE-evolved prompts '%s', '%s' and '%s' with basic prompt '%s' into '%s'", -- GitLab