Skip to content

Commit 67eef22

Browse files
authored
Merge pull request #983 from WolframResearch/feature/inherit-some-NA-settings-in-popout-chat
Inherit some NA settings in popout chat
2 parents f622c8b + df93187 commit 67eef22

File tree

2 files changed

+64
-13
lines changed

2 files changed

+64
-13
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" -> "2.0.4",
4+
"Version" -> "2.0.5",
55
"WolframVersion" -> "14.1+",
66
"Description" -> "Wolfram Notebooks + LLMs",
77
"License" -> "MIT",

Source/Chatbook/ChatModes/UI.wl

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ SaveAsChatNotebook // endExportedDefinition;
13801380
saveAsChatNB // beginDefinition;
13811381

13821382
saveAsChatNB[ targetObj_NotebookObject ] := Enclose[
1383-
Catch @ Module[ { cellObjects, title, filepath, cells, nbExpr },
1383+
Catch @ Module[ { cellObjects, title, filepath, cells, settings, nbExpr },
13841384
cellObjects = Cells @ targetObj;
13851385
If[ ! MatchQ[ cellObjects, { __CellObject } ], Throw @ Null ];
13861386
title = Replace[
@@ -1400,7 +1400,8 @@ saveAsChatNB[ targetObj_NotebookObject ] := Enclose[
14001400
StringQ @ filepath && StringEndsQ[ filepath, ".nb" ],
14011401
cells = NotebookRead @ cellObjects;
14021402
If[ ! MatchQ[ cells, { __Cell } ], Throw @ Null ];
1403-
nbExpr = ConfirmMatch[ cellsToChatNB @ cells, _Notebook, "Converted" ];
1403+
settings = CurrentChatSettings @ targetObj;
1404+
nbExpr = ConfirmMatch[ cellsToChatNB[ cells, settings ], _Notebook, "Converted" ];
14041405
ConfirmBy[ Export[ filepath, nbExpr, "NB" ], FileExistsQ, "Exported" ],
14051406
True,
14061407
Null
@@ -1415,24 +1416,25 @@ saveAsChatNB // endDefinition;
14151416
(* ::Subsection::Closed:: *)
14161417
(*popOutChatNB*)
14171418
popOutChatNB // beginDefinition;
1418-
popOutChatNB[ nbo_NotebookObject ] := popOutChatNB @ NotebookGet @ nbo;
1419-
popOutChatNB[ Notebook[ cells_, ___ ] ] := popOutChatNB @ cells;
1420-
popOutChatNB[ Dynamic[ messageList_ ] ] := popOutChatNB @ messageList;
1421-
popOutChatNB[ cells: { ___Cell } ] := NotebookPut @ cellsToChatNB @ cells;
1422-
popOutChatNB[ chat_Association ] := popOutChatNB0 @ chat;
1419+
popOutChatNB[ nbo_NotebookObject ] := popOutChatNB[ NotebookGet @ nbo, CurrentChatSettings @ nbo ];
1420+
popOutChatNB[ Notebook[ cells_, ___ ], settings_ ] := popOutChatNB[ cells, settings ];
1421+
popOutChatNB[ cells: { ___Cell }, settings_ ] := NotebookPut @ cellsToChatNB[ cells, settings ];
1422+
popOutChatNB[ chat_Association, settings_Association ] := popOutChatNB0[ chat, settings ];
14231423
popOutChatNB // endDefinition;
14241424

14251425

14261426
popOutChatNB0 // beginDefinition;
14271427

1428-
popOutChatNB0[ id_ ] := Enclose[
1429-
Module[ { loaded, uuid, title, messages, cells },
1428+
popOutChatNB0[ id_, settings_Association ] := Enclose[
1429+
Module[ { loaded, uuid, title, messages, dingbat, cells, options },
14301430
loaded = ConfirmBy[ LoadChat @ id, AssociationQ, "Loaded" ];
14311431
uuid = ConfirmBy[ loaded[ "ConversationUUID" ], StringQ, "UUID" ];
14321432
title = ConfirmBy[ loaded[ "ConversationTitle" ], StringQ, "Title" ];
14331433
messages = ConfirmBy[ loaded[ "Messages" ], ListQ, "Messages" ];
1434-
cells = ConfirmMatch[ ChatMessageToCell @ messages, { __Cell }, "Cells" ];
1435-
ConfirmMatch[ CreateChatNotebook @ cells, _NotebookObject, "Notebook" ]
1434+
dingbat = Cell[ BoxData @ makeOutputDingbat @ settings, Background -> None ];
1435+
cells = ConfirmMatch[ updateCellDingbats[ ChatMessageToCell @ messages, dingbat ], { __Cell }, "Cells" ];
1436+
options = Sequence @@ Normal[ settings, Association ];
1437+
ConfirmMatch[ CreateChatNotebook[ cells, options ], _NotebookObject, "Notebook" ]
14361438
],
14371439
throwInternalFailure
14381440
];
@@ -1447,9 +1449,43 @@ cellsToChatNB // beginDefinition;
14471449
cellsToChatNB[ cells: { ___Cell } ] :=
14481450
Notebook[ cells /. $fromWorkspaceChatConversionRules, StyleDefinitions -> "Chatbook.nb" ];
14491451

1452+
cellsToChatNB[ cells: { ___Cell }, settings_Association ] :=
1453+
Module[ { dingbat, notebook },
1454+
1455+
dingbat = Cell[ BoxData @ makeOutputDingbat @ settings, Background -> None ];
1456+
notebook = updateCellDingbats[ cellsToChatNB @ cells, dingbat ];
1457+
1458+
Append[
1459+
notebook,
1460+
TaggingRules -> <| "ChatNotebookSettings" -> KeyTake[ settings, $popOutSettings ] |>
1461+
]
1462+
];
1463+
14501464
cellsToChatNB // endDefinition;
14511465

14521466

1467+
$popOutSettings = {
1468+
"LLMEvaluator",
1469+
"MaxContextTokens",
1470+
"MaxToolResponses",
1471+
"Model"
1472+
};
1473+
1474+
(* TODO: we should really have something better for this *)
1475+
$evaluatedChatInputDingbat = Cell[
1476+
BoxData @ DynamicBox @ ToBoxes[
1477+
If[ TrueQ @ CloudSystem`$CloudNotebooks,
1478+
RawBoxes @ TemplateBox[ { }, "ChatIconUser" ],
1479+
RawBoxes @ TemplateBox[ { }, "ChatInputCellDingbat" ]
1480+
],
1481+
StandardForm
1482+
],
1483+
Background -> None,
1484+
CellFrame -> 0,
1485+
CellMargins -> 0
1486+
];
1487+
1488+
14531489
$fromWorkspaceChatConversionRules := $fromWorkspaceChatConversionRules = Dispatch @ {
14541490
Cell[ BoxData @ TemplateBox[ { Cell[ TextData[ text_ ], ___ ] }, "UserMessageBox", ___ ], "ChatInput", ___ ] :>
14551491
Cell[ Flatten @ TextData @ text, "ChatInput" ]
@@ -1461,6 +1497,21 @@ $fromWorkspaceChatConversionRules := $fromWorkspaceChatConversionRules = Dispatc
14611497
Cell[ Flatten @ TextData @ text, "ChatOutput" ]
14621498
};
14631499

1500+
(* ::**************************************************************************************************************:: *)
1501+
(* ::Subsubsection::Closed:: *)
1502+
(*updateCellDingbats*)
1503+
updateCellDingbats // beginDefinition;
1504+
1505+
updateCellDingbats[ cells_, outputDingbat_ ] := ReplaceAll[
1506+
cells,
1507+
{
1508+
Cell[ a__, "ChatInput" , b___ ] :> Cell[ a, "ChatInput" , b, CellDingbat -> $evaluatedChatInputDingbat ],
1509+
Cell[ a__, "ChatOutput", b___ ] :> Cell[ a, "ChatOutput", b, CellDingbat -> outputDingbat ]
1510+
}
1511+
];
1512+
1513+
updateCellDingbats // endDefinition;
1514+
14641515
(* ::**************************************************************************************************************:: *)
14651516
(* ::Section::Closed:: *)
14661517
(*Overlay Menus*)
@@ -1977,7 +2028,7 @@ makeHistoryMenuItem[ Dynamic[ rows_ ], nbo_NotebookObject, chat_Association ] :=
19772028
{ {
19782029
Button[
19792030
$popOutButtonLabel,
1980-
popOutChatNB @ chat,
2031+
popOutChatNB[ chat, CurrentChatSettings @ nbo ],
19812032
Appearance -> "Suppressed"
19822033
],
19832034
Button[

0 commit comments

Comments
 (0)