Skip to content

Commit

Permalink
支持基于现有助理创建副本 (#20)
Browse files Browse the repository at this point in the history
* 支持创建助理副本

* 修正英文翻译文本
  • Loading branch information
Richasy authored Jun 24, 2024
1 parent fab6b41 commit 99af30e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Desktop/RodelAgent.UI/Controls/Chat/AgentsSection.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<ic:SymbolIcon Symbol="Edit" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem Click="OnCreateCopyItemClick" Text="{ext:Locale Name=CreateCopyFromThis}">
<MenuFlyoutItem.Icon>
<ic:SymbolIcon Symbol="SaveCopy" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem Click="OnPresetItemDeleteClick" Text="{ext:Locale Name=Delete}">
<MenuFlyoutItem.Icon>
<ic:SymbolIcon Foreground="{ThemeResource SystemFillColorCriticalBrush}" Symbol="Delete" />
Expand Down
9 changes: 9 additions & 0 deletions src/Desktop/RodelAgent.UI/Controls/Chat/AgentsSection.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ private void OnEditItemClick(object sender, RoutedEventArgs e)
ViewModel.EditAgentCommand.Execute(vm);
}
}

private void OnCreateCopyItemClick(object sender, RoutedEventArgs e)
{
var vm = (sender as FrameworkElement)?.DataContext as ViewModels.Items.ChatPresetItemViewModel;
if (vm != null)
{
ViewModel.CreateAgentCopyCommand.Execute(vm);
}
}
}
11 changes: 7 additions & 4 deletions src/Desktop/RodelAgent.UI/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
<value>Keep plugin</value>
</data>
<data name="CanNotLoadAgentWarning" xml:space="preserve">
<value>Unable to load the assistant. The corresponding service may have been deregistered. Please check and try again.</value>
<value>Unable to load the agent. The corresponding service may have been deregistered. Please check and try again.</value>
</data>
<data name="CanNotLoadLocalModelWarning" xml:space="preserve">
<value>Unable to load the local model. The model may have been deleted or the default preset is missing. Please try deleting and re-importing the model.</value>
Expand Down Expand Up @@ -286,7 +286,7 @@
<value>Conversation turn</value>
</data>
<data name="ChooseServiceOrAgent" xml:space="preserve">
<value>Choose a service or assistant</value>
<value>Choose a service or agent</value>
</data>
<data name="ChooseServiceOrAgentDescription" xml:space="preserve">
<value>Start a constructive conversation!</value>
Expand Down Expand Up @@ -363,6 +363,9 @@
<data name="Create" xml:space="preserve">
<value>Create</value>
</data>
<data name="CreateCopyFromThis" xml:space="preserve">
<value>Create copy</value>
</data>
<data name="CreateCustomModel" xml:space="preserve">
<value>Create custom model</value>
</data>
Expand Down Expand Up @@ -611,7 +614,7 @@ You can manually adjust the limit, and the application will capture the specifie
<value>Modify</value>
</data>
<data name="ModifyAgent" xml:space="preserve">
<value>Modify assistant</value>
<value>Modify agent</value>
</data>
<data name="ModifyCustomModel" xml:space="preserve">
<value>Modify custom model</value>
Expand Down Expand Up @@ -662,7 +665,7 @@ You can manually adjust the limit, and the application will capture the specifie
<value>Next step</value>
</data>
<data name="NoAgents" xml:space="preserve">
<value>No available assistants</value>
<value>No available agents</value>
</data>
<data name="NoAudioHistory" xml:space="preserve">
<value>No audio records yet, go generate one~</value>
Expand Down
3 changes: 3 additions & 0 deletions src/Desktop/RodelAgent.UI/Resources/zh-Hans-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@
<data name="Create" xml:space="preserve">
<value>创建</value>
</data>
<data name="CreateCopyFromThis" xml:space="preserve">
<value>创建副本</value>
</data>
<data name="CreateCustomModel" xml:space="preserve">
<value>创建自定义模型</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ private async Task AddAgentAsync()
IsAgentsEmpty = AgentPresets.Count == 0;
}

[RelayCommand]
private async Task CreateAgentCopyAsync(ChatPresetItemViewModel presetVM)
{
var tempAgent = presetVM.Data.Clone();
tempAgent.Id = Guid.NewGuid().ToString("N");

var vm = new ChatPresetItemViewModel(tempAgent);
_presetModuleVM.SetData(vm, ChatSessionPresetType.Agent);
var dialog = new ChatPresetSettingsDialog();
await dialog.ShowAsync();

var preset = dialog.ViewModel.Data;
if (preset is not null && !_presetModuleVM.IsManualClose)
{
if (!AgentPresets.Any(p => p.Data.Id == preset.Data.Id))
{
AgentPresets.Add(new ChatPresetItemViewModel(preset.Data));
await _storageService.AddOrUpdateChatAgentAsync(preset.Data);
}
}

IsAgentsEmpty = AgentPresets.Count == 0;
}

[RelayCommand]
private async Task SetSelectedAgentAsync(ChatPresetItemViewModel presetVM)
{
Expand Down

0 comments on commit 99af30e

Please sign in to comment.