Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加内部提示词测试工具 #75

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Core/RodelChat.Models/Client/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public sealed class ChatMessage
/// 发送者名称.
/// </summary>
[JsonPropertyName("author")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Author { get; set; }

/// <summary>
/// 发送者 ID.
/// </summary>
[JsonPropertyName("author_id")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? AuthorId { get; set; }

/// <summary>
Expand All @@ -43,13 +45,15 @@ public sealed class ChatMessage
/// 消息发送的时间.
/// </summary>
[JsonPropertyName("time")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(DateTimeOffsetConverter))]
public DateTimeOffset? Time { get; set; }

/// <summary>
/// 获取或设置客户端消息类型.
/// </summary>
[JsonPropertyName("client_message_type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public ClientMessageType ClientMessageType { get; set; } = ClientMessageType.Normal;

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Desktop/RodelAgent.UI.Models/Constants/InfoType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public enum InfoType
/// 成功消息.
/// </summary>
Success,

/// <summary>
/// 加载中.
/// </summary>
Loading,
}
7 changes: 7 additions & 0 deletions src/Desktop/RodelAgent.UI.Models/Constants/SettingNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ public enum SettingNames
IsAudioHistoryColumnManualHide,
LastSelectedFeaturePage,
IsInternalPromptTest,
PromptTestLastSelectedChatService,
PromptTestLastSelectedModel,
PromptTestPageExtraColumnWidth,
PromptTestMessageJsonFilePath,
PromptTestSystemPromptPath,
PromptTestPresetVariablesFilePath,
PromptTestInputFilePath,
}
#pragma warning restore CS1591 // 缺少对公共可见类型或成员的 XML 注释
12 changes: 11 additions & 1 deletion src/Desktop/RodelAgent.UI/Controls/Base/StatusTip.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mc:Ignorable="d">

<Grid
Padding="12,8,12,12"
Padding="{x:Bind Padding, Mode=OneWay}"
Background="{x:Bind Background, Mode=OneWay}"
BorderBrush="{x:Bind BorderBrush, Mode=OneWay}"
BorderThickness="{x:Bind BorderThickness, Mode=OneWay}"
Expand Down Expand Up @@ -46,6 +46,16 @@
Foreground="{ThemeResource InfoBarErrorSeverityIconBackground}"
Symbol="DismissCircle"
Visibility="Collapsed" />
<ProgressRing
x:Name="LoadingRing"
Width="12"
Height="12"
MinWidth="12"
MinHeight="12"
VerticalAlignment="Center"
IsActive="False"
Style="{StaticResource PageProgressRingStyle}"
Visibility="Collapsed" />
</Grid>
<TextBlock
Grid.Column="1"
Expand Down
11 changes: 11 additions & 0 deletions src/Desktop/RodelAgent.UI/Controls/Base/StatusTip.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ private static void OnStatusChanged(DependencyObject d, DependencyPropertyChange

private void ChangeStatus()
{
InformationIcon.Visibility = Visibility.Collapsed;
SuccessIcon.Visibility = Visibility.Collapsed;
WarningIcon.Visibility = Visibility.Collapsed;
ErrorIcon.Visibility = Visibility.Collapsed;
LoadingRing.Visibility = Visibility.Collapsed;
LoadingRing.IsActive = false;

switch (Status)
{
case InfoType.Information:
Expand All @@ -70,6 +77,10 @@ private void ChangeStatus()
case InfoType.Error:
ErrorIcon.Visibility = Visibility.Visible;
break;
case InfoType.Loading:
LoadingRing.Visibility = Visibility.Visible;
LoadingRing.IsActive = true;
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/Desktop/RodelAgent.UI/Controls/Base/TipPopup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

<local:StatusTip
x:Name="PopupContainer"
Padding="12,8,12,12"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
Padding="8,0"
Style="{StaticResource PageScrollViewerStyle}">
<StackPanel x:Name="ControlPanel" Margin="0,0,0,12">
<StackPanel x:Name="BasicPanel">
<StackPanel x:Name="BasicPanel" Visibility="{x:Bind BasicPanelVisibility, Mode=OneWay}">
<Grid
Margin="12,0"
Padding="0,2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public sealed partial class ChatProviderOptionPanel : ChatProviderOptionPanelBas
public static readonly DependencyProperty IsMaxRoundEnabledProperty =
DependencyProperty.Register(nameof(IsMaxRoundEnabled), typeof(bool), typeof(ChatProviderOptionPanel), new PropertyMetadata(true));

/// <summary>
/// <see cref="BasicPanelVisibility"/> 的依赖属性.
/// </summary>
public static readonly DependencyProperty BasicPanelVisibilityProperty =
DependencyProperty.Register(nameof(BasicPanelVisibility), typeof(Visibility), typeof(ChatProviderOptionPanel), new PropertyMetadata(Visibility.Visible));

private bool _isInitialized;

/// <summary>
Expand All @@ -40,6 +46,15 @@ public bool IsMaxRoundEnabled
set => SetValue(IsMaxRoundEnabledProperty, value);
}

/// <summary>
/// 基础面板可见性.
/// </summary>
public Visibility BasicPanelVisibility
{
get => (Visibility)GetValue(BasicPanelVisibilityProperty);
set => SetValue(BasicPanelVisibilityProperty, value);
}

/// <inheritdoc/>
protected override void OnViewModelChanged(ChatPresetItemViewModel? oldValue, ChatPresetItemViewModel? newValue)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<local:PromptTestPageControlBase
x:Class="RodelAgent.UI.Controls.Internal.PromptTestExtraBody"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:RodelAgent.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ext="using:RodelAgent.UI.Extensions"
xmlns:local="using:RodelAgent.UI.Controls.Internal"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewmodels="using:RodelAgent.UI.ViewModels"
mc:Ignorable="d">

<Grid>
<controls:EmptyHolder
Title="{ext:Locale Name=ClickGenerate}"
Description="{ext:Locale Name=ClickGenerateDescription}"
Emoji="&#x1F44B;"
Style="{StaticResource BasicEmptyHolderStyle}"
Visibility="{x:Bind ViewModel.IsSessionsEmpty, Mode=OneWay}" />
<ScrollView Style="{StaticResource PageScrollViewStyle}" Visibility="{x:Bind ViewModel.IsSessionsEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
<ItemsRepeater Margin="16,12" ItemsSource="{x:Bind ViewModel.Sessions, Mode=OneWay}">
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="viewmodels:PromptTestSessionItemViewModel">
<local:PromptTestSessionItemControl ViewModel="{x:Bind}" />
</DataTemplate>
</ItemsRepeater.ItemTemplate>
<ItemsRepeater.Layout>
<StackLayout Spacing="4" />
</ItemsRepeater.Layout>
</ItemsRepeater>
</ScrollView>
</Grid>
</local:PromptTestPageControlBase>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Rodel. All rights reserved.

namespace RodelAgent.UI.Controls.Internal;

/// <summary>
/// 提示词测试页面额外内容.
/// </summary>
public sealed partial class PromptTestExtraBody : PromptTestPageControlBase
{
/// <summary>
/// Initializes a new instance of the <see cref="PromptTestExtraBody"/> class.
/// </summary>
public PromptTestExtraBody() => InitializeComponent();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<local:PromptTestPageControlBase
x:Class="RodelAgent.UI.Controls.Internal.PromptTestExtraHeader"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ext="using:RodelAgent.UI.Extensions"
xmlns:ic="using:FluentIcons.WinUI"
xmlns:local="using:RodelAgent.UI.Controls.Internal"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Padding="16,0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Style="{StaticResource BodyStrongTextBlockStyle}"
Text="{ext:Locale Name=GenerateResult}" />
<Grid Grid.Column="1" Visibility="{x:Bind ViewModel.IsSessionsEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
<HyperlinkButton
VerticalAlignment="Center"
Command="{x:Bind ViewModel.CancelGeneratingCommand}"
Content="{ext:Locale Name=Cancel}"
Visibility="{x:Bind ViewModel.IsGenerating, Mode=OneWay}" />
<Button
VerticalAlignment="Center"
Command="{x:Bind ViewModel.ExportResultCommand, Mode=OneWay}"
Style="{StaticResource IconButtonStyle}"
ToolTipService.ToolTip="{ext:Locale Name=Export}"
Visibility="{x:Bind ViewModel.IsFinished, Mode=OneWay}">
<ic:SymbolIcon FontSize="14" Symbol="Share" />
</Button>
</Grid>
</Grid>
</local:PromptTestPageControlBase>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Rodel. All rights reserved.

namespace RodelAgent.UI.Controls.Internal;

/// <summary>
/// 提示词测试页面额外标题.
/// </summary>
public sealed partial class PromptTestExtraHeader : PromptTestPageControlBase
{
/// <summary>
/// Initializes a new instance of the <see cref="PromptTestExtraHeader"/> class.
/// </summary>
public PromptTestExtraHeader() => InitializeComponent();
}
133 changes: 133 additions & 0 deletions src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8" ?>
<local:PromptTestPageControlBase
x:Class="RodelAgent.UI.Controls.Internal.PromptTestMainBody"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="using:Richasy.WinUI.Share.Base"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ext="using:RodelAgent.UI.Extensions"
xmlns:items="using:RodelAgent.UI.ViewModels.Items"
xmlns:local="using:RodelAgent.UI.Controls.Internal"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox
Padding="18,12"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AcceptsReturn="True"
FontSize="18"
IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
Style="{StaticResource TransparentTextBoxStyle}"
Text="{x:Bind ViewModel.CurrentSystemPrompt.Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<Border
Grid.Row="1"
Height="1"
HorizontalAlignment="Stretch"
Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
<TextBox
Grid.Row="2"
Padding="18,12"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AcceptsReturn="True"
FontSize="18"
IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
LostFocus="OnTextBoxLostFocus"
Style="{StaticResource TransparentTextBoxStyle}"
Text="{x:Bind ViewModel.UserPromptTemplate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<Border
Grid.Row="3"
Height="1"
HorizontalAlignment="Stretch"
Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
<Grid Grid.Row="4" Padding="16,8">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{ext:Locale Name=Variables}"
IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
Visibility="{x:Bind ViewModel.IsVariableEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
<Button.Flyout>
<Flyout Placement="Top" ShouldConstrainToRootBounds="False">
<Grid Width="380">
<ItemsRepeater ItemsSource="{x:Bind ViewModel.Variables}">
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="items:VariableItemViewModel">
<Grid>
<ComboBox
x:Name="ValuesComboBox"
HorizontalAlignment="Stretch"
x:Load="{x:Bind Values, Mode=OneWay, Converter={StaticResource ObjectToBoolConverter}}"
Header="{x:Bind Name}"
ItemsSource="{x:Bind Values}"
SelectedItem="{x:Bind Value, Mode=TwoWay}"
Visibility="{x:Bind Values, Converter={StaticResource ObjectToVisibilityConverter}}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="x:String">
<base:TrimTextBlock MaxLines="1" Text="{x:Bind}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBox
x:Name="ValueBox"
HorizontalAlignment="Stretch"
x:Load="{x:Bind Values, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
AcceptsReturn="True"
Header="{x:Bind Name}"
PlaceholderText="{x:Bind Name}"
Text="{x:Bind Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
Visibility="{x:Bind Values, Converter={StaticResource ObjectToVisibilityReverseConverter}}" />
</Grid>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
<ItemsRepeater.Layout>
<StackLayout Spacing="8" />
</ItemsRepeater.Layout>
</ItemsRepeater>
</Grid>
</Flyout>
</Button.Flyout>
</Button>
<Button
Grid.Column="1"
MinWidth="120"
VerticalAlignment="Center"
Command="{x:Bind ViewModel.GenerateCommand}"
Content="{ext:Locale Name=Generate}"
Style="{StaticResource AccentButtonStyle}"
Visibility="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
<Button
Grid.Column="1"
MinWidth="120"
VerticalAlignment="Center"
Command="{x:Bind ViewModel.CancelGeneratingCommand, Mode=OneWay}"
Style="{StaticResource AccentButtonStyle}"
Visibility="{x:Bind ViewModel.IsGenerating, Mode=OneWay}">
<StackPanel Orientation="Horizontal" Spacing="8">
<ProgressRing
Width="16"
Height="16"
VerticalAlignment="Center"
Foreground="{ThemeResource TextOnAccentFillColorPrimaryBrush}" />
<TextBlock VerticalAlignment="Center" Text="{ext:Locale Name=Cancel}" />
</StackPanel>
</Button>
</Grid>
</Grid>
</local:PromptTestPageControlBase>
Loading
Loading