Skip to content

Commit

Permalink
Move cloud toolbar content to separate file and use new preferences c…
Browse files Browse the repository at this point in the history
…ontrols
  • Loading branch information
rhennigan committed Dec 14, 2023
1 parent 5872fd3 commit d14ceec
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 143 deletions.
107 changes: 107 additions & 0 deletions Source/Chatbook/CloudToolbar.wl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
(* ::Section::Closed:: *)
(*Package Header*)
BeginPackage[ "Wolfram`Chatbook`CloudToolbar`" ];

HoldComplete[
`makeChatCloudDockedCellContents;
];

Begin[ "`Private`" ];

Needs[ "Wolfram`Chatbook`" ];
Needs[ "Wolfram`Chatbook`Common`" ];
Needs[ "Wolfram`Chatbook`Dialogs`" ];
Needs[ "Wolfram`Chatbook`Dynamics`" ];
Needs[ "Wolfram`Chatbook`PreferencesContent`" ];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Configuration*)
$notebookTypeLabelOptions = Sequence[
FontColor -> RGBColor[ "#333333" ],
FontFamily -> "Source Sans Pro",
FontSize -> 16,
FontWeight -> "DemiBold"
];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Docked Cell Contents*)

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

makeChatCloudDockedCellContents[ ] :=
Block[ { $preferencesScope := EvaluationNotebook[ ] },
Grid[
{
{
Item[ $cloudChatBanner, Alignment -> Left ],
Item[ "", ItemSize -> Fit ],
makePersonaSelector[ ],
makeModelSelector[ ]
}
},
Dividers -> { { False, False, False, True }, False },
Spacings -> { 2, 0 },
BaseStyle -> { "Text", FontSize -> 14, FontColor -> GrayLevel[ 0.4 ] },
FrameStyle -> Directive[ Thickness[ 2 ], GrayLevel[ 0.9 ] ]
]
];

makeChatCloudDockedCellContents // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Notebook Type Label*)

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*$cloudChatBanner*)
$cloudChatBanner := $cloudChatBanner = cvExpand @ PaneSelector[
{ True -> $chatDrivenNotebookLabel, False -> $chatEnabledNotebookLabel },
Dynamic @ TrueQ @ cv[ EvaluationNotebook[ ], "ChatDrivenNotebook" ],
ImageSize -> Automatic
];

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*$chatDrivenNotebookLabel*)
$chatDrivenNotebookLabel := Grid[
{
{
"",
chatbookIcon[ "ChatDrivenNotebookIcon", False ],
Style[ "Chat-Driven Notebook", $notebookTypeLabelOptions ]
}
},
Alignment -> { Automatic, Center },
Spacings -> 0.5
];

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*$chatEnabledNotebookLabel*)
$chatEnabledNotebookLabel := Grid[
{
{
"",
chatbookIcon[ "ChatEnabledNotebookIcon", False ],
Style[ "Chat-Enabled Notebook", $notebookTypeLabelOptions ]
}
},
Alignment -> { Automatic, Center },
Spacings -> 0.5
];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Package Footer*)
If[ Wolfram`ChatbookInternal`$BuildingMX,
$cloudChatBanner;
];

End[ ];
EndPackage[ ];
1 change: 1 addition & 0 deletions Source/Chatbook/Dialogs.wl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ redDialogButtonLabel // endDefinition;
cvExpand // beginDefinition;
cvExpand // Attributes = { HoldFirst };
cvExpand[ expr_ ] := expr /. $cvRules;
cvExpand /: SetDelayed[ lhs_, cvExpand[ rhs_ ] ] := Unevaluated @ SetDelayed[ lhs, rhs ] /. $cvRules;
cvExpand // endDefinition;

(* ::**************************************************************************************************************:: *)
Expand Down
1 change: 1 addition & 0 deletions Source/Chatbook/Main.wl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Block[ { $ContextPath },
Get[ "Wolfram`Chatbook`ToolManager`" ];
Get[ "Wolfram`Chatbook`PersonaManager`" ];
Get[ "Wolfram`Chatbook`ChatHistory`" ];
Get[ "Wolfram`Chatbook`CloudToolbar`" ];
];

(* ::**************************************************************************************************************:: *)
Expand Down
145 changes: 2 additions & 143 deletions Source/Chatbook/UI.wl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Begin["`Private`"]

Needs[ "Wolfram`Chatbook`" ];
Needs[ "Wolfram`Chatbook`Actions`" ];
Needs[ "Wolfram`Chatbook`CloudToolbar`" ];
Needs[ "Wolfram`Chatbook`Common`" ];
Needs[ "Wolfram`Chatbook`Dynamics`" ];
Needs[ "Wolfram`Chatbook`Errors`" ];
Expand Down Expand Up @@ -69,108 +70,7 @@ $chatMenuWidth = 220;
(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*MakeChatCloudDockedCellContents*)
MakeChatCloudDockedCellContents[] := Grid[
{{
Item[$cloudChatBanner, Alignment -> Left],
Item["", ItemSize -> Fit],
Row[{"Persona", Spacer[5], trackedDynamic[$cloudPersonaChooser, "Personas"]}],
Row[{"Model", Spacer[5], trackedDynamic[$cloudModelChooser, "Models"]}]
}},
Dividers -> {{False, False, False, True}, False},
Spacings -> {2, 0},
BaseStyle -> {"Text", FontSize -> 14, FontColor -> GrayLevel[0.4]},
FrameStyle -> Directive[Thickness[2], GrayLevel[0.9]]
]

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*$cloudPersonaChooser*)
$cloudPersonaChooser := PopupMenu[
Dynamic[
Replace[
CurrentValue[EvaluationNotebook[], {TaggingRules, "ChatNotebookSettings", "LLMEvaluator"}],
Inherited :> Lookup[$defaultChatSettings, "LLMEvaluator", "CodeAssistant"]
],
Function[CurrentValue[EvaluationNotebook[], {TaggingRules, "ChatNotebookSettings", "LLMEvaluator"}] = #]
],
KeyValueMap[
Function[{key, as}, key -> Grid[{{resizeMenuIcon[getPersonaMenuIcon[as]], personaDisplayName[key, as]}}]],
GetCachedPersonaData[]
],
ImageSize -> {Automatic, 30},
Alignment -> {Left, Baseline},
BaseStyle -> {FontSize -> 12}
]

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*$cloudModelChooser*)
$cloudModelChooser := PopupMenu[
Dynamic[
Replace[
CurrentValue[EvaluationNotebook[], {TaggingRules, "ChatNotebookSettings", "Model"}],
Inherited :> Lookup[$defaultChatSettings, "Model", "gpt-3.5-turbo"]
],
Function[CurrentValue[EvaluationNotebook[], {TaggingRules, "ChatNotebookSettings", "Model"}] = #]
],
KeyValueMap[
{modelName, settings} |-> (
modelName -> Grid[{{getModelMenuIcon[settings], modelDisplayName[modelName]}}]
),
(* FIXME: use the new system *)
getModelsMenuItems[]
],
ImageSize -> {Automatic, 30},
Alignment -> {Left, Baseline},
BaseStyle -> {FontSize -> 12}
]

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*$cloudChatBanner*)
$cloudChatBanner := PaneSelector[
{
True -> Grid[
{
{
"",
chatbookIcon[ "ChatDrivenNotebookIcon", False ],
Style[
"Chat-Driven Notebook",
FontColor -> RGBColor[ "#333333" ],
FontFamily -> "Source Sans Pro",
FontSize -> 16,
FontWeight -> "DemiBold"
]
}
},
Alignment -> { Automatic, Center },
Spacings -> 0.5
],
False -> Grid[
{
{
"",
chatbookIcon[ "ChatEnabledNotebookIcon", False ],
Style[
"Chat-Enabled Notebook",
FontColor -> RGBColor[ "#333333" ],
FontFamily -> "Source Sans Pro",
FontSize -> 16,
FontWeight -> "DemiBold"
]
}
},
Alignment -> { Automatic, Center },
Spacings -> 0.5
]
},
Dynamic @ TrueQ @ CurrentValue[
EvaluationNotebook[ ],
{ TaggingRules, "ChatNotebookSettings", "ChatDrivenNotebook" }
],
ImageSize -> Automatic
]
MakeChatCloudDockedCellContents[] := makeChatCloudDockedCellContents[ ];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
Expand Down Expand Up @@ -399,47 +299,6 @@ labeledCheckbox[value_, label_, enabled_ : Automatic] :=

(*====================================*)

makeToolCallFrequencySlider[ obj_ ] := Pane[
Grid[
{
{
labeledCheckbox[
Dynamic[
currentChatSettings[ obj, "ToolCallFrequency" ] === Automatic,
Function[
If[ TrueQ[ # ],
CurrentValue[ obj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = Inherited,
CurrentValue[ obj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = 0.5
]
]
],
Style[ "Choose automatically", "ChatMenuLabel" ]
]
},
{
Pane[
Slider[
Dynamic[
Replace[ currentChatSettings[ obj, "ToolCallFrequency" ], Automatic -> 0.5 ],
(CurrentValue[ obj, { TaggingRules, "ChatNotebookSettings", "ToolCallFrequency" } ] = #) &
],
{ 0, 1, 0.01 },
(* Enabled -> Dynamic[ currentChatSettings[ obj, "ToolCallFrequency" ] =!= Automatic ], *)
ImageSize -> { 150, Automatic },
ImageMargins -> { { 5, 0 }, { 5, 5 } }
],
ImageSize -> { 180, Automatic },
BaseStyle -> { FontSize -> 12 }
],
SpanFromLeft
}
},
Alignment -> Left,
Spacings -> { Automatic, 0 }
],
ImageMargins -> { { 5, 0 }, { 5, 5 } }
];

makeToolCallFrequencySlider[ obj_ ] :=
Module[ { checkbox, slider },
checkbox = labeledCheckbox[
Expand Down

0 comments on commit d14ceec

Please sign in to comment.