Skip to content

Commit

Permalink
Merge pull request #1 from hjohnson12/bugfix/api-key
Browse files Browse the repository at this point in the history
Fix for updating OpenAI Api Key
  • Loading branch information
hjohnson12 committed Jun 21, 2024
2 parents 81ce9e5 + b0f2850 commit 3f6b054
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using ChatTailorAI.Shared.Services.Chat.LMStudio;
using ChatTailorAI.Shared.Base;
using ChatTailorAI.Shared.Models.Shared;
using ChatTailorAI.Shared.Events;

namespace ChatTailorAI.Shared.ViewModels.Pages
{
Expand Down Expand Up @@ -410,18 +411,16 @@ public ObservableCollection<PromptDto> Prompts
set => SetProperty(ref _prompts, value);
}

private string _password;

public string Password
public string OpenAIApiKey
{
get
{
return _userSettingsService.Get<string>(UserSettings.OpenAiApiKey);
}
set
{
// TODO: Try to avoid updating per character changed
_userSettingsService.Set(UserSettings.OpenAiApiKey, value);
_eventAggregator.PublishApiKeyChange(new ApiKeyChangedEventArgs { ApiKey = value, KeyType = ApiKeyType.OpenAI });
}
}

Expand All @@ -434,7 +433,7 @@ public string AzureSpeechApiKey
set
{
_userSettingsService.Set(UserSettings.AzureSpeechServicesKey, value);
_eventAggregator.PublishApiKeyChange(new ApiKeyChangedEventArgs { ApiKey = value, KeyType = Events.ApiKeyType.AzureSpeech });
_eventAggregator.PublishApiKeyChange(new ApiKeyChangedEventArgs { ApiKey = value, KeyType = ApiKeyType.AzureSpeech });
}
}

Expand Down Expand Up @@ -713,7 +712,7 @@ public void NavigateBack()
// Certain services lsiten for API key changes, since currently it only initializes
// the API key for a specific service on instantiation
// Eventually may just grab it each time before the request intead of an event
_eventAggregator.PublishApiKeyChange(new ApiKeyChangedEventArgs { ApiKey = Password, KeyType = Events.ApiKeyType.OpenAI });
_eventAggregator.PublishApiKeyChange(new ApiKeyChangedEventArgs { ApiKey = OpenAIApiKey, KeyType = Events.ApiKeyType.OpenAI });

_navigationService.NavigateBack();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ChatTailorAI.Uwp/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Identity
Name="17325HunterJohnson.ChatTailorAI"
Publisher="CN=7E9AA0BA-92B9-4274-B9BB-343DA3A9765C"
Version="2.3.0.0" />
Version="2.3.1.0" />

<mp:PhoneIdentity PhoneProductId="145d555a-796f-464e-88f3-ff3829795b85" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
2 changes: 1 addition & 1 deletion src/ChatTailorAI.Uwp/Views/Dialogs/AppUpdatedDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<StackPanel Orientation="Vertical">
<TextBlock
Margin="0,0,0,12"
Text="v2.3.0 ChatTailor AI:"
Text="v2.3.1 ChatTailor AI:"
TextDecorations="Underline"
TextWrapping="Wrap" />
<TextBlock
Expand Down
9 changes: 6 additions & 3 deletions src/ChatTailorAI.Uwp/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@
AutomationProperties.Name="Simple PasswordBox"
IsPasswordRevealButtonEnabled="False">
<i1:Interaction.Behaviors>
<behaviors:PasswordBoxBehavior Password="{Binding Password, Mode=TwoWay}" />
<behaviors:PasswordBoxBehavior Password="{Binding OpenAIApiKey, Mode=TwoWay}" />
<core:EventTriggerBehavior EventName="LostFocus">
<core:InvokeCommandAction Command="{x:Bind ViewModel.TextLostFocusCommand}" />
</core:EventTriggerBehavior>
</i1:Interaction.Behaviors>
</PasswordBox>
<CheckBox
Expand Down Expand Up @@ -1825,7 +1828,7 @@
Margin="12"
HorizontalAlignment="Right"
VerticalAlignment="Center">
v2.3.0
v2.3.1
</TextBlock>
</Grid>
</Grid>
Expand Down Expand Up @@ -1856,7 +1859,7 @@
Margin="0,12,0,0"
FontWeight="Bold"
IsTextSelectionEnabled="True"
Text="v2.3.0:"
Text="v2.3.1:"
TextDecorations="Underline"
TextWrapping="Wrap" />
<TextBlock
Expand Down
2 changes: 1 addition & 1 deletion src/ChatTailorAI.Uwp/Views/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void RevealModeCheckbox_Changed(object sender, RoutedEventArgs e)

private void apiKeyBox_PasswordChanged(object sender, RoutedEventArgs e)
{
ViewModel.Password = (sender as PasswordBox).Password;
ViewModel.OpenAIApiKey = (sender as PasswordBox).Password;
}

private async void Page_Loaded(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 3f6b054

Please sign in to comment.