Skip to content

Commit

Permalink
Merge pull request #477 from WolframResearch/bugfix/handle-failures-i…
Browse files Browse the repository at this point in the history
…n-tool-call-chat-submit

Bugfix: Handle failures in tool call chat submit
  • Loading branch information
rhennigan authored Nov 30, 2023
2 parents 046ad94 + 0f3fbec commit f12bfa4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Source/Chatbook/ChatMessages.wl
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,23 @@ inferMultimodalTypes // endDefinition;
inferMultimodalTypes0 // beginDefinition;
inferMultimodalTypes0[ content_List ] := inferMultimodalTypes0 /@ content;
inferMultimodalTypes0[ content_String ] := <| "Type" -> "Text" , "Data" -> content |>;
inferMultimodalTypes0[ content_? graphicsQ ] := <| "Type" -> "Image", "Data" -> content |>;
inferMultimodalTypes0[ content_? graphicsQ ] := <| "Type" -> "Image", "Data" -> ensureCompatibleImage @ content |>;
inferMultimodalTypes0 // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsubsection::Closed:: *)
(*ensureCompatibleImage*)
ensureCompatibleImage // beginDefinition;
ensureCompatibleImage[ img_ ] /; $useRasterizationCompatibility && ! Image`PossibleImageQ @ img := Rasterize @ img;
ensureCompatibleImage[ img_ ] := img;
ensureCompatibleImage // endDefinition;


$useRasterizationCompatibility := Enclose[
$useRasterizationCompatibility =
! PacletNewerQ[ ConfirmBy[ PacletObject[ "ServiceConnection_OpenAI" ], PacletObjectQ ], "13.3.18" ]
];

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*expressionURIQ*)
Expand Down
15 changes: 13 additions & 2 deletions Source/Chatbook/SendChat.wl
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ toolFreeQ // endDefinition;
toolEvaluation // beginDefinition;

toolEvaluation[ settings_, container_Symbol, cell_, as_Association ] := Enclose[
Module[ { string, callPos, toolCall, toolResponse, output, messages, newMessages, req, toolID },
Module[ { string, callPos, toolCall, toolResponse, output, messages, newMessages, req, toolID, task },

string = ConfirmBy[ container[ "FullContent" ], StringQ, "FullContent" ];

Expand Down Expand Up @@ -1010,7 +1010,18 @@ toolEvaluation[ settings_, container_Symbol, cell_, as_Association ] := Enclose[

appendToolResult[ container, output, toolID ];

$lastTask = chatSubmit[ container, req, cell, settings ]
task = $lastTask = chatSubmit[ container, req, cell, settings ];

addHandlerArguments[ "Task" -> task ];

CurrentValue[ cell, { TaggingRules, "ChatNotebookSettings", "CellObject" } ] = cell;
CurrentValue[ cell, { TaggingRules, "ChatNotebookSettings", "Task" } ] = task;

If[ FailureQ @ task, throwTop @ writeErrorCell[ cell, task ] ];

If[ task === $Canceled, StopChat @ cell ];

task
],
throwInternalFailure[ toolEvaluation[ settings, container, cell, as ], ## ] &
];
Expand Down

0 comments on commit f12bfa4

Please sign in to comment.