Skip to content

Commit

Permalink
支持设置 OpenAI 音频服务的代理地址 (#42)
Browse files Browse the repository at this point in the history
* 支持设置 OpenAI 音频服务的代理地址

* Update
  • Loading branch information
Richasy authored Jun 29, 2024
1 parent 2004d76 commit ea1ff5a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
Loaded="OnKeyBoxLoaded"
PasswordChanged="OnKeyBoxPasswordChanged" />
</community:SettingsCard>
<community:SettingsCard
x:Name="EndpointCard"
Description="{ext:Locale Name=EndpointDescription}"
Header="{ext:Locale Name=Endpoint}">
<TextBox
x:Name="EndpointBox"
Width="200"
AutomationProperties.Name="{ext:Locale Name=Endpoint}"
PlaceholderText="{ext:Locale Name=EndpointPlaceholder}"
TextChanged="OnEndpointBoxTextChanged" />
</community:SettingsCard>
<community:SettingsCard
x:Name="OrganizationCard"
Description="{ext:Locale Name=OptionalPlaceholder}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ protected override void OnViewModelChanged(DependencyPropertyChangedEventArgs e)
KeyBox.PlaceholderText = string.Format(ResourceToolkit.GetLocalizedString(Models.Constants.StringNames.AccessKeyPlaceholder), newVM.Name);
PredefinedCard.Description = string.Format(ResourceToolkit.GetLocalizedString(Models.Constants.StringNames.PredefinedModelsDescription), newVM.Name);

newVM.Config ??= new OpenAIClientConfig();
newVM.Config ??= new OpenAIClientConfig() { Endpoint = ProviderConstants.OpenAIApi };
if (newVM.Config is OpenAIClientConfig config && string.IsNullOrEmpty(config.Endpoint))
{
config.Endpoint = ProviderConstants.OpenAIApi;
}

ViewModel.CheckCurrentConfig();
}

private void OnKeyBoxLoaded(object sender, RoutedEventArgs e)
{
KeyBox.Password = ViewModel.Config?.Key ?? string.Empty;
EndpointBox.Text = (ViewModel.Config as ClientEndpointConfigBase)?.Endpoint ?? string.Empty;
OrganizationBox.Text = (ViewModel.Config as OpenAIClientConfig)?.OrganizationId ?? string.Empty;
KeyBox.Focus(FocusState.Programmatic);
}
Expand All @@ -47,6 +53,12 @@ private void OnKeyBoxPasswordChanged(object sender, RoutedEventArgs e)
ViewModel.CheckCurrentConfig();
}

private void OnEndpointBoxTextChanged(object sender, TextChangedEventArgs e)
{
((ClientEndpointConfigBase)ViewModel.Config).Endpoint = EndpointBox.Text;
ViewModel.CheckCurrentConfig();
}

private void OnOrganizationBoxTextChanged(object sender, TextChangedEventArgs e)
=> ((OpenAIClientConfig)ViewModel.Config).OrganizationId = OrganizationBox.Text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mc:Ignorable="d">

<StackPanel Spacing="8">
<local:AudioClientConfigSection x:Name="ClientConfig" ViewModel="{x:Bind ViewModel}" />
<local:AudioClientEndpointConfigSection x:Name="ClientConfig" ViewModel="{x:Bind ViewModel}" />
<TextBox
x:Name="OrganizationBox"
HorizontalAlignment="Stretch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ protected override void OnViewModelChanged(DependencyPropertyChangedEventArgs e)
}

newVM.Config ??= CreateCurrentConfig();
if (newVM.Config is OpenAIClientConfig config && string.IsNullOrEmpty(config.Endpoint))
{
config.Endpoint = ProviderConstants.OpenAIApi;
}

Debug.Assert(ViewModel.Config != null, "ViewModel.Config should not be null.");
ViewModel.CheckCurrentConfig();
}
Expand Down

0 comments on commit ea1ff5a

Please sign in to comment.