Skip to content

Commit

Permalink
Merge pull request #509 from WolframResearch/main
Browse files Browse the repository at this point in the history
Release v1.3.6
  • Loading branch information
rhennigan authored Jan 3, 2024
2 parents c6f2ed9 + 7757dfc commit 00a4dce
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 34 deletions.
2 changes: 1 addition & 1 deletion 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.3.4.3910935567"|>
TaggingRules -> <|"StyleSheetVersion" -> "1.3.6.3913177292"|>
],
Cell[
StyleData["Text"],
Expand Down
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.3.5",
"Version" -> "1.3.6",
"WolframVersion" -> "13.3+",
"Description" -> "Wolfram Notebooks + LLMs",
"License" -> "MIT",
Expand Down
7 changes: 5 additions & 2 deletions Source/Chatbook/Actions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,10 @@ EvaluateChatInput // beginDefinition;
EvaluateChatInput[ ] := EvaluateChatInput @ rootEvaluationCell[ ];

EvaluateChatInput[ evalCell_CellObject? chatInputCellQ ] :=
EvaluateChatInput[ evalCell, parentNotebook @ evalCell ];
If[ chatExcludedQ @ evalCell,
Null,
EvaluateChatInput[ evalCell, parentNotebook @ evalCell ]
];

EvaluateChatInput[ source: _CellObject | $Failed ] :=
With[ { evalCell = rootEvaluationCell @ source },
Expand Down Expand Up @@ -1034,7 +1037,7 @@ SendChat // beginDefinition;

SendChat[ ] := SendChat @ rootEvaluationCell[ ];

SendChat[ evalCell_CellObject, ___ ] /; MemberQ[ CurrentValue[ evalCell, CellStyle ], "ChatExcluded" ] := Null;
SendChat[ evalCell_CellObject? chatExcludedQ, ___ ] := Null;

SendChat[ evalCell_CellObject ] := SendChat[ evalCell, parentNotebook @ evalCell ];

Expand Down
30 changes: 17 additions & 13 deletions Source/Chatbook/ChatHistory.wl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ BeginPackage[ "Wolfram`Chatbook`ChatHistory`" ];

HoldComplete[
`accentIncludedCells;
`chatExcludedQ;
`extraCellHeight;
`filterChatCells;
`getCellsInChatHistory;
Expand Down Expand Up @@ -172,24 +173,27 @@ selectChatHistoryCells // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*filterChatCells*)
filterChatCells // beginDefinition;
(*chatExcludedQ*)
chatExcludedQ // beginDefinition;

filterChatCells[ cellInfo: { ___Association } ] := Enclose[
Module[ { styleExcluded, tagExcluded, cells },
chatExcludedQ[ cell_CellObject ] := chatExcludedQ @ cellInformation @ cell;

styleExcluded = DeleteCases[ cellInfo, KeyValuePattern[ "Style" -> $$chatIgnoredStyle ] ];
chatExcludedQ[ Cell[ __, $$chatIgnoredStyle, ___ ] ] := True;
chatExcludedQ[ Cell[ __, TaggingRules -> tags_, ___ ] ] := chatExcludedQ @ tags;
chatExcludedQ[ Cell[ ___ ] ] := False;

tagExcluded = DeleteCases[
styleExcluded,
KeyValuePattern[ "ChatNotebookSettings" -> KeyValuePattern[ "ExcludeFromChat" -> True ] ]
];
chatExcludedQ[ KeyValuePattern[ "Style" -> $$chatIgnoredStyle ] ] := True;
chatExcludedQ[ KeyValuePattern[ "ChatNotebookSettings" -> settings_ ] ] := chatExcludedQ @ settings;
chatExcludedQ[ KeyValuePattern[ "ExcludeFromChat" -> exclude_ ] ] := TrueQ @ exclude;
chatExcludedQ[ KeyValuePattern[ { } ] ] := False;

tagExcluded
],
throwInternalFailure[ filterChatCells @ cellInfo, ## ] &
];
chatExcludedQ // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*filterChatCells*)
filterChatCells // beginDefinition;
filterChatCells[ cellInfo: { ___Association } ] := Select[ cellInfo, Not @* chatExcludedQ ];
filterChatCells // endDefinition;

(* ::**************************************************************************************************************:: *)
Expand Down
14 changes: 9 additions & 5 deletions Source/Chatbook/ChatMessages.wl
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,14 @@ makeChatMessages[ settings_, cells_ ] :=
{
$multimodalMessages = TrueQ @ settings[ "Multimodal" ],
$tokenBudget = settings[ "MaxContextTokens" ],
$tokenPressure = 0.0
$tokenPressure = 0.0,
$initialCellStringBudget = Replace[
settings[ "MaxCellStringLength" ],
Except[ $$size ] -> $defaultMaxCellStringLength
],
$cellStringBudget
},
$cellStringBudget = $initialCellStringBudget;
If[ settings[ "BasePrompt" ] =!= None, tokenCheckedMessage[ settings, $fullBasePrompt ] ];
(* FIXME: need to account for persona/tool prompting as well *)
makeChatMessages0[ settings, cells ]
Expand All @@ -241,10 +247,6 @@ makeChatMessages0[ settings0_, cells_List ] := Enclose[
toMessage0 = Confirm[ getCellMessageFunction @ settings, "CellMessageFunction" ];

$tokenBudgetLog = Internal`Bag[ ];
$initialCellStringBudget = Replace[
settings[ "MaxCellStringLength" ],
Except[ $$size ] -> $defaultMaxCellStringLength
];

toMessage = Function @ With[
{ msg = toMessage0[ #1, <| #2, "TokenBudget" -> $tokenBudget, "TokenPressure" -> $tokenPressure |> ] },
Expand Down Expand Up @@ -304,6 +306,8 @@ combineExcisedMessages // endDefinition;
(*tokenCheckedMessage*)
tokenCheckedMessage // beginDefinition;

tokenCheckedMessage[ as_Association, message_ ] /; $cellStringBudget === Infinity := message;

tokenCheckedMessage[ as_Association, message_ ] := Enclose[
Catch @ Module[ { count, budget, resized },

Expand Down
17 changes: 15 additions & 2 deletions Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ insertCodeBelow[ cell_Cell, evaluate_ ] :=
];

insertCodeBelow[ string_String, evaluate_ ] :=
insertCodeBelow[ Cell[ BoxData @ string, "Input" ], evaluate ];
insertCodeBelow[ reparseCodeBoxes @ Cell[ BoxData @ string, "Input" ], evaluate ];

insertCodeBelow // endDefinition;

Expand Down Expand Up @@ -491,7 +491,7 @@ getCodeBlockContent[ TemplateBox[ { boxes_ }, "ChatCodeBlockTemplate", ___ ] ] :
getCodeBlockContent[ Cell[ BoxData[ boxes_, ___ ] ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ DynamicModuleBox[ _, boxes_, ___ ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ TagBox[ boxes_, _EventHandlerTag, ___ ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ Cell[ boxes_, "ChatCode", "Input", ___ ] ] := Cell[ boxes, "Input" ];
getCodeBlockContent[ Cell[ boxes_, "ChatCode", "Input", ___ ] ] := reparseCodeBoxes @ Cell[ boxes, "Input" ];

getCodeBlockContent[ Cell[ boxes_, "ExternalLanguage", ___, CellEvaluationLanguage -> lang_, ___ ] ] :=
Cell[ boxes, "ExternalLanguage", CellEvaluationLanguage -> lang ];
Expand All @@ -500,6 +500,19 @@ getCodeBlockContent[ cell: Cell[ _, _String, ___ ] ] := cell;

getCodeBlockContent // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*reparseCodeBoxes*)
reparseCodeBoxes // beginDefinition;

reparseCodeBoxes[ Cell[ BoxData[ s_String ], a___ ] ] /; $cloudNotebooks :=
Cell[ BoxData @ UsingFrontEnd @ stringToBoxes @ s, a ];

reparseCodeBoxes[ cell_Cell ] :=
cell;

reparseCodeBoxes // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*Boxes*)
Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/FrontEnd.wl
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ compressRasterBoxes // endDefinition;
(* Effectively equivalent to OpenerView, except strips out the unnecessary interpretation information, and compresses
the hidden part if it's very large.
*)
openerView[ args___ ] := openerView[ args ] = openerView0[ args ];
openerView[ args___ ] := Verbatim[ openerView[ args ] ] = openerView0[ args ];

openerView0 // beginDefinition;
openerView0[ { a_, b_ }, args___ ] /; ByteCount @ b > 50000 := openerView1[ { a, compressUntilViewed @ b }, args ];
Expand Down
13 changes: 5 additions & 8 deletions Source/Chatbook/SendChat.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,9 @@ selectChatCells0[ cell_, cells: { __CellObject }, final_ ] := Enclose[
(* Filter out ignored cells *)
filtered = ConfirmMatch[ filterChatCells @ selectedRange, { ___Association }, "FilteredCellInfo" ];

(* If all cells are excluded, do nothing *)
If[ filtered === { }, throwTop @ Null ];

(* Delete output cells that come after the evaluation cell *)
rest = deleteExistingChatOutputs @ Drop[ cellData, cellPosition ];

Expand Down Expand Up @@ -1298,6 +1301,7 @@ $autoSettingKeyPriority := Enclose[
(* FIXME: need to hook into token pressure to gradually decrease limits *)
chooseMaxCellStringLength // beginDefinition;
chooseMaxCellStringLength[ as_Association ] := chooseMaxCellStringLength[ as, as[ "MaxContextTokens" ] ];
chooseMaxCellStringLength[ as_, Infinity ] := Infinity;
chooseMaxCellStringLength[ as_, tokens: $$size ] := Ceiling[ $defaultMaxCellStringLength * tokens / 2^13 ];
chooseMaxCellStringLength // endDefinition;

Expand Down Expand Up @@ -2297,14 +2301,7 @@ attachChatOutputMenu[ cell_CellObject ] /; $cloudNotebooks := Null;

attachChatOutputMenu[ cell_CellObject ] := (
$lastChatOutput = cell;
NotebookDelete @ Cells[ cell, AttachedCell -> True, CellStyle -> "ChatMenu" ];
AttachCell[
cell,
Cell[ BoxData @ TemplateBox[ { "ChatOutput", RGBColor[ "#ecf0f5" ] }, "ChatMenuButton" ], "ChatMenu" ],
{ Right, Top },
Offset[ { -7, -7 }, { Right, Top } ],
{ Right, Top }
]
Block[ { EvaluationCell = cell & }, CurrentValue[ cell, Initialization ] ]
);

attachChatOutputMenu // endDefinition;
Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/UI.wl
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ makeChatActionMenuContent[
}, Module[{
personaValue = OptionValue["PersonaValue"],
modelValue = OptionValue["ModelValue"],
roleValue = OptionValue["RoleValue"],
roleValue = Replace[OptionValue["RoleValue"], {source_, Inherited} :> {source, "User"}],
toolValue = OptionValue["ToolCallFrequency"],
tempValue = OptionValue["TemperatureValue"],
advancedSettingsMenu,
Expand Down

0 comments on commit 00a4dce

Please sign in to comment.