Skip to content

Commit

Permalink
Restored "OpenAIAPICompletionURL" preferences setting for 13.3 users
Browse files Browse the repository at this point in the history
  • Loading branch information
rhennigan committed Dec 15, 2023
1 parent a9ec5f6 commit 9ba1198
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
50 changes: 44 additions & 6 deletions Source/Chatbook/PreferencesContent.wl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ createNotebookSettingsPanel // endDefinition;
makeDefaultSettingsContent // beginDefinition;

makeDefaultSettingsContent[ ] := Enclose[
Module[ { assistanceCheckbox, personaSelector, modelSelector, temperatureInput },
Module[ { assistanceCheckbox, personaSelector, modelSelector, temperatureInput, openAICompletionURLInput },
(* Checkbox to enable automatic assistance for normal shift-enter evaluations: *)
assistanceCheckbox = ConfirmMatch[ makeAssistanceCheckbox[ ], _Style, "AssistanceCheckbox" ];
(* The personaSelector is a pop-up menu for selecting the default persona: *)
Expand All @@ -319,14 +319,21 @@ makeDefaultSettingsContent[ ] := Enclose[
modelSelector = ConfirmMatch[ makeModelSelector[ ], _Dynamic, "ModelSelector" ];
(* The temperatureInput is an input field for setting the default 'temperature' for responses: *)
temperatureInput = ConfirmMatch[ makeTemperatureInput[ ], _Style, "TemperatureInput" ];
(* The openAICompletionURLInput is an input field for setting URL used for API calls to OpenAI: *)
openAICompletionURLInput = ConfirmMatch[
makeOpenAICompletionURLInput[ ],
_Style|Nothing, (* Returns Nothing if we're relying on LLMServices for API requests *)
"OpenAICompletionURLInput"
];

(* Assemble the persona selector, model selector, and temperature slider into a grid layout: *)
Grid[
{
{ assistanceCheckbox },
{ personaSelector },
{ modelSelector },
{ temperatureInput }
List /@ {
assistanceCheckbox,
personaSelector,
modelSelector,
temperatureInput,
openAICompletionURLInput
},
Alignment -> { Left, Baseline },
Spacings -> { 0, 0.7 }
Expand Down Expand Up @@ -749,6 +756,37 @@ makeTemperatureInput[ ] := highlightControl[

makeTemperatureInput // endDefinition;

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

makeOpenAICompletionURLInput[ ] :=
makeOpenAICompletionURLInput @ $useLLMServices;

makeOpenAICompletionURLInput[ True ] :=
Nothing;

makeOpenAICompletionURLInput[ False ] := highlightControl[
prefsInputField[
"Chat Completion URL:",
scopedDynamic[
(* cSpell: ignore AIAPI *)
CurrentChatSettings[ $preferencesScope, "OpenAIAPICompletionURL" ],
{
None,
If[ StringQ @ #, CurrentChatSettings[ $preferencesScope, "OpenAIAPICompletionURL" ] = # ] &
}
],
String,
ImageSize -> { 200, Automatic }
],
"Notebooks",
"OpenAIAPICompletionURL"
];

makeOpenAICompletionURLInput // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*makeInterfaceContent*)
Expand Down
9 changes: 5 additions & 4 deletions Source/Chatbook/SendChat.wl
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,13 @@ sendChat // endDefinition;
(*makeHTTPRequest*)
makeHTTPRequest // beginDefinition;

(* cSpell: ignore ENDTOOLCALL *)
(* cSpell: ignore ENDTOOLCALL, AIAPI *)
makeHTTPRequest[ settings_Association? AssociationQ, messages: { __Association } ] :=
Enclose @ Module[ { key, stream, model, tokens, temperature, topP, freqPenalty, presPenalty, data, body, apiCompletionURL },
Enclose @ Module[
{ key, stream, model, tokens, temperature, topP, freqPenalty, presPenalty, data, body, apiCompletionURL },

key = ConfirmBy[ Lookup[ settings, "OpenAIKey" ], StringQ ];
stream = True;
key = ConfirmBy[ Lookup[ settings, "OpenAIKey" ], StringQ ];
stream = True;
apiCompletionURL = ConfirmBy[ Lookup[ settings, "OpenAIAPICompletionURL" ], StringQ ];

(* model parameters *)
Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/Services.wl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ $availableServices := getAvailableServices[ ];
(*getAvailableServices*)
getAvailableServices // beginDefinition;
getAvailableServices[ ] := getAvailableServices @ $useLLMServices;
getAvailableServices[ False ] := $fallBackServices;
getAvailableServices[ False ] := getAvailableServices0 @ $fallBackServices;
getAvailableServices[ True ] := getAvailableServices0[ ];
getAvailableServices // endDefinition;

Expand Down

0 comments on commit 9ba1198

Please sign in to comment.