Skip to content

Commit ff48e5f

Browse files
authored
Merge pull request #966 from WolframResearch/bugfix/454827
Bugfix: Use default `EvaluateWithProgress` for normal chat notebook evaluations
2 parents 281b8e0 + 0a5f6dd commit ff48e5f

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

PacletInfo.wl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PacletObject[ <|
22
"Name" -> "Wolfram/Chatbook",
33
"PublisherID" -> "Wolfram",
4-
"Version" -> "1.5.2.16",
4+
"Version" -> "1.5.2.17",
55
"WolframVersion" -> "14.1+",
66
"Description" -> "Wolfram Notebooks + LLMs",
77
"License" -> "MIT",

Source/Chatbook/PromptGenerators/VectorDatabases.wl

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,27 @@ downloadVectorDatabases[ ] :=
128128
downloadVectorDatabases[ $localVectorDBDirectory, $vectorDBDownloadURLs ];
129129

130130
downloadVectorDatabases[ dir0_, urls_Association ] := Enclose[
131-
Module[ { names, sizes, dir, tasks },
131+
Module[ { dir, lock, names, sizes, tasks },
132132

133-
dir = ConfirmBy[ GeneralUtilities`EnsureDirectory @ dir0, DirectoryQ, "Directory" ];
133+
dir = ConfirmBy[ GeneralUtilities`EnsureDirectory @ dir0, DirectoryQ, "Directory" ];
134+
lock = FileNameJoin @ { dir, "download.lock" };
134135
names = ConfirmMatch[ Keys @ urls, { __String }, "Names" ];
135136
sizes = ConfirmMatch[ getDownloadSize /@ Values @ urls, { __? Positive }, "Sizes" ];
136137

137138
$downloadProgress = AssociationMap[ 0 &, names ];
138139
$progressText = "Downloading semantic search indices\[Ellipsis]";
139140

140141
evaluateWithProgress[
141-
142-
tasks = ConfirmMatch[ KeyValueMap[ downloadVectorDatabase @ dir, urls ], { __TaskObject }, "Download" ];
143-
ConfirmMatch[ taskWait @ tasks, { __TaskObject }, "TaskWait" ];
144-
$progressText = "Unpacking files\[Ellipsis]";
145-
ConfirmBy[ unpackVectorDatabases @ dir, DirectoryQ, "Unpacked" ],
142+
WithLock[
143+
File @ lock
144+
,
145+
tasks = ConfirmMatch[ KeyValueMap[ downloadVectorDatabase @ dir, urls ], { __TaskObject }, "Download" ];
146+
ConfirmMatch[ taskWait @ tasks, { (_TaskObject|$Failed).. }, "TaskWait" ];
147+
$progressText = "Unpacking files\[Ellipsis]";
148+
ConfirmBy[ unpackVectorDatabases @ dir, DirectoryQ, "Unpacked" ]
149+
,
150+
PersistenceTime -> 180
151+
],
146152

147153
<|
148154
"Text" :> $progressText,
@@ -205,7 +211,7 @@ unpackVectorDatabase // endDefinition;
205211
(* ::Subsubsection::Closed:: *)
206212
(*taskWait*)
207213
taskWait // beginDefinition;
208-
taskWait[ tasks_List ] := taskWait /@ tasks;
214+
taskWait[ tasks_List ] := CheckAbort[ taskWait /@ tasks, Quiet[ TaskRemove /@ tasks ], PropagateAborts -> True ];
209215
taskWait[ task_TaskObject ] := taskWait[ task, task[ "TaskStatus" ] ];
210216
taskWait[ task_TaskObject, "Removed" ] := task;
211217
taskWait[ task_TaskObject, _ ] := TaskWait @ task;
@@ -220,17 +226,26 @@ downloadVectorDatabase[ dir_ ] :=
220226
downloadVectorDatabase[ dir, ## ] &;
221227

222228
downloadVectorDatabase[ dir_, name_String, url_String ] := Enclose[
223-
Module[ { file },
229+
Module[ { file, tmp },
230+
224231
file = ConfirmBy[ FileNameJoin @ { dir, name<>".zip" }, StringQ, "File" ];
225-
ConfirmMatch[
226-
URLDownloadSubmit[
227-
url,
228-
file,
229-
HandlerFunctions -> <| "TaskProgress" -> setDownloadProgress @ name |>,
230-
HandlerFunctionsKeys -> { "ByteCountDownloaded" }
231-
],
232-
_TaskObject,
233-
"Task"
232+
tmp = file <> ".tmp";
233+
Quiet[ DeleteFile /@ { file, tmp } ];
234+
235+
With[ { tmp = tmp, file = file },
236+
ConfirmMatch[
237+
URLDownloadSubmit[
238+
url,
239+
tmp,
240+
HandlerFunctions -> <|
241+
"TaskProgress" -> setDownloadProgress @ name,
242+
"TaskFinished" -> (RenameFile[ tmp, file ] &)
243+
|>,
244+
HandlerFunctionsKeys -> { "ByteCountDownloaded" }
245+
],
246+
_TaskObject,
247+
"Task"
248+
]
234249
]
235250
] // LogChatTiming[ { "DownloadVectorDatabase", name } ],
236251
throwInternalFailure

Source/Chatbook/Utils.wl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,8 @@ evaluateWithProgress // beginDefinition;
822822
evaluateWithProgress // Attributes = { HoldFirst };
823823
evaluateWithProgress[ args___ ] /; $WorkspaceChat := evaluateWithWorkspaceProgress @ args;
824824
evaluateWithProgress[ args___ ] /; $InlineChat := evaluateWithInlineProgress @ args;
825-
evaluateWithProgress[ args___ ] := evaluateWithProgressContainer[ $progressContainer, args ];
825+
evaluateWithProgress[ args___ ] /; $ContentSuggestions := evaluateWithProgressContainer[ $progressContainer, args ];
826+
evaluateWithProgress[ args___ ] := Progress`EvaluateWithProgress[ args, "Delay" -> 0 ];
826827
evaluateWithProgress // endDefinition;
827828

828829
(* ::**************************************************************************************************************:: *)

0 commit comments

Comments
 (0)