Skip to content

Commit

Permalink
Merge pull request #947 from WolframResearch/bugfix/454287
Browse files Browse the repository at this point in the history
Bugfix: Handle failures in `llmSynthesizeSubmit` task
  • Loading branch information
rhennigan authored Nov 22, 2024
2 parents 95edf72 + c7c87ee commit b26ae62
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/Chatbook/LLMUtilities.wl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ],
Expand Down

0 comments on commit b26ae62

Please sign in to comment.