Skip to content

Commit f193ce4

Browse files
authored
Merge pull request #1325 from WolframResearch/bugfix/TemperatureDisplay
Update temperature and tool frequence sliders
2 parents aaf96ec + 5001edb commit f193ce4

File tree

2 files changed

+121
-65
lines changed

2 files changed

+121
-65
lines changed

Source/Chatbook/Menus.wl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ With[ { en = EvaluationNotebook[ ], mag = If[$OperatingSystem =!= "MacOSX", 0.75
9393
linkTrailFrame[ "Advanced Settings", aiPane = "Main" ],
9494
scrollablePane[
9595
Column[
96-
sideBarMenuItem[ #, generatedMenu, aiPane, modelPaneLabel, en ]& /@ Wolfram`Chatbook`UI`Private`createAdvancedSettingsMenu[ en ],
96+
sideBarMenuItem[ #, generatedMenu, aiPane, modelPaneLabel, en ]& /@ Wolfram`Chatbook`UI`Private`createAdvancedSettingsMenu[ en, sideBarCell ],
9797
Spacings -> { 0, 0 } ],
9898
mag, 90, en ] },
9999
ItemSize -> Automatic, Spacings -> { 0, 0 }, Alignment -> Left
@@ -1061,7 +1061,7 @@ submenuLabel // endDefinition;
10611061
AttachSubmenu // beginDefinition;
10621062

10631063
AttachSubmenu[ parentMenu_, expr_, menuTag_String ] := Enclose[
1064-
Module[ { parentInfo, root, pos, oPos, offsetX, offsetY, magnification, tags, attached },
1064+
Module[ { parentInfo, pos, oPos, offsetX, offsetY, magnification, tags, attached },
10651065

10661066
parentInfo = Replace[
10671067
Association @ CurrentValue[ parentMenu, TaggingRules ],

Source/Chatbook/UI.wl

Lines changed: 119 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -545,62 +545,71 @@ labeledCheckbox0[ Dynamic @ value_, update_Function, label_, enabled_, width_ ]
545545

546546
(*====================================*)
547547

548-
makeToolCallFrequencySlider[ obj_ ] :=
548+
makeToolCallFrequencySlider[ targetObj_, appContainer_ ] :=
549549
With[
550550
{
551-
initFrequency = currentChatSettings[ obj, "ToolCallFrequency" ]
551+
initFrequency = currentChatSettings[ targetObj, "ToolCallFrequency" ]
552552
},
553-
Module[ { checkboxUpdate, checkboxLabel, slider },
554-
checkboxUpdate =
555-
Function[
556-
If[ TrueQ[ # ],
557-
CurrentValue[ obj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = Inherited,
558-
CurrentValue[ obj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = 0.5
559-
]
560-
];
553+
Module[ { checkboxUpdate, checkboxLabel },
561554
checkboxLabel =
562555
Style[
563556
tr @ "UIAdvancedChooseAutomatically",
564557
"ChatMenuLabel",
565-
FontColor -> (Dynamic[ If[ CurrentValue[ "MouseOver" ], #1, #2 ] ]&[
558+
If[ MatchQ[ appContainer, _CellObject ],
559+
FontColor -> (Dynamic[ If[ CurrentValue[ "MouseOver" ], #1, #2 ] ]&[
560+
LightDarkSwitched[ RGBColor[ "#2FA7DC" ], RGBColor[ "#87D0F9" ] ],
561+
LightDarkSwitched[ GrayLevel[ 0.2 ], GrayLevel[ 0.9613 ] ]
562+
]),
563+
FontColor -> (Dynamic[ If[ CurrentValue[ "MouseOver" ], #1, #2 ] ]&[
566564
color @ "ChatMenuCheckboxLabelFontHover",
567565
color @ "ChatMenuCheckboxLabelFont"
568566
])
567+
]
569568
];
570-
slider = Pane[
571-
Grid[
572-
{
573-
{
574-
Style[ tr[ "Rare" ], "ChatMenuLabel", FontSize -> 12 ],
575-
DynamicModule[ { value },
576-
Slider[(* let the slider move freely, but only update the TaggingRules on mouse-up *)
577-
Dynamic[ value, { None, Temporary, (value = CurrentValue[ obj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = #) & } ],
578-
{ 0, 1, 0.01 },
579-
ImageSize -> { 100, Automatic },
580-
ImageMargins -> { { 0, 0 }, { 5, 5 } }
581-
],
582-
Initialization :> (value = Replace[ initFrequency, Except[ _?NumericQ ] -> 0.5 ])
583-
],
584-
Style[ tr[ "Often" ], "ChatMenuLabel", FontSize -> 12 ]
585-
}
586-
},
587-
Spacings -> { { 0, { 0.5 }, 0 }, 0 },
588-
Alignment -> { { Left, Center, Right }, Baseline }
589-
],
590-
ImageMargins -> 0,
591-
ImageSize -> { 170, Automatic }
592-
];
569+
593570
Pane[
594-
DynamicModule[ { value },
571+
DynamicModule[ { autoQ, value },
572+
checkboxUpdate =
573+
Function[
574+
If[ TrueQ[ # ],
575+
CurrentValue[ targetObj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = Inherited,
576+
CurrentValue[ targetObj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = value
577+
]
578+
];
579+
595580
PaneSelector[
596581
{
597-
True -> Column[ { labeledCheckbox0[ Dynamic @ value, checkboxUpdate, checkboxLabel, True, 155 ] }, Alignment -> Left ],
598-
False -> Column[ { slider, labeledCheckbox0[ Dynamic @ value, checkboxUpdate, checkboxLabel, True, 155 ] }, Alignment -> Left ]
582+
True -> Column[ { labeledCheckbox0[ Dynamic @ autoQ, checkboxUpdate, checkboxLabel, True, 155 ] }, Alignment -> Left ],
583+
False -> Column[
584+
{
585+
Pane[
586+
Grid[
587+
{
588+
{
589+
Style[ tr[ "Rare" ], "ChatMenuLabel", FontSize -> 12 ],
590+
Slider[(* let the slider move freely, but only update the TaggingRules on mouse-up *)
591+
Dynamic[ value, { None, Temporary, (value = CurrentValue[ targetObj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = #) & } ],
592+
{ 0, 1, 0.01 },
593+
ImageSize -> { 100, Automatic },
594+
ImageMargins -> { { 0, 0 }, { 5, 5 } }
595+
],
596+
Style[ tr[ "Often" ], "ChatMenuLabel", FontSize -> 12 ]
597+
}
598+
},
599+
Spacings -> { { 0, { 0.5 }, 0 }, 0 },
600+
Alignment -> { { Left, Center, Right }, Baseline }
601+
],
602+
ImageMargins -> 0,
603+
ImageSize -> { 170, Automatic }
604+
],
605+
labeledCheckbox0[ Dynamic @ autoQ, checkboxUpdate, checkboxLabel, True, 155 ]
606+
},
607+
Alignment -> Left ]
599608
},
600-
Dynamic @ value,
609+
Dynamic @ autoQ,
601610
ImageSize -> Automatic
602611
],
603-
Initialization :> (value = initFrequency === Automatic)
612+
Initialization :> (value = Replace[ initFrequency, Except[ _?NumericQ ] -> 0.5 ]; autoQ = initFrequency === Automatic)
604613
],
605614
ImageMargins -> { { 5, 0 }, { 5, 5 } }
606615
]
@@ -609,26 +618,73 @@ With[
609618

610619
SetFallthroughError[makeTemperatureSlider]
611620

612-
makeTemperatureSlider[ targetObj_ ] :=
613-
Pane[
614-
DynamicModule[ { value },
615-
Slider[
616-
Dynamic[ value, {
617-
None,
618-
Automatic,
619-
Function[
620-
value = #;
621-
CurrentValue[ targetObj, { TaggingRules, "ChatNotebookSettings", "Temperature" }] = # ] }
621+
makeTemperatureSlider[ targetObj_, appContainer_ ] :=
622+
With[
623+
{
624+
initTemperature = currentChatSettings[ targetObj, "Temperature" ]
625+
},
626+
Module[ { checkboxUpdate, checkboxLabel },
627+
checkboxLabel =
628+
Style[
629+
tr @ "UIAdvancedChooseAutomatically",
630+
"ChatMenuLabel",
631+
If[ MatchQ[ appContainer, _CellObject ],
632+
FontColor -> (Dynamic[ If[ CurrentValue[ "MouseOver" ], #1, #2 ] ]&[
633+
LightDarkSwitched[ RGBColor[ "#2FA7DC" ], RGBColor[ "#87D0F9" ] ],
634+
LightDarkSwitched[ GrayLevel[ 0.2 ], GrayLevel[ 0.9613 ] ]
635+
]),
636+
FontColor -> (Dynamic[ If[ CurrentValue[ "MouseOver" ], #1, #2 ] ]&[
637+
color @ "ChatMenuCheckboxLabelFontHover",
638+
color @ "ChatMenuCheckboxLabelFont"
639+
])
640+
]
641+
];
642+
643+
Pane[
644+
DynamicModule[ { autoQ, value },
645+
checkboxUpdate =
646+
Function[
647+
If[ TrueQ[ # ],
648+
CurrentValue[ targetObj, { TaggingRules, "ChatNotebookSettings", "Temperature" } ] = Inherited,
649+
CurrentValue[ targetObj, { TaggingRules, "ChatNotebookSettings", "Temperature" } ] = value
650+
]
651+
];
652+
653+
PaneSelector[
654+
{
655+
True -> Column[ { labeledCheckbox0[ Dynamic @ autoQ, checkboxUpdate, checkboxLabel, True, 155 ] }, Alignment -> Left ],
656+
False -> Column[
657+
{
658+
Pane[
659+
Slider[(* let the slider move freely, but only update the TaggingRules on mouse-up *)
660+
Dynamic[ value, {
661+
None,
662+
Automatic,
663+
Function[
664+
value = #;
665+
CurrentValue[ targetObj, { TaggingRules, "ChatNotebookSettings", "Temperature" }] = # ] }
666+
],
667+
{ 0, 2, 0.01 },
668+
ImageSize -> { 130, Automatic },
669+
ImageMargins -> {{5, 0}, {5, 5}},
670+
Appearance -> "Labeled"
671+
],
672+
ImageMargins -> 0,
673+
ImageSize -> { 170, Automatic }
674+
],
675+
labeledCheckbox0[ Dynamic @ autoQ, checkboxUpdate, checkboxLabel, True, 155 ]
676+
},
677+
Alignment -> Left
678+
]
679+
},
680+
Dynamic @ autoQ,
681+
ImageSize -> Automatic
682+
],
683+
Initialization :> (value = Replace[ initTemperature, Except[ _?NumericQ ] -> 0.5 ]; autoQ = initTemperature === Automatic)
622684
],
623-
{ 0, 2, 0.01 },
624-
ImageSize -> { 135, Automatic },
625-
ImageMargins -> {{5, 0}, {5, 5}},
626-
Appearance -> "Labeled"
627-
],
628-
Initialization :> (value = currentChatSettings[ targetObj, "Temperature" ])
629-
],
630-
ImageSize -> { 180, Automatic },
631-
BaseStyle -> { FontSize -> 12 }
685+
ImageMargins -> { { 5, 0 }, { 5, 5 } }
686+
]
687+
]
632688
]
633689

634690
(*=========================================*)
@@ -1142,7 +1198,7 @@ MakeChatDelimiterCellDingbat[ frameLabelCell_CellObject ] := With[ {
11421198
filterPersonas // beginDefinition;
11431199

11441200
filterPersonas[ targetObj_ ] :=
1145-
Module[ { personas, favorites },
1201+
Module[ { personas },
11461202
personas = GetPersonasAssociation[ "IncludeHidden" -> False ];
11471203

11481204
RaiseConfirmMatch[personas, <| (_String -> _Association)... |>];
@@ -1279,7 +1335,7 @@ Join[
12791335
"Label" -> tr @ "UIAdvancedSettings",
12801336
"Icon" -> getIcon @ "AdvancedSettings",
12811337
"MenuTag" -> "AdvancedSettings",
1282-
"Menu" :> createAdvancedSettingsMenu @ targetObj,
1338+
"Menu" :> createAdvancedSettingsMenu[ targetObj, None ],
12831339
"Width" -> 200
12841340
|>
12851341
}
@@ -1299,17 +1355,17 @@ getIcon[ name_ ] := Dynamic @ RawBoxes @ FEPrivate`FrontEndResource[ "ChatbookEx
12991355
(*createAdvancedSettingsMenu*)
13001356
createAdvancedSettingsMenu // beginDefinition;
13011357

1302-
createAdvancedSettingsMenu[ targetObj_ ] :=
1358+
createAdvancedSettingsMenu[ targetObj_, appContainer_ ] :=
13031359
With[
13041360
{
13051361
roleValue = Replace[ currentValueOrigin[ targetObj, { TaggingRules, "ChatNotebookSettings", "Role" } ], { source_, Inherited } :> { source, "User" } ]
13061362
},
13071363
Join[
13081364
{
13091365
<| "Type" -> "Header", "Label" -> tr @ "UIAdvancedTemperature" |>,
1310-
<| "Type" -> "Custom", "Content" -> makeTemperatureSlider @ targetObj |>,
1366+
<| "Type" -> "Custom", "Content" -> makeTemperatureSlider[ targetObj, appContainer ] |>,
13111367
<| "Type" -> "Header", "Label" -> tr @ "UIAdvancedToolCallFrequency" |>,
1312-
<| "Type" -> "Custom", "Content" -> makeToolCallFrequencySlider @ targetObj |>,
1368+
<| "Type" -> "Custom", "Content" -> makeToolCallFrequencySlider[ targetObj, appContainer ] |>,
13131369
<| "Type" -> "Header", "Label" -> tr @ "UIAdvancedRoles" |>
13141370
},
13151371
Map[

0 commit comments

Comments
 (0)