500 lines
14 KiB
C#
500 lines
14 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Effects;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace AxCopilot.Views;
|
|
|
|
internal sealed class ModelRegistrationDialog : Window
|
|
{
|
|
private readonly TextBox _aliasBox;
|
|
|
|
private readonly TextBox _modelBox;
|
|
|
|
private readonly TextBox _endpointBox;
|
|
|
|
private readonly TextBox _apiKeyBox;
|
|
|
|
private readonly ComboBox _authTypeBox;
|
|
|
|
private readonly StackPanel _cp4dPanel;
|
|
|
|
private readonly TextBox _cp4dUrlBox;
|
|
|
|
private readonly TextBox _cp4dUsernameBox;
|
|
|
|
private readonly PasswordBox _cp4dPasswordBox;
|
|
|
|
public string ModelAlias => _aliasBox.Text.Trim();
|
|
|
|
public string ModelName => _modelBox.Text.Trim();
|
|
|
|
public string Endpoint => _endpointBox.Text.Trim();
|
|
|
|
public string ApiKey => _apiKeyBox.Text.Trim();
|
|
|
|
public string AuthType => (_authTypeBox.SelectedItem as ComboBoxItem)?.Tag?.ToString() ?? "bearer";
|
|
|
|
public string Cp4dUrl => _cp4dUrlBox.Text.Trim();
|
|
|
|
public string Cp4dUsername => _cp4dUsernameBox.Text.Trim();
|
|
|
|
public string Cp4dPassword => _cp4dPasswordBox.Password.Trim();
|
|
|
|
public ModelRegistrationDialog(string service, string existingAlias = "", string existingModel = "", string existingEndpoint = "", string existingApiKey = "", string existingAuthType = "bearer", string existingCp4dUrl = "", string existingCp4dUsername = "", string existingCp4dPassword = "")
|
|
{
|
|
bool flag = !string.IsNullOrEmpty(existingAlias);
|
|
base.Title = (flag ? "모델 편집" : "모델 추가");
|
|
base.Width = 420.0;
|
|
base.SizeToContent = SizeToContent.Height;
|
|
base.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
|
base.ResizeMode = ResizeMode.NoResize;
|
|
base.WindowStyle = WindowStyle.None;
|
|
base.AllowsTransparency = true;
|
|
base.Background = Brushes.Transparent;
|
|
Brush background = (Application.Current.TryFindResource("LauncherBackground") as Brush) ?? new SolidColorBrush(Color.FromRgb(26, 27, 46));
|
|
Brush foreground = (Application.Current.TryFindResource("PrimaryText") as Brush) ?? Brushes.White;
|
|
Brush foreground2 = (Application.Current.TryFindResource("SecondaryText") as Brush) ?? Brushes.Gray;
|
|
Brush brush = (Application.Current.TryFindResource("AccentColor") as Brush) ?? Brushes.Blue;
|
|
Brush background2 = (Application.Current.TryFindResource("ItemBackground") as Brush) ?? new SolidColorBrush(Color.FromRgb(42, 43, 64));
|
|
Brush brush2 = (Application.Current.TryFindResource("BorderColor") as Brush) ?? Brushes.Gray;
|
|
Border border = new Border
|
|
{
|
|
Background = background,
|
|
CornerRadius = new CornerRadius(16.0),
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0),
|
|
Padding = new Thickness(28.0, 24.0, 28.0, 24.0),
|
|
Effect = new DropShadowEffect
|
|
{
|
|
BlurRadius = 24.0,
|
|
ShadowDepth = 4.0,
|
|
Opacity = 0.3,
|
|
Color = Colors.Black
|
|
}
|
|
};
|
|
StackPanel stackPanel = new StackPanel();
|
|
StackPanel stackPanel2 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 20.0)
|
|
};
|
|
stackPanel2.Children.Add(new TextBlock
|
|
{
|
|
Text = "\uea86",
|
|
FontFamily = new FontFamily("Segoe MDL2 Assets"),
|
|
FontSize = 18.0,
|
|
Foreground = brush,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Margin = new Thickness(0.0, 0.0, 10.0, 0.0)
|
|
});
|
|
stackPanel2.Children.Add(new TextBlock
|
|
{
|
|
Text = (flag ? "모델 편집" : "새 모델 등록"),
|
|
FontSize = 17.0,
|
|
FontWeight = FontWeights.Bold,
|
|
Foreground = foreground,
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
});
|
|
stackPanel.Children.Add(stackPanel2);
|
|
string text = ((service == "vllm") ? "vLLM" : "Ollama");
|
|
Border border2 = new Border
|
|
{
|
|
Background = brush,
|
|
CornerRadius = new CornerRadius(6.0),
|
|
Padding = new Thickness(10.0, 3.0, 10.0, 3.0),
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 16.0),
|
|
HorizontalAlignment = HorizontalAlignment.Left,
|
|
Opacity = 0.85
|
|
};
|
|
border2.Child = new TextBlock
|
|
{
|
|
Text = text + " 서비스",
|
|
FontSize = 11.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = Brushes.White
|
|
};
|
|
stackPanel.Children.Add(border2);
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "별칭 (표시 이름)",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "채팅 화면에서 표시될 이름입니다. 예: 코드 리뷰 전용, 일반 대화",
|
|
FontSize = 11.0,
|
|
Foreground = foreground2,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
|
|
});
|
|
_aliasBox = new TextBox
|
|
{
|
|
Text = existingAlias,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
Border element = new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _aliasBox
|
|
};
|
|
stackPanel.Children.Add(element);
|
|
stackPanel.Children.Add(new Rectangle
|
|
{
|
|
Height = 1.0,
|
|
Fill = brush2,
|
|
Margin = new Thickness(0.0, 16.0, 0.0, 16.0),
|
|
Opacity = 0.5
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "실제 모델명",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "서버에 배포된 실제 모델 ID (예: llama3:8b, qwen2:7b)",
|
|
FontSize = 11.0,
|
|
Foreground = foreground2,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
|
|
});
|
|
_modelBox = new TextBox
|
|
{
|
|
Text = existingModel,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
Border element2 = new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _modelBox
|
|
};
|
|
stackPanel.Children.Add(element2);
|
|
stackPanel.Children.Add(new Rectangle
|
|
{
|
|
Height = 1.0,
|
|
Fill = brush2,
|
|
Margin = new Thickness(0.0, 16.0, 0.0, 16.0),
|
|
Opacity = 0.5
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "서버 엔드포인트 (선택)",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "이 모델 전용 서버 주소. 비워두면 기본 엔드포인트를 사용합니다.",
|
|
FontSize = 11.0,
|
|
Foreground = foreground2,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
|
|
});
|
|
_endpointBox = new TextBox
|
|
{
|
|
Text = existingEndpoint,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
stackPanel.Children.Add(new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _endpointBox
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "인증 방식",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 10.0, 0.0, 6.0)
|
|
});
|
|
_authTypeBox = new ComboBox
|
|
{
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(8.0, 6.0, 8.0, 6.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
ComboBoxItem comboBoxItem = new ComboBoxItem
|
|
{
|
|
Content = "Bearer 토큰 (API 키)",
|
|
Tag = "bearer"
|
|
};
|
|
ComboBoxItem comboBoxItem2 = new ComboBoxItem
|
|
{
|
|
Content = "CP4D (IBM Cloud Pak for Data)",
|
|
Tag = "cp4d"
|
|
};
|
|
_authTypeBox.Items.Add(comboBoxItem);
|
|
_authTypeBox.Items.Add(comboBoxItem2);
|
|
_authTypeBox.SelectedItem = ((existingAuthType == "cp4d") ? comboBoxItem2 : comboBoxItem);
|
|
stackPanel.Children.Add(new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _authTypeBox
|
|
});
|
|
StackPanel apiKeyPanel = new StackPanel();
|
|
apiKeyPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "API 키 (선택)",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 10.0, 0.0, 6.0)
|
|
});
|
|
_apiKeyBox = new TextBox
|
|
{
|
|
Text = existingApiKey,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
apiKeyPanel.Children.Add(new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _apiKeyBox
|
|
});
|
|
stackPanel.Children.Add(apiKeyPanel);
|
|
_cp4dPanel = new StackPanel
|
|
{
|
|
Visibility = ((!(existingAuthType == "cp4d")) ? Visibility.Collapsed : Visibility.Visible)
|
|
};
|
|
_cp4dPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "CP4D 서버 URL",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 10.0, 0.0, 6.0)
|
|
});
|
|
_cp4dPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "예: https://cpd-host.example.com",
|
|
FontSize = 11.0,
|
|
Foreground = foreground2,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
|
|
});
|
|
_cp4dUrlBox = new TextBox
|
|
{
|
|
Text = existingCp4dUrl,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
_cp4dPanel.Children.Add(new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _cp4dUrlBox
|
|
});
|
|
_cp4dPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "사용자 이름",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 10.0, 0.0, 6.0)
|
|
});
|
|
_cp4dUsernameBox = new TextBox
|
|
{
|
|
Text = existingCp4dUsername,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
_cp4dPanel.Children.Add(new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _cp4dUsernameBox
|
|
});
|
|
_cp4dPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "비밀번호 / API 키",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 10.0, 0.0, 6.0)
|
|
});
|
|
_cp4dPasswordBox = new PasswordBox
|
|
{
|
|
Password = existingCp4dPassword,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
_cp4dPanel.Children.Add(new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _cp4dPasswordBox
|
|
});
|
|
stackPanel.Children.Add(_cp4dPanel);
|
|
_authTypeBox.SelectionChanged += delegate
|
|
{
|
|
bool flag2 = AuthType == "cp4d";
|
|
_cp4dPanel.Visibility = ((!flag2) ? Visibility.Collapsed : Visibility.Visible);
|
|
apiKeyPanel.Visibility = (flag2 ? Visibility.Collapsed : Visibility.Visible);
|
|
};
|
|
apiKeyPanel.Visibility = ((existingAuthType == "cp4d") ? Visibility.Collapsed : Visibility.Visible);
|
|
StackPanel stackPanel3 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
Margin = new Thickness(0.0, 12.0, 0.0, 0.0)
|
|
};
|
|
stackPanel3.Children.Add(new TextBlock
|
|
{
|
|
Text = "\ue72e",
|
|
FontFamily = new FontFamily("Segoe MDL2 Assets"),
|
|
FontSize = 11.0,
|
|
Foreground = new SolidColorBrush(Color.FromRgb(56, 161, 105)),
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Margin = new Thickness(0.0, 0.0, 6.0, 0.0)
|
|
});
|
|
stackPanel3.Children.Add(new TextBlock
|
|
{
|
|
Text = "모델명은 AES-256으로 암호화되어 설정 파일에 저장됩니다",
|
|
FontSize = 10.5,
|
|
Foreground = foreground2,
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
});
|
|
stackPanel.Children.Add(stackPanel3);
|
|
StackPanel stackPanel4 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
HorizontalAlignment = HorizontalAlignment.Right,
|
|
Margin = new Thickness(0.0, 24.0, 0.0, 0.0)
|
|
};
|
|
Button button = new Button
|
|
{
|
|
Content = "취소",
|
|
Width = 80.0,
|
|
Padding = new Thickness(0.0, 8.0, 0.0, 8.0),
|
|
Margin = new Thickness(0.0, 0.0, 10.0, 0.0),
|
|
Background = Brushes.Transparent,
|
|
Foreground = foreground2,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0),
|
|
Cursor = Cursors.Hand,
|
|
FontSize = 13.0
|
|
};
|
|
button.Click += delegate
|
|
{
|
|
base.DialogResult = false;
|
|
Close();
|
|
};
|
|
stackPanel4.Children.Add(button);
|
|
Button button2 = new Button
|
|
{
|
|
Content = (flag ? "저장" : "등록"),
|
|
Width = 80.0,
|
|
Padding = new Thickness(0.0, 8.0, 0.0, 8.0),
|
|
Background = brush,
|
|
Foreground = Brushes.White,
|
|
BorderThickness = new Thickness(0.0),
|
|
Cursor = Cursors.Hand,
|
|
FontSize = 13.0,
|
|
FontWeight = FontWeights.SemiBold
|
|
};
|
|
button2.Click += delegate
|
|
{
|
|
if (string.IsNullOrWhiteSpace(_aliasBox.Text))
|
|
{
|
|
CustomMessageBox.Show("별칭을 입력하세요.", "입력 오류", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
_aliasBox.Focus();
|
|
}
|
|
else if (string.IsNullOrWhiteSpace(_modelBox.Text))
|
|
{
|
|
CustomMessageBox.Show("모델명을 입력하세요.", "입력 오류", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
_modelBox.Focus();
|
|
}
|
|
else
|
|
{
|
|
base.DialogResult = true;
|
|
Close();
|
|
}
|
|
};
|
|
stackPanel4.Children.Add(button2);
|
|
stackPanel.Children.Add(stackPanel4);
|
|
border.Child = stackPanel;
|
|
base.Content = border;
|
|
base.KeyDown += delegate(object _, KeyEventArgs ke)
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
if ((int)ke.Key == 13)
|
|
{
|
|
base.DialogResult = false;
|
|
Close();
|
|
}
|
|
};
|
|
base.Loaded += delegate
|
|
{
|
|
_aliasBox.Focus();
|
|
_aliasBox.SelectAll();
|
|
};
|
|
border.MouseLeftButtonDown += delegate(object _, MouseButtonEventArgs me)
|
|
{
|
|
if (me.LeftButton == MouseButtonState.Pressed)
|
|
{
|
|
try
|
|
{
|
|
DragMove();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|