Skip to content

Commit

Permalink
Release/0.5.1 (#28)
Browse files Browse the repository at this point in the history
* rename: skill -> plugin

* format config.json

* fix: default config folder
  • Loading branch information
xbotter authored Feb 6, 2024
1 parent 8da153b commit f683f6a
Show file tree
Hide file tree
Showing 19 changed files with 258 additions and 226 deletions.
4 changes: 2 additions & 2 deletions PromptPlayground/Messages/CloseFunctionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace PromptPlayground.Messages
{
public class CloseFunctionMessage
{
public CloseFunctionMessage(SemanticPluginViewModel function)
public CloseFunctionMessage(SemanticFunctionViewModel function)
{
Function = function;
}

public SemanticPluginViewModel Function { get; }
public SemanticFunctionViewModel Function { get; }
}
}
4 changes: 2 additions & 2 deletions PromptPlayground/Messages/FunctionCreateMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{
public class FunctionCreateMessage
{
public FunctionCreateMessage(SemanticPluginViewModel? function = null)
public FunctionCreateMessage(SemanticFunctionViewModel? function = null)
{
Function = function;
}

public SemanticPluginViewModel? Function { get; }
public SemanticFunctionViewModel? Function { get; }
}
}
4 changes: 2 additions & 2 deletions PromptPlayground/Messages/FunctionSelectedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace PromptPlayground.Messages
{
public class FunctionSelectedMessage
{
public SemanticPluginViewModel Function { get; set; }
public SemanticFunctionViewModel Function { get; set; }

public FunctionSelectedMessage(SemanticPluginViewModel viewModel)
public FunctionSelectedMessage(SemanticFunctionViewModel viewModel)
{
this.Function = viewModel;
}
Expand Down
9 changes: 9 additions & 0 deletions PromptPlayground/Messages/PluginOpenMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using PromptPlayground.Messages;

namespace PromptPlayground.ViewModels
{
public class PluginOpenMessage : FileOrFolderOpenMessage
{
public PluginOpenMessage(string path) : base(path) { }
}
}
9 changes: 0 additions & 9 deletions PromptPlayground/Messages/SkillOpenMessage.cs

This file was deleted.

4 changes: 2 additions & 2 deletions PromptPlayground/PromptPlayground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
</ItemGroup>

<ItemGroup>
<Compile Update="Views\SkillsView.axaml.cs">
<DependentUpon>SkillsView.axaml</DependentUpon>
<Compile Update="Views\PluginsView.axaml.cs">
<DependentUpon>PluginsView.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
15 changes: 11 additions & 4 deletions PromptPlayground/ViewModels/ConfigViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public partial class ConfigViewModel : ViewModelBase, IConfigAttributesProvider,

public List<ConfigAttribute> AllAttributes { get; set; } = [];

public int MaxCount { get => maxCount; set => SetProperty(ref maxCount, value); }
[ObservableProperty]
private int maxCount = 3;

#region Model
private int modelSelectedIndex = 0;

Expand Down Expand Up @@ -67,11 +68,13 @@ public int ModelSelectedIndex
private readonly List<ILLMConfigViewModel> LLMs = [];
#endregion

#region IConfigAttributesProvider
IList<ConfigAttribute> IConfigAttributesProvider.AllAttributes => this.AllAttributes;
public ILLMConfigViewModel GetLLM()
{
return this.SelectedModel;
}
#endregion

public ConfigViewModel(bool requireLoadConfig = false) : this()
{
Expand Down Expand Up @@ -120,17 +123,21 @@ private List<ConfigAttribute> CheckAttributes(List<ConfigAttribute> list)
return list;
}


private void SaveConfigToUserProfile()
{
var profile = GetConfigFilePath();
File.WriteAllText(profile, JsonSerializer.Serialize(this));
}

private string GetConfigFilePath()
private string GetConfigFilePath(string configFile = "user.config")
{
var profile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
return Path.Combine(profile, "PromptPlayground.config");
var folder = Path.Combine(profile, ".prompt_playground");
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
return Path.Combine(folder, configFile);
}

public void SaveConfig()
Expand Down
2 changes: 1 addition & 1 deletion PromptPlayground/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task OpenFolderAsync()

if (!string.IsNullOrWhiteSpace(response))
{
WeakReferenceMessenger.Default.Send(new SkillOpenMessage(response!));
WeakReferenceMessenger.Default.Send(new PluginOpenMessage(response!));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,46 @@

namespace PromptPlayground.ViewModels
{
public partial class SkillViewModel : ObservableRecipient, IEquatable<SkillViewModel>, IRecipient<FunctionSelectedMessage>, IRecipient<CloseFunctionMessage>
public partial class PluginViewModel : ObservableRecipient, IEquatable<PluginViewModel>, IRecipient<FunctionSelectedMessage>, IRecipient<CloseFunctionMessage>
{
private static bool IsFunctionDir(string folder) => File.Exists(Path.Combine(folder, Constants.SkPrompt));

public bool Equals(SkillViewModel? other)
public bool Equals(PluginViewModel? other)
{
return other?.Folder == this.Folder;
}

public SkillViewModel(string folder)
public PluginViewModel(string folder)
{
if (Directory.Exists(folder))
{
this.Folder = folder;
this.Title = Path.GetFileName(folder);
var functions = Directory.GetDirectories(Folder)
.Where(IsFunctionDir)
.Select(SemanticPluginViewModel.Create)
.Select(SemanticFunctionViewModel.Create)
.ToList();

Functions = new ObservableCollection<SemanticPluginViewModel>(functions);
Functions = new ObservableCollection<SemanticFunctionViewModel>(functions);
}
else
{
this.Title = folder;
Functions = new ObservableCollection<SemanticPluginViewModel>();
Functions = new ObservableCollection<SemanticFunctionViewModel>();
}
IsActive = true;
}
public string? Folder { get; set; }
public string Title { get; set; }

[ObservableProperty]
private ObservableCollection<SemanticPluginViewModel> functions;
private ObservableCollection<SemanticFunctionViewModel> functions;

[ObservableProperty]
private SemanticPluginViewModel? selected;
private SemanticFunctionViewModel? selected;


partial void OnSelectedChanged(SemanticPluginViewModel? oldValue, SemanticPluginViewModel? newValue)
partial void OnSelectedChanged(SemanticFunctionViewModel? oldValue, SemanticFunctionViewModel? newValue)
{
if (newValue != null && oldValue != newValue)
{
Expand All @@ -61,15 +61,15 @@ partial void OnSelectedChanged(SemanticPluginViewModel? oldValue, SemanticPlugin
[RelayCommand(CanExecute = nameof(CanAddNewFunction))]
public void AddNewFunction()
{
AddNewFunction(new SemanticPluginViewModel(""));
AddNewFunction(new SemanticFunctionViewModel(""));
}

private bool CanAddNewFunction()
{
return !Directory.Exists(this.Folder);
}

public void AddNewFunction(SemanticPluginViewModel function)
public void AddNewFunction(SemanticFunctionViewModel function)
{
if (string.IsNullOrWhiteSpace(function.Name))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,44 @@

namespace PromptPlayground.ViewModels
{
public partial class SkillsViewModel : ObservableRecipient, IRecipient<SkillOpenMessage>,
public partial class PluginsViewModel : ObservableRecipient, IRecipient<PluginOpenMessage>,
IRecipient<FunctionOpenMessage>,
IRecipient<FunctionCreateMessage>
{
public SkillsViewModel()
public PluginsViewModel()
{

OpenedFunctions = new SkillViewModel("opened");
Skills = new ObservableCollection<SkillViewModel>
OpenedPlugin = new PluginViewModel("opened");
Plugins = new ObservableCollection<PluginViewModel>
{
OpenedFunctions
OpenedPlugin
};
IsActive = true;
}

[RelayCommand]
public void CloseSkillFolder(SkillViewModel model)
public void ClosePluginFolder(PluginViewModel model)
{
if (this.Skills.Contains(model))
if (this.Plugins.Contains(model))
{
this.Skills.Remove(model);
this.Plugins.Remove(model);
}
}

[RelayCommand]
public void FunctionSelected(SemanticPluginViewModel viewModel)
public void FunctionSelected(SemanticFunctionViewModel viewModel)
{
WeakReferenceMessenger.Default.Send(new FunctionSelectedMessage(viewModel));
}

public void Receive(SkillOpenMessage message)
public void Receive(PluginOpenMessage message)
{
if (Directory.Exists(message.Path))
{
var skill = new SkillViewModel(message.Path);
if (!Skills.Contains(skill))
var plugin = new PluginViewModel(message.Path);
if (!Plugins.Contains(plugin))
{
Skills.Add(skill);
Plugins.Add(plugin);
}
}
}
Expand All @@ -61,25 +61,25 @@ public void Receive(FunctionOpenMessage message)
return;
}

var function = new SemanticPluginViewModel(message.Path);
if (!OpenedFunctions.Functions.Contains(function))
var function = new SemanticFunctionViewModel(message.Path);
if (!OpenedPlugin.Functions.Contains(function))
{
OpenedFunctions.Functions.Add(function);
OpenedPlugin.Functions.Add(function);
FunctionSelected(function);
}
}

public void Receive(FunctionCreateMessage message)
{
var function = message.Function ?? new SemanticPluginViewModel("");
this.OpenedFunctions.AddNewFunction(function);
var function = message.Function ?? new SemanticFunctionViewModel("");
this.OpenedPlugin.AddNewFunction(function);

FunctionSelected(function);
}

public SkillViewModel OpenedFunctions { get; set; }
public PluginViewModel OpenedPlugin { get; set; }

public ObservableCollection<SkillViewModel> Skills { get; set; }
public ObservableCollection<PluginViewModel> Plugins { get; set; }

}
}
4 changes: 2 additions & 2 deletions PromptPlayground/ViewModels/ResultsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace PromptPlayground.ViewModels
{
public class ResultsViewModel : ObservableRecipient, IRecipient<FunctionSelectedMessage>
{
private SemanticPluginViewModel function;
private SemanticFunctionViewModel function;
public ObservableCollection<GenerateResult> Results => function.Results;
public ResultsViewModel(SemanticPluginViewModel function)
public ResultsViewModel(SemanticFunctionViewModel function)
{
this.function = function;
IsActive = true;
Expand Down
Loading

0 comments on commit f683f6a

Please sign in to comment.