Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.3.6 #509

Merged
merged 17 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
e781846
Manually reparse `BoxData["..."]` into boxes when in cloud
rhennigan Jan 2, 2024
5f64c74
Bump paclet version
rhennigan Jan 2, 2024
d0b62df
Update stylesheet version
rhennigan Jan 2, 2024
1095bb9
Add missing `reparseCodeBoxes` call for string arguments
rhennigan Jan 2, 2024
90fdc08
Merge pull request #502 from WolframResearch/501-code-blocks-with-mul…
rhennigan Jan 2, 2024
2d4a621
Just rerun cell initialization instead of duplicating code for each c…
rhennigan Jan 2, 2024
175b257
Merge pull request #503 from WolframResearch/299-assistant-output-cel…
rhennigan Jan 2, 2024
77564b3
Show checkmark next to "User" role as default
rhennigan Jan 2, 2024
55b09d4
Return `Null` if all cells are excluded
rhennigan Jan 2, 2024
feaac5b
Do not proceed with chat evaluation for chat inputs that are excluded
rhennigan Jan 2, 2024
3f9852d
Merge pull request #504 from WolframResearch/300-advanced-settings-ro…
rhennigan Jan 2, 2024
56fd8b3
Merge pull request #505 from WolframResearch/350-executing-a-chatexcl…
rhennigan Jan 2, 2024
ab4baab
Use `Verbatim` when caching values for `openerView`, since arguments …
rhennigan Jan 2, 2024
400859a
Merge pull request #507 from WolframResearch/506-tool-responses-conta…
rhennigan Jan 2, 2024
0a155d0
Setting `MaxContextTokens -> Infinity` will skip the usual truncation…
rhennigan Jan 2, 2024
6b9aa17
Initialize budget values earlier
rhennigan Jan 2, 2024
7757dfc
Merge pull request #508 from WolframResearch/feature/set-max-tokens-t…
rhennigan Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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