Skip to content

Commit fac0708

Browse files
authored
Merge pull request #1296 from WolframResearch/feature/attachments
Added `LoadAttachments`
2 parents bb7c5af + 3be9940 commit fac0708

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

Source/Chatbook/Main.wl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ BeginPackage[ "Wolfram`Chatbook`" ];
7979
`InstallVectorDatabases;
8080
`InvalidateServiceCache;
8181
`ListSavedChats;
82+
`LoadAttachments;
8283
`LoadChat;
8384
`LogChatTiming;
8485
`MakeExpressionURI;
8586
`ProcessNotebookForRAG;
8687
`RebuildChatSearchIndex;
8788
`RegisterVectorDatabase;
8889
`RelatedDocumentation;
89-
`RelatedWolframAlphaResults;
9090
`RelatedWolframAlphaQueries;
91+
`RelatedWolframAlphaResults;
9192
`RemoveChatFromSearchIndex;
9293
`SandboxLinguisticAssistantData;
9394
`SaveAsChatNotebook;
@@ -264,6 +265,7 @@ $ChatbookProtectedNames = "Wolfram`Chatbook`" <> # & /@ {
264265
"InlineTemplateBoxes",
265266
"InstallVectorDatabases",
266267
"ListSavedChats",
268+
"LoadAttachments",
267269
"LoadChat",
268270
"LogChatTiming",
269271
"MakeExpressionURI",
@@ -272,6 +274,7 @@ $ChatbookProtectedNames = "Wolfram`Chatbook`" <> # & /@ {
272274
"RegisterVectorDatabase",
273275
"RelatedDocumentation",
274276
"RelatedWolframAlphaQueries",
277+
"RelatedWolframAlphaResults",
275278
"RemoveChatFromSearchIndex",
276279
"SandboxLinguisticAssistantData",
277280
"SaveAsChatNotebook",

Source/Chatbook/Storage.wl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,8 @@ restoreAttachments // beginDefinition;
222222
restoreAttachments[ KeyValuePattern[ "Attachments" -> attachments_Association ] ] :=
223223
Association @ KeyValueMap[ # -> restoreAttachments @ ## &, attachments ];
224224

225-
restoreAttachments[ "Expressions", expressions_Association ] := Enclose[
226-
$attachments = ConfirmBy[ <| $attachments, expressions |>, AssociationQ, "Attachments" ],
227-
throwInternalFailure
228-
];
229-
230-
restoreAttachments[ "ToolCalls", toolCalls_Association ] := Enclose[
231-
$toolEvaluationResults = ConfirmBy[ <| $toolEvaluationResults, toolCalls |>, AssociationQ, "ToolCalls" ],
225+
restoreAttachments[ type: "Expressions"|"ToolCalls", as_Association ] := Enclose[
226+
ConfirmBy[ LoadAttachments[ type, as ], AssociationQ, "LoadAttachments" ],
232227
throwInternalFailure
233228
];
234229

Source/Chatbook/Tools/ExpressionURIs.wl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ GetAttachments[ messages_ ] :=
340340
GetAttachments[ messages: $$chatMessages|None, prop: $$attachmentProperty|All ] :=
341341
catchMine @ getAttachments[ messages, prop ];
342342

343+
GetAttachments[ content_, prop: $$attachmentProperty|All ] :=
344+
catchMine @ getAttachments[ ensureChatMessages @ content, prop ];
345+
343346
GetAttachments // endExportedDefinition;
344347

345348
(* TODO: this should identify expression and tool call keys from earlier sessions and give Missing[...] for those *)
@@ -378,6 +381,31 @@ getAttachments[ messages_, prop: $$attachmentProperty ] := Enclose[
378381

379382
getAttachments // endDefinition;
380383

384+
(* ::**************************************************************************************************************:: *)
385+
(* ::Section::Closed:: *)
386+
(*LoadAttachments*)
387+
LoadAttachments // beginDefinition;
388+
LoadAttachments[ as_Association ] := catchMine @ LoadAttachments[ "Expressions", as ];
389+
LoadAttachments[ type: "Expressions"|"ToolCalls", as_Association ] := catchMine @ loadAttachments[ type, as ];
390+
LoadAttachments // endExportedDefinition;
391+
392+
(* ::**************************************************************************************************************:: *)
393+
(* ::Subsection::Closed:: *)
394+
(*loadAttachments*)
395+
loadAttachments // beginDefinition;
396+
397+
loadAttachments[ "Expressions", expressions_Association ] := Enclose[
398+
$attachments = ConfirmBy[ <| $attachments, expressions |>, AssociationQ, "Attachments" ],
399+
throwInternalFailure
400+
];
401+
402+
loadAttachments[ "ToolCalls", toolCalls_Association ] := Enclose[
403+
$toolEvaluationResults = ConfirmBy[ <| $toolEvaluationResults, toolCalls |>, AssociationQ, "ToolCalls" ],
404+
throwInternalFailure
405+
];
406+
407+
loadAttachments // endDefinition;
408+
381409
(* ::**************************************************************************************************************:: *)
382410
(* ::Section::Closed:: *)
383411
(*Package Footer*)

0 commit comments

Comments
 (0)