Skip to content

Commit

Permalink
Update the cloud toolbar to handle multiple services
Browse files Browse the repository at this point in the history
  • Loading branch information
rhennigan committed Dec 15, 2023
1 parent 05d56aa commit a2c7fe2
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 5 deletions.
2 changes: 1 addition & 1 deletion PacletInfo.wl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PacletObject[ <|
"Name" -> "Wolfram/Chatbook",
"PublisherID" -> "Wolfram",
"Version" -> "1.3.4",
"WolframVersion" -> "13.3+",
"WolframVersion" -> "14.0+",
"Description" -> "Wolfram Notebooks + LLMs",
"License" -> "MIT",
"Creator" -> "Connor Gray, Theodore Gray, Richard Hennigan",
Expand Down
111 changes: 110 additions & 1 deletion Source/Chatbook/CloudToolbar.wl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Needs[ "Wolfram`Chatbook`Common`" ];
Needs[ "Wolfram`Chatbook`Dialogs`" ];
Needs[ "Wolfram`Chatbook`Dynamics`" ];
Needs[ "Wolfram`Chatbook`PreferencesContent`" ];
Needs[ "Wolfram`Chatbook`Services`" ];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
Expand Down Expand Up @@ -42,7 +43,7 @@ makeChatCloudDockedCellContents[ ] :=
Item[ $cloudChatBanner, Alignment -> Left ],
Item[ "", ItemSize -> Fit ],
makePersonaSelector[ ],
makeModelSelector[ ]
cloudModelSelector[ ]
}
},
Alignment -> { Left, Baseline },
Expand All @@ -62,6 +63,114 @@ makeChatCloudDockedCellContents[ ] :=

makeChatCloudDockedCellContents // endDefinition;

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

cloudModelSelector[ ] :=
DynamicModule[ { serviceSelector, modelSelector },

serviceSelector = PopupMenu[
Dynamic[
Replace[
CurrentValue[ EvaluationNotebook[ ], { TaggingRules, "ChatNotebookSettings", "Model" } ],
{
_String|Inherited :> "OpenAI",
KeyValuePattern[ "Service" -> service_String ] :> service,
_ :> Set[
CurrentValue[
EvaluationNotebook[ ],
{ TaggingRules, "ChatNotebookSettings", "Model" }
],
$DefaultModel
][ "Service" ]
}
],
Function[
CurrentValue[
EvaluationNotebook[ ],
{ TaggingRules, "ChatNotebookSettings", "Model", "Service" }
] = #1;

CurrentValue[
EvaluationNotebook[ ],
{ TaggingRules, "ChatNotebookSettings", "Model", "Name" }
] = Automatic;

cloudModelNameSelector[ Dynamic @ modelSelector, #1 ]
]
],
KeyValueMap[
#1 -> Row @ { inlineTemplateBoxes[ #2[ "Icon" ] ], Spacer[ 1 ], #2[ "Service" ] } &,
$availableServices
]
];

cloudModelNameSelector[
Dynamic @ modelSelector,
Replace[
CurrentValue[ EvaluationNotebook[ ], { TaggingRules, "ChatNotebookSettings", "Model" } ],
{
_String|Inherited :> "OpenAI",
KeyValuePattern[ "Service" -> service_String ] :> service,
_ :> Set[
CurrentValue[ EvaluationNotebook[ ], { TaggingRules, "ChatNotebookSettings", "Model" } ],
$DefaultModel
][ "Service" ]
}
]
];

Row @ {
"LLM Service: ", serviceSelector,
Spacer[ 5 ],
"Model: ", Dynamic @ modelSelector
}
];

cloudModelSelector // endDefinition;

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

cloudModelNameSelector[ Dynamic[ modelSelector_ ], service_String ] :=
modelSelector = DynamicModule[ { display, models },
display = ProgressIndicator[ Appearance -> "Percolate" ];
Dynamic[ display ],
Initialization :> (
models = getServiceModelList @ service;
If[ SameQ[
CurrentValue[ EvaluationNotebook[ ], { TaggingRules, "ChatNotebookSettings", "Model", "Name" } ],
Automatic
],
CurrentValue[ EvaluationNotebook[ ], { TaggingRules, "ChatNotebookSettings", "Model", "Name" } ] =
First[ models, <| "Name" -> Automatic |> ][ "Name" ]
];

display = PopupMenu[
Dynamic[
Replace[
CurrentChatSettings[ EvaluationNotebook[ ], "Model" ],
{ KeyValuePattern[ "Name" -> model_String ] :> model, _ :> Automatic }
],
Function[
CurrentValue[
EvaluationNotebook[ ],
{ TaggingRules, "ChatNotebookSettings", "Model", "Name" }
] = #1
]
],
(#Name -> #DisplayName &) /@ models
]
),
SynchronousInitialization -> False
];

cloudModelNameSelector // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Notebook Type Label*)
Expand Down
10 changes: 9 additions & 1 deletion Source/Chatbook/PreferencesContent.wl
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,15 @@ makePersonaSelector0[ personas: { (_String -> _).. } ] :=
"Persona:",
Spacer[ 3 ],
PopupMenu[
scopedDynamic @ CurrentChatSettings[ $preferencesScope, "LLMEvaluator" ],
scopedDynamic[
CurrentChatSettings[ $preferencesScope, "LLMEvaluator" ],
Function[
CurrentValue[
$preferencesScope,
{ TaggingRules, "ChatNotebookSettings", "LLMEvaluator" }
] = #1
]
],
personas
]
},
Expand Down
3 changes: 2 additions & 1 deletion Source/Chatbook/Prompting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ becomes ``Styled message``.";

$basePromptComponents[ "SpecialURI" ] = "\
* You will occasionally see markdown links with special URI schemes, e.g. ![label](scheme://content-id) that represent \
interactive interface elements. You can use these in your responses to display the same elements to the user.";
interactive interface elements. You can use these in your responses to display the same elements to the user, but they \
must be formatted as image links (include the '!' at the beginning). If you do not include the '!', the link will fail.";

$basePromptComponents[ "SpecialURIAudio" ] = "\
* ![label](audio://content-id) represents an interactive audio player.";
Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/Sandbox.wl
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ initializeExpressions[ flat: HoldComplete @ Association @ OrderlessPatternSequen
ReplacePart[ flat, Thread[ pos -> Extract[ flat, pos ] ] ]
];

initializeExpressions[ failed: HoldComplete[ _Failure ] ] :=
initializeExpressions[ failed: HoldComplete[ _Failure|$Failed|$Aborted ] ] :=
failed;

initializeExpressions // endDefinition;
Expand Down

0 comments on commit a2c7fe2

Please sign in to comment.