Skip to content

Commit

Permalink
Various improvements to models management (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcarrere authored Dec 25, 2024
1 parent 5d9482f commit 7356722
Show file tree
Hide file tree
Showing 19 changed files with 612 additions and 437 deletions.
15 changes: 14 additions & 1 deletion LM-Kit-Maestro/Services/AppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public string ModelStorageDirectory
{
string directory = Settings.Get(nameof(ModelStorageDirectory), LMKitDefaultSettings.DefaultModelStorageDirectory);

if(directory != LMKit.Global.Configuration.ModelStorageDirectory)
if (directory != LMKit.Global.Configuration.ModelStorageDirectory)
{
LMKit.Global.Configuration.ModelStorageDirectory = directory;
}
Expand All @@ -55,6 +55,19 @@ public string ModelStorageDirectory
}
}

public bool EnableSlowModels
{
get
{
return Settings.Get(nameof(EnableSlowModels), LMKitDefaultSettings.DefaultEnableSlowModels);
}
set
{
Settings.Set(nameof(EnableSlowModels), value);
OnPropertyChanged();
}
}

public string SystemPrompt
{
get
Expand Down
1 change: 1 addition & 0 deletions LM-Kit-Maestro/Services/Interfaces/IAppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface IAppSettingsService
public SamplingMode SamplingMode { get; set; }
public RandomSamplingConfig RandomSamplingConfig { get; set; }
public Mirostat2SamplingConfig Mirostat2SamplingConfig { get; set; }
public bool EnableSlowModels { get; set; }
}
3 changes: 1 addition & 2 deletions LM-Kit-Maestro/Services/Interfaces/ILLMFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ public interface ILLMFileManager
ReadOnlyObservableCollection<ModelCard> UnsortedModels { get; }
bool FileCollectingInProgress { get; }
string ModelStorageDirectory { get; set; }

long TotalModelSize { get; }
int DownloadedCount { get; }

public bool EnableSlowModels { get; set; }
event EventHandler? FileCollectingCompleted;
void Initialize();
void DeleteModel(ModelCard modelCard);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
namespace LMKit.Maestro.Services;

public partial class LLMFileManager
{
private sealed partial class FileSystemEntryRecorder
{
public class DirectoryRecord : FileSystemEntryRecord
{
public List<FileSystemEntryRecord> Entries { get; protected set; }

public DirectoryRecord(string name, DirectoryRecord? parent) : base(name, parent)
{
Entries = new List<FileSystemEntryRecord>();
}

public bool DeleteEntry(FileSystemEntryRecord entry)
{
return Entries.Remove(entry);
}

public void AddEntry(FileSystemEntryRecord entry)
{
Entries.Add(entry);
}

public DirectoryRecord? TryGetChildDirectory(string name)
{
foreach (var child in Entries)
{
if (child is DirectoryRecord childDirectory && string.CompareOrdinal(child.Name, name) == 0)
{
return childDirectory;
}
}

return null;
}

public FileRecord? TryGetChildFile(string name)
{
foreach (var child in Entries)
{
if (child is FileRecord childFile && string.CompareOrdinal(childFile.Name, name) == 0)
{
return childFile;
}
}

return null;
}

public FileSystemEntryRecord? TryGetChildEntry(string name)
{
foreach (var entry in Entries)
{
if (string.CompareOrdinal(entry.Name, name) == 0)
{
return entry;
}
}

return null;
}

protected override void OnEntryRenamed()
{
PropagateRenamedParentEntryToChildren(1, Name, this);
}

private void PropagateRenamedParentEntryToChildren(int ancestorLevel, string newName, DirectoryRecord directoryRecord)
{
foreach (var child in directoryRecord.Entries)
{
if (child is FileRecord childFile)
{
childFile.OnParentDirectoryRenamed(ancestorLevel, newName);
}
else if (child is DirectoryRecord childDirectory)
{
PropagateRenamedParentEntryToChildren(ancestorLevel + 1, newName, childDirectory);
}
}
}

#if DEBUG
public override string ToString()
{
return ("(directory)" + Name);
}
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using LMKit.Maestro.Helpers;

namespace LMKit.Maestro.Services;

public partial class LLMFileManager
{
private sealed partial class FileSystemEntryRecorder
{
public class FileRecord : FileSystemEntryRecord
{
public Uri FileUri { get; set; }

public event EventHandler? FilePathChanged;

public FileRecord(Uri fileUri, string name, DirectoryRecord parent) : base(name, parent)
{
FileUri = fileUri;
}

public void OnParentDirectoryRenamed(int ancestorLevel, string newName)
{
Uri oldUri = FileUri;
FileUri = FileHelpers.GetRenamedFileUri(FileUri, newName, ancestorLevel);
FilePathChanged?.Invoke(this, new FileRecordPathChangedEventArgs(oldUri, FileUri));
}

protected override void OnEntryRenamed()
{
Uri oldUri = FileUri;
FileUri = FileHelpers.GetRenamedFileUri(FileUri, Name);
FilePathChanged?.Invoke(this, new FileRecordPathChangedEventArgs(oldUri, FileUri));
}

#if DEBUG
public override string ToString()
{
return ("(file)" + Name);
}
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace LMKit.Maestro.Services;

public partial class LLMFileManager
{
private sealed partial class FileSystemEntryRecorder
{
public sealed class FileRecordPathChangedEventArgs : EventArgs
{
public Uri OldPath { get; }

public Uri NewPath { get; }

public FileRecordPathChangedEventArgs(Uri oldPath, Uri newPath)
{
OldPath = oldPath;
NewPath = newPath;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace LMKit.Maestro.Services;

public partial class LLMFileManager
{
private sealed partial class FileSystemEntryRecorder
{
public abstract class FileSystemEntryRecord
{
public DirectoryRecord? Parent { get; protected set; }

public string Name { get; private set; }

public FileSystemEntryRecord(string name, DirectoryRecord? parent)
{
Name = name;
Parent = parent;
}

protected abstract void OnEntryRenamed();

public void Rename(string name)
{
Name = name;
OnEntryRenamed();
}

public bool Delete()
{
if (Parent == null)
{
return false;
}

return Parent.DeleteEntry(this);
}
}
}
}
Loading

0 comments on commit 7356722

Please sign in to comment.