Skip to content

Commit

Permalink
Added the function to ask questions to ChatGPT in case of errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
yt3trees committed Nov 19, 2023
1 parent 5731d6f commit 2150961
Show file tree
Hide file tree
Showing 18 changed files with 956 additions and 42 deletions.
90 changes: 90 additions & 0 deletions msbuild-gui/APISettings.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<Window
x:Class="msbuild_gui.APISettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:app="clr-namespace:msbuild_gui"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:msbuild_gui"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:msbuild_gui.Properties"
xmlns:sys="clr-namespace:System;assembly=netstandard"
xmlns:ui="http://schemas.modernwpf.com/2019"
Title="{Binding Resources.OpenAIAPISetting, Source={x:Static app:ResourceService.Current}, Mode=OneWay}"
Width="350"
Height="400"
ui:WindowHelper.UseModernWindowStyle="True"
Closing="Window_Closing"
KeyDown="Window_KeyDown"
ResizeMode="NoResize"
ShowInTaskbar="False"
WindowStartupLocation="CenterScreen"
WindowStyle="ToolWindow"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="5*" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Margin="10,0,10,0">
<Label HorizontalAlignment="Left" Content="Provider" />
<ComboBox
x:Name="ProviderComboBox"
Width="120"
HorizontalAlignment="Left"
VerticalAlignment="Top"
SelectionChanged="ProviderComboBox_SelectionChanged">
<ComboBoxItem Content="OpenAI" />
<ComboBoxItem Content="Azure" />
</ComboBox>
<Label HorizontalAlignment="Left" Content="API Key" />
<PasswordBox
x:Name="APIKeyPasswordbox"
MinWidth="200"
VerticalAlignment="Top"
PasswordChar="*">
<PasswordBox.Background>
<SolidColorBrush Opacity="0.5" Color="{DynamicResource SystemChromeLowColor}" />
</PasswordBox.Background>
</PasswordBox>
<Label HorizontalAlignment="Left" Content="Model" />
<ComboBox
x:Name="ModelComboBox"
MinWidth="140"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
<Label HorizontalAlignment="Left" Content="Deployment-ID" />
<TextBox
x:Name="DeploymentIdTextbox"
MinWidth="200"
VerticalAlignment="Top">
<TextBox.Background>
<SolidColorBrush Opacity="0.5" Color="{DynamicResource SystemChromeLowColor}" />
</TextBox.Background>
</TextBox>
<Label HorizontalAlignment="Left" Content="BaseDomain" />
<TextBox
x:Name="BaseDomainTextbox"
MinWidth="200"
VerticalAlignment="Top"
ui:ControlHelper.PlaceholderText="">
<TextBox.Background>
<SolidColorBrush Opacity="0.5" Color="{DynamicResource SystemChromeLowColor}" />
</TextBox.Background>
</TextBox>
</StackPanel>
<Button
x:Name="OkButton"
Grid.Row="2"
Width="120"
Height="30"
MinWidth="60"
Margin="0,0,10,10"
Padding="0,0,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Click="OkButton_Click"
Content="_OK"
IsDefault="True"
Style="{StaticResource AccentButtonStyle}" />
</Grid>
</Window>
84 changes: 84 additions & 0 deletions msbuild-gui/APISettings.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using ModernWpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace msbuild_gui
{
/// <summary>
/// ColorSettings.xaml の相互作用ロジック
/// </summary>
public partial class APISettings : Window
{
public static bool OkFlg { get; set; }

public APISettings()
{
InitializeComponent();
this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
OkFlg = false;

ProviderComboBox.Text = Properties.Settings.Default.Provider;
APIKeyPasswordbox.Password = Properties.Settings.Default.APIKey;
DeploymentIdTextbox.Text = Properties.Settings.Default.AzDeploymentId;
BaseDomainTextbox.Text = Properties.Settings.Default.AzBaseDomain;
string[] modelList = Properties.Settings.Default.ModelList.Split(',');
foreach(string model in modelList)
{
ModelComboBox.Items.Add(model);
}
ModelComboBox.Text = Properties.Settings.Default.Model;
}
/// <summary>
/// 閉じるボタン押下時
/// </summary>
protected virtual void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (OkFlg == false)
{
}
}

private void OkButton_Click(object sender, RoutedEventArgs e)
{
OkFlg = true;

Properties.Settings.Default.Provider = ProviderComboBox.Text;
Properties.Settings.Default.APIKey = APIKeyPasswordbox.Password;
Properties.Settings.Default.Model = ModelComboBox.Text;
Properties.Settings.Default.AzDeploymentId = DeploymentIdTextbox.Text;
Properties.Settings.Default.AzBaseDomain = BaseDomainTextbox.Text;
Properties.Settings.Default.Save();
this.Close();
}
private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
}

private void ProviderComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ProviderComboBox.SelectedItem == null) return;
if (ProviderComboBox.SelectedItem.ToString() == "System.Windows.Controls.ComboBoxItem: OpenAI")
{
ModelComboBox.IsEnabled = true;
DeploymentIdTextbox.IsEnabled = false;
BaseDomainTextbox.IsEnabled = false;
}
else
{
ModelComboBox.IsEnabled = false;
DeploymentIdTextbox.IsEnabled = true;
BaseDomainTextbox.IsEnabled = true;
}
}
}
}
33 changes: 33 additions & 0 deletions msbuild-gui/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="msbuild_gui.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<msbuild_gui.Properties.Settings>
<setting name="APIKey" serializeAs="String">
<value />
</setting>
<setting name="Provider" serializeAs="String">
<value>Azure</value>
</setting>
<setting name="Model" serializeAs="String">
<value />
</setting>
<setting name="ModelList" serializeAs="String">
<value>gpt-3.5-turbo,gpt-3.5-turbo-16k,gpt-3.5-turbo-16k-instruct,gpt-3.5-turbo-1106,gpt-4,gpt-4-0613,gpt-4-1106-preview,gpt-4-vision-preview</value>
</setting>
<setting name="AzDeploymentId" serializeAs="String">
<value />
</setting>
<setting name="AzBaseDomain" serializeAs="String">
<value />
</setting>
<setting name="UpgradeRequired" serializeAs="String">
<value>True</value>
</setting>
</msbuild_gui.Properties.Settings>
</userSettings>
</configuration>
26 changes: 14 additions & 12 deletions msbuild-gui/App.xaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<Application x:Class="msbuild_gui.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:msbuild_gui"
StartupUri="MainWindow.xaml"
xmlns:ui="http://schemas.modernwpf.com/2019"
Startup="Application_Startup"
Exit="Application_Exit"
xmlns:properties="clr-namespace:msbuild_gui.Properties"
ShutdownMode="OnMainWindowClose"><!-- 小ウィンドウを閉じる -->
<Application
x:Class="msbuild_gui.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:msbuild_gui"
xmlns:properties="clr-namespace:msbuild_gui.Properties"
xmlns:ui="http://schemas.modernwpf.com/2019"
Exit="Application_Exit"
ShutdownMode="OnMainWindowClose"
Startup="Application_Startup"
StartupUri="MainWindow.xaml">
<!-- 小ウィンドウを閉じる -->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemeResources />
<ui:XamlControlsResources />
<!-- Other merged dictionaries here -->
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
<!-- Other app resources here -->
</ResourceDictionary>
</Application.Resources>
</Application>
49 changes: 49 additions & 0 deletions msbuild-gui/AskAI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Orchestration;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace msbuild_gui
{
internal class AskAI
{
/// <summary>
/// https://learn.microsoft.com/en-us/semantic-kernel/prompt-engineering/your-first-prompt
/// </summary>
public static async Task<string> ExecutePlugin(string errorMessage)
{
var kernel = CreateKernelWithAuthentication();

IDictionary<string, ISKFunction> plugins = kernel.ImportSemanticFunctionsFromDirectory(@"Plugins", "SemanticPlugins");

ContextVariables variables = new ContextVariables();
variables.Set("errorMessage", errorMessage);
variables.Set("language", MainWindow.Projects.Language);

var context = await kernel.RunAsync(variables, plugins["ErrorAnalysis"]);
return context.ToString();
}
private static IKernel CreateKernelWithAuthentication()
{
var builder = new KernelBuilder();

switch (Properties.Settings.Default.Provider)
{
case "Azure":
return builder.WithAzureOpenAIChatCompletionService(
apiKey: Properties.Settings.Default.APIKey,
deploymentName: Properties.Settings.Default.AzDeploymentId,
endpoint: Properties.Settings.Default.AzBaseDomain
).Build();
case "OpenAI":
return builder.WithOpenAIChatCompletionService(
apiKey: Properties.Settings.Default.APIKey,
modelId: Properties.Settings.Default.Model
).Build();
default:
throw new InvalidOperationException("Unsupported provider");
}
}
}
}
Loading

0 comments on commit 2150961

Please sign in to comment.