From c7c87eed6658122276f632f99e0a379c647da2d3 Mon Sep 17 00:00:00 2001 From: Rick Hennigan Date: Fri, 22 Nov 2024 15:43:57 -0500 Subject: [PATCH] Bugfix: Handle failures in `llmSynthesizeSubmit` task --- Source/Chatbook/LLMUtilities.wl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Chatbook/LLMUtilities.wl b/Source/Chatbook/LLMUtilities.wl index c4b5581b..2853c5bc 100644 --- a/Source/Chatbook/LLMUtilities.wl +++ b/Source/Chatbook/LLMUtilities.wl @@ -44,10 +44,12 @@ llmSynthesize // endDefinition; llmSynthesize0 // beginDefinition; llmSynthesize0[ prompt: $$llmPrompt, evaluator_Association, attempt_ ] := Enclose[ - Module[ { result, callback }, + Module[ { result, callback, task }, result = $Failed; callback = Function[ result = # ]; - TaskWait @ llmSynthesizeSubmit[ prompt, evaluator, callback ]; + task = llmSynthesizeSubmit[ prompt, evaluator, callback ]; + If[ FailureQ @ task, throwFailureToChatOutput @ task ]; + TaskWait @ ConfirmMatch[ task, _TaskObject, "Task" ]; If[ MatchQ[ result, Failure[ "InvalidResponse", _ ] ] && attempt <= 3, Pause[ Exp @ attempt / E ]; llmSynthesize0[ prompt, evaluator, attempt + 1 ],