Skip to content

Commit

Permalink
Merge pull request #562 from WolframResearch/main
Browse files Browse the repository at this point in the history
Release v1.4.1
  • Loading branch information
rhennigan authored Jan 22, 2024
2 parents 00db891 + f978bcc commit 99ef68c
Show file tree
Hide file tree
Showing 26 changed files with 2,324 additions and 1,226 deletions.
4 changes: 2 additions & 2 deletions FrontEnd/StyleSheets/Chatbook.nb
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ Notebook[
],
Cell[
StyleData["ChatStyleSheetInformation"],
TaggingRules -> <|"StyleSheetVersion" -> "1.4.0.3913547000"|>
TaggingRules -> <|"StyleSheetVersion" -> "1.4.1.3913792210"|>
],
Cell[
StyleData["Text"],
Expand Down Expand Up @@ -17593,4 +17593,4 @@ Notebook[
]
},
StyleDefinitions -> "PrivateStylesheetFormatting.nb"
]
]
2 changes: 1 addition & 1 deletion PacletInfo.wl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PacletObject[ <|
"Name" -> "Wolfram/Chatbook",
"PublisherID" -> "Wolfram",
"Version" -> "1.4.0",
"Version" -> "1.4.1",
"WolframVersion" -> "13.3+",
"Description" -> "Wolfram Notebooks + LLMs",
"License" -> "MIT",
Expand Down
1 change: 1 addition & 0 deletions Scripts/Common.wl
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ Print[ "ResourceSystemBase: ", $ResourceSystemBase ];
$defNB = File @ FileNameJoin @ { $pacletDir, "ResourceDefinition.nb" };
Print[ "Definition Notebook: ", $defNB ];

PacletDirectoryLoad @ $pacletDir;

$loadedDefinitions = True;

Expand Down
71 changes: 58 additions & 13 deletions Source/Chatbook/Actions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ BeginPackage[ "Wolfram`Chatbook`Actions`" ];
`$autoAssistMode;
`$autoOpen;
`$finalCell;
`$lastCellObject;
`$lastChatString;
`$lastMessages;
`$lastSettings;
Expand Down Expand Up @@ -406,14 +407,32 @@ EvaluateChatInput[ evalCell_CellObject, nbo_NotebookObject ] :=
EvaluateChatInput[ evalCell, nbo, currentChatSettings @ nbo ];

EvaluateChatInput[ evalCell_CellObject, nbo_NotebookObject, settings_Association? AssociationQ ] :=
withChatState @ Block[ { $autoAssistMode = False },
$lastMessages = None;
withChatState @ Block[ { $autoAssistMode = False, $aborted = False },
$lastCellObject = None;
$lastChatString = None;
$lastMessages = None;
$nextTaskEvaluation = None;
clearMinimizedChats @ nbo;
$enableLLMServices = settings[ "EnableLLMServices" ];
sendChat[ evalCell, nbo, settings ];
waitForLastTask[ ];
clearMinimizedChats @ nbo;

(* Send chat while listening for an abort: *)
CheckAbort[
sendChat[ evalCell, nbo, settings ];
waitForLastTask[ ]
,
(* The user has issued an abort: *)
$aborted = True;
(* Clean up the current chat evaluation: *)
With[ { cell = $lastCellObject },
If[ MatchQ[ cell, _CellObject ],
StopChat @ cell,
removeTask @ $lastTask
]
]
,
PropagateAborts -> False
];

blockChatObject[
If[ ListQ @ $lastMessages && StringQ @ $lastChatString,
With[
Expand All @@ -423,18 +442,31 @@ EvaluateChatInput[ evalCell_CellObject, nbo_NotebookObject, settings_Association
<| "Role" -> "Assistant", "Content" -> $lastChatString |>
]
},
applyHandlerFunction[ settings, "ChatPost", <| "ChatObject" -> chat, "NotebookObject" -> nbo |> ];
Sow[ chat, $chatObjectTag ]
applyChatPost[ chat, settings, nbo, $aborted ]
],
applyHandlerFunction[ settings, "ChatPost", <| "ChatObject" -> None, "NotebookObject" -> nbo |> ];
Sow[ None, $chatObjectTag ];
applyChatPost[ None, settings, nbo, $aborted ];
Null
];
]
];

EvaluateChatInput // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*applyChatPost*)
applyChatPost // beginDefinition;

applyChatPost[ chat_, settings_, nbo_, aborted: True|False ] := (
If[ aborted,
applyHandlerFunction[ settings, "ChatAbort", <| "ChatObject" -> chat, "NotebookObject" -> nbo |> ],
applyHandlerFunction[ settings, "ChatPost" , <| "ChatObject" -> chat, "NotebookObject" -> nbo |> ]
];
Sow[ chat, $chatObjectTag ]
);

applyChatPost // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*blockChatObject*)
Expand Down Expand Up @@ -481,10 +513,23 @@ ensureChatInputCell // endDefinition;
(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*chatOutputCellQ*)
chatOutputCellQ[ cell_CellObject ] := chatOutputCellQ[ cell ] = chatOutputCellQ[ cell, Developer`CellInformation @ cell ];
chatOutputCellQ[ cell_, KeyValuePattern[ "Style" -> $$chatOutputStyle ] ] := True;
chatOutputCellQ[ cell_CellObject, ___ ] := ($badCellObject = cell; $badCell = NotebookRead @ cell; False);
chatOutputCellQ[ ___ ] := False;
chatOutputCellQ[ cell_CellObject ] := chatOutputCellQ[ cell ] =
chatOutputCellQ[ cell, Developer`CellInformation @ cell ];

chatOutputCellQ[ cell_, KeyValuePattern[ "Style" -> $$chatOutputStyle ] ] :=
True;

chatOutputCellQ[ cell_CellObject, KeyValuePattern[ "Style" -> "Output" ] ] /; $cloudNotebooks :=
MatchQ[ CurrentValue[ cell, { TaggingRules, "ChatNotebookSettings", "CellObject" } ], _CellObject ];

chatOutputCellQ[ cell_CellObject, ___ ] := (
$badCellObject = cell;
$badCell = NotebookRead @ cell;
False
);

chatOutputCellQ[ ___ ] :=
False;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
Expand Down
1 change: 1 addition & 0 deletions Source/Chatbook/ChatHistory.wl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ chatExcludedQ[ KeyValuePattern[ "Style" -> $$chatIgnoredStyle ] ] := True;
chatExcludedQ[ KeyValuePattern[ "ChatNotebookSettings" -> settings_ ] ] := chatExcludedQ @ settings;
chatExcludedQ[ KeyValuePattern[ "ExcludeFromChat" -> exclude_ ] ] := TrueQ @ exclude;
chatExcludedQ[ KeyValuePattern[ { } ] ] := False;
chatExcludedQ[ Inherited ] := False;

chatExcludedQ // endDefinition;

Expand Down
1 change: 1 addition & 0 deletions Source/Chatbook/ChatMessages.wl
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ inferMultimodalTypes[ content_List ] := Enclose[

inferMultimodalTypes // endDefinition;

(* TODO: add a way to control image detail and insert "Detail" -> "..." here when appropriate: *)
inferMultimodalTypes0 // beginDefinition;
inferMultimodalTypes0[ content_List ] := inferMultimodalTypes0 /@ content;
inferMultimodalTypes0[ content_String ] := <| "Type" -> "Text" , "Data" -> content |>;
Expand Down
10 changes: 9 additions & 1 deletion Source/Chatbook/Chatbook.wl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ Quiet[
Unprotect[ "Wolfram`Chatbook`*" ];
ClearAll[ "Wolfram`Chatbook`*" ];
ClearAll[ "Wolfram`Chatbook`*`*" ];
Get @ Wolfram`ChatbookLoader`$MXFile
Get @ Wolfram`ChatbookLoader`$MXFile;
(* Ensure all subcontexts are in $Packages to avoid reloading subcontexts out of order: *)
If[ MatchQ[ Wolfram`Chatbook`$ChatbookContexts, { __String } ],
WithCleanup[
Unprotect @ $Packages,
$Packages = DeleteDuplicates @ Join[ $Packages, Wolfram`Chatbook`$ChatbookContexts ],
Protect @ $Packages
]
]
,
WithCleanup[
PreemptProtect[
Expand Down
Loading

0 comments on commit 99ef68c

Please sign in to comment.