Skip to content

Commit

Permalink
Fixed OpenAIApiKey not being updated properly on first time entry
Browse files Browse the repository at this point in the history
  • Loading branch information
hjohnson12 committed Jun 20, 2024
1 parent ca6e97c commit cdd21c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 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
5 changes: 4 additions & 1 deletion 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
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 cdd21c8

Please sign in to comment.