From c5c19fab036cb9d56fd7d9764973c74ab110a018 Mon Sep 17 00:00:00 2001 From: ilyanekhay-uta <142261870+ilyanekhay-uta@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:52:25 -0500 Subject: [PATCH] Avoid double-including error message in retry when Mode.TOOLS (#514) --- instructor/retry.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/instructor/retry.py b/instructor/retry.py index 2ed50a807..cd3139c76 100644 --- a/instructor/retry.py +++ b/instructor/retry.py @@ -26,6 +26,7 @@ def reask_messages(response: ChatCompletion, mode: Mode, exception: Exception): yield dump_message(response.choices[0].message) + # TODO: Give users more control on configuration if mode == Mode.TOOLS: for tool_call in response.choices[0].message.tool_calls: # type: ignore yield { @@ -34,9 +35,7 @@ def reask_messages(response: ChatCompletion, mode: Mode, exception: Exception): "name": tool_call.function.name, "content": f"Validation Error found:\n{exception}\nRecall the function correctly, fix the errors", } - - # TODO: Give users more control on configuration - if mode == Mode.MD_JSON: + elif mode == Mode.MD_JSON: yield { "role": "user", "content": f"Correct your JSON ONLY RESPONSE, based on the following errors:\n{exception}",