Skip to content

Commit

Permalink
Pull request #86: Use kernel symbols instead of CurrentValue to deter…
Browse files Browse the repository at this point in the history
…mine cloud state

Merge in PAC/chatbook from bugfix/PreferencesContent_CloudConnect to main

* commit '5cd2adf63ff247292324d08451a928e3ab0caffb':
  Further simplify logic
  Put LLM subscription logic behind LLM functions
  Use kernel symbols instead of CurrentValue to determine cloud state
  • Loading branch information
Kevin Daily authored and rhennigan committed Nov 26, 2024
2 parents 3b9a3d3 + 5cd2adf commit f319547
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions Source/Chatbook/PreferencesContent.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,12 @@ servicesSettingsPanel0[ ] := Enclose[
"MouseClicked" :> ( Typeset`openQ = !Typeset`openQ ) ] },
Dynamic[ Typeset`openQ ],
BaselinePosition -> Baseline,
ImageSize -> Automatic ]
ImageSize -> Automatic ],
Initialization :> None, (* needed for Deinitialization to run *)
Deinitialization :>
If[ TrueQ[ Wolfram`LLMFunctions`Common`Private`$LastLLMKitRequest[ "ConnectionQ" ] ],
SessionSubmit @ Wolfram`LLMFunctions`Common`Private`teardownLLMListener[ ]
]
];

llmIcon = chatbookIcon[ "llmkit-dialog-sm", False ];
Expand All @@ -1175,8 +1180,7 @@ servicesSettingsPanel0[ ] := Enclose[
FontColor -> RGBColor[ "#333333" ],
FontFamily -> "Roboto",
FontSize -> 11 } ],
If[ !AssociationQ[ Wolfram`LLMFunctions`Common`$LLMKitInfo ], Wolfram`LLMFunctions`Common`UpdateLLMKitInfo[ ] ];
openLLMKitURL[ "learnMoreUrl" ],
Wolfram`LLMFunctions`Common`OpenLLMKitURL @ "Learn",
Appearance -> "Suppressed",
BaselinePosition -> Baseline,
Method -> "Queued",
Expand Down Expand Up @@ -1218,8 +1222,7 @@ makeLLMPanel[ ] :=
Framed[ tr[ "PreferencesContentLLMKitSubscribeButton" ], BaseStyle -> "ButtonRed1Normal", FrameMargins -> { { 17, 17 }, { 7, 7 } } ],
Framed[ tr[ "PreferencesContentLLMKitSubscribeButton" ], BaseStyle -> "ButtonRed1Hover", FrameMargins -> { { 17, 17 }, { 7, 7 } } ],
Framed[ tr[ "PreferencesContentLLMKitSubscribeButton" ], BaseStyle -> "ButtonRed1Pressed", FrameMargins -> { { 17, 17 }, { 7, 7 } } ] ],
If[ !AssociationQ[ Wolfram`LLMFunctions`Common`$LLMKitInfo ], Wolfram`LLMFunctions`Common`UpdateLLMKitInfo[ ] ];
openLLMKitURL[ "buyNowUrl" ],
Wolfram`LLMFunctions`Common`OpenLLMKitURL @ "Buy",
Appearance -> "Suppressed",
BaseStyle -> "DialogTextCommon",
BaselinePosition -> Baseline,
Expand All @@ -1238,7 +1241,7 @@ makeLLMPanel[ ] :=
Alignment -> { Left, Baseline },
BaseStyle -> { FontColor -> GrayLevel[ 0.2 ], FontSize -> 14 },
BaselinePosition -> { 1, 2 } ] },
Dynamic[ TrueQ[ CurrentValue[ "WolframCloudConnected" ] ] ],
Dynamic[ Wolfram`LLMFunctions`Common`CloudAuthenticatedQ[ ] ],
BaselinePosition -> Baseline,
ImageSize -> Automatic ];

Expand All @@ -1251,7 +1254,8 @@ makeLLMPanel[ ] :=
If[ CurrentValue[ "MouseOver" ],
RGBColor[ 0.3333333333333333, 0.6941176470588235, 0.8483660130718954 ],
RGBColor[ 0., 0.5411764705882353, 0.7725490196078432 ] ] ] ],
If[ CurrentValue[ "WolframCloudConnected" ] =!= "Pending", FEPrivate`WolframCloudSignIn[ ] ],
CloudConnect[ ];
If[ Wolfram`LLMFunctions`Common`CloudAuthenticatedQ[ ], Wolfram`LLMFunctions`Common`UpdateLLMKitInfo[ ] ],
Appearance -> "Suppressed",
BaseStyle -> "DialogTextCommon",
BaselinePosition -> Baseline,
Expand All @@ -1263,8 +1267,7 @@ makeLLMPanel[ ] :=
Style[
tr[ "PreferencesContentLLMKitEnabledManage" ],
FontColor -> Dynamic[ If[ CurrentValue[ "MouseOver" ], GrayLevel[ 0.2 ], GrayLevel[ 0.537254 ] ] ] ],
If[ !AssociationQ[ Wolfram`LLMFunctions`Common`$LLMKitInfo ], Wolfram`LLMFunctions`Common`UpdateLLMKitInfo[ ] ];
openLLMKitURL[ "manageSubscriptionUrl" ],
Wolfram`LLMFunctions`Common`OpenLLMKitURL @ "Manage",
Appearance -> "Suppressed",
BaseStyle -> "DialogTextCommon",
Method -> "Queued",
Expand Down Expand Up @@ -1318,7 +1321,7 @@ makeLLMPanel[ ] :=
},
Dynamic[
Which[
!TrueQ[ CurrentValue[ "WolframCloudConnected" ] ], "NotCloudConnected",
!Wolfram`LLMFunctions`Common`CloudAuthenticatedQ[ ], "NotCloudConnected",
TrueQ[ Wolfram`LLMFunctions`Common`$LLMKitInfo[ "userHasSubscription" ] ], "CloudConnectedAndSubscribed",
!AssociationQ[ Wolfram`LLMFunctions`Common`$LLMKitInfo ], "Loading",
True, "CloudConnectedButNotSubscribed" ] ],
Expand Down Expand Up @@ -1848,18 +1851,6 @@ clearConnectionCache[ service_String, delete: True|False ] := (

clearConnectionCache // endDefinition;

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

openLLMKitURL[ name_String ] :=
With[ { url = Wolfram`LLMFunctions`Common`$LLMKitInfo[ name ] },
If[ StringQ @ url, SystemOpen @ url ]
];

openLLMKitURL // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*UI Elements*)
Expand Down

0 comments on commit f319547

Please sign in to comment.