Skip to content

Commit

Permalink
Improve model management (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcarrere authored Dec 21, 2024
1 parent 110f644 commit 7c17e92
Show file tree
Hide file tree
Showing 29 changed files with 522 additions and 459 deletions.
65 changes: 1 addition & 64 deletions LM-Kit-Maestro/AppConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

internal static class AppConstants
{
public const string AppVersion = "0.1.1";
public const string AppVersion = "0.1.2";
public const string AppName = "LM-Kit Maestro";
public static string AppNameWithVersion => $"{AppName} {AppVersion}";

Expand All @@ -19,67 +19,4 @@ internal static class AppConstants
public const string ChatRoute = "Chat";

public const string ModelsRoute = "Models";

#if BETA_DOWNLOAD_MODELS
//LM-Kit models catalog: https://huggingface.co/lm-kit
public static readonly ModelInfo[] AvailableModels =
{
new ModelInfo(
@"https://huggingface.co/lm-kit/llama-3-8b-instruct-gguf/resolve/main/Llama-3-8B-Instruct-Q4_K_M.gguf",
new ModelInfo.ModelMetadata()
{
FileSize = 4920733952
}),

new ModelInfo(
@"https://huggingface.co/lm-kit/LM-Kit.Sentiment_Analysis-TinyLlama-1.1B-1T-OpenOrca-en-q4-gguf/resolve/main/LM-Kit.Sentiment_Analysis-TinyLlama-1.1B-1T-OpenOrca-en-q4.gguf",
new ModelInfo.ModelMetadata()
{
}),

new ModelInfo(
@"https://huggingface.co/lm-kit/LM-Kit.Sarcasm_Detection-TinyLlama-1.1B-1T-OpenOrca-en-q4-gguf/resolve/main/LM-Kit.Sarcasm_Detection-TinyLlama-1.1B-1T-OpenOrca-en-q4.gguf",
new ModelInfo.ModelMetadata()
{
}),

new ModelInfo(
@"https://huggingface.co/lm-kit/bge-1.5-gguf/resolve/main/bge-small-en-v1.5-f16.gguf",
new ModelInfo.ModelMetadata()
{
}),

new ModelInfo(
@"https://huggingface.co/lm-kit/mistral-0.1-openorca-7b-gguf/resolve/main/Mistral-0.1-OpenOrca-7B-Q4_K_M.gguf",
new ModelInfo.ModelMetadata()
{
}),

new ModelInfo(
@"https://huggingface.co/lm-kit/mistral-0.3-7b-gguf/resolve/main/Mistral-0.3-7B-Q4_K_M.gguf",
new ModelInfo.ModelMetadata()
{
}),

new ModelInfo(
@"https://huggingface.co/lm-kit/deepseek-coder-1.6-7b-gguf/resolve/main/DeepSeek-Coder-1.6-7B-Instruct-Q4_K_M.gguf",
new ModelInfo.ModelMetadata()
{
}),

new ModelInfo(
@"https://huggingface.co/lm-kit/deepseek-coder-2-lite-15.7b-gguf/resolve/main/DeepSeek-Coder-2-Lite-15.7B-Instruct-Q4_K_M.gguf",
new ModelInfo.ModelMetadata()
{
}),
//https://huggingface.co/lm-kit/llama-3.1-8b-instruct-gguf
//https://huggingface.co/lm-kit/phi-3.1-mini-4k-3.8b-instruct-gguf/tree/main
//https://huggingface.co/lm-kit/gemma-2-2b-gguf/tree/main
//https://huggingface.co/lm-kit/phi-3-medium-4k-14b-instruct-gguf/tree/main
//https://huggingface.co/lm-kit/mistral-0.3-7b-instruct-gguf/tree/main
//https://huggingface.co/lm-kit/mistral-nemo-2407-12.2b-instruct-gguf/tree/main
//https://huggingface.co/lm-kit/qwen-2-7b-instruct-gguf/tree/main
//https://huggingface.co/lm-kit/gemma-2-9b-gguf/tree/main
};
#endif
}
14 changes: 7 additions & 7 deletions LM-Kit-Maestro/Helpers/FileHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LMKit.Maestro.Services;
using LMKit.Model;
using System.Web;

namespace LMKit.Maestro.Helpers;
Expand Down Expand Up @@ -108,14 +108,14 @@ public static string SanitizeUriSegment(string uriSegment)
return Uri.UnescapeDataString(uriSegment);
}

public static Uri GetModelFileUri(ModelInfo modelInfo, string modelsFolderPath)
public static Uri GetModelFileUri(ModelCard modelCard, string modelsFolderPath)
{
return new Uri(GetModelFilePath(modelInfo, modelsFolderPath));
return new Uri(GetModelFilePath(modelCard, modelsFolderPath));
}

public static string GetModelFilePath(ModelInfo modelInfo, string modelsFolderPath)
public static string GetModelFilePath(ModelCard modelCard, string modelsFolderPath)
{
return Path.Combine(modelsFolderPath, modelInfo.Publisher, modelInfo.Repository, modelInfo.FileName);
return Path.Combine(modelsFolderPath, modelCard.Publisher, modelCard.Repository, modelCard.FileName);
}

public static string? GetModelFilePathFromUrl(Uri modelUrl, string modelsFolderPath)
Expand Down Expand Up @@ -176,9 +176,9 @@ public static long GetFileSize(string path)
return new FileInfo(path).Length;
}

public static string GetModelFileRelativeName(ModelInfo modelInfo)
public static string GetModelFileRelativeName(ModelCard modelCard)
{
return Path.Combine(modelInfo.Publisher, modelInfo.Repository, modelInfo.FileName);
return Path.Combine(modelCard.Publisher, modelCard.Repository, modelCard.FileName);
}

public static string GetModelFileRelativePath(string filePath, string modelsFolderPath)
Expand Down
37 changes: 19 additions & 18 deletions LM-Kit-Maestro/Helpers/MaestroHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
using LMKit.Maestro.Services;
using LMKit.Maestro.ViewModels;
using LMKit.Model;

namespace LMKit.Maestro.Helpers
{
internal static class MaestroHelpers
{
public static ModelInfoViewModel? TryGetExistingModelInfoViewModel(ICollection<ModelInfoViewModel> modelInfoViewModels, ModelInfo modelInfo)
public static ModelInfoViewModel? TryGetExistingModelInfoViewModel(ICollection<ModelInfoViewModel> modelCardViewModels, ModelCard modelCard)
{
foreach (var modelInfoViewModel in modelInfoViewModels)
{
if (string.CompareOrdinal(modelInfoViewModel.ModelInfo.FileName, modelInfo.FileName) == 0 &&
string.CompareOrdinal(modelInfoViewModel.ModelInfo.Repository, modelInfo.Repository) == 0 &&
string.CompareOrdinal(modelInfoViewModel.ModelInfo.Publisher, modelInfo.Publisher) == 0)
foreach (var modelCardViewModel in modelCardViewModels)
{//todo: use sha instead
if (string.CompareOrdinal(modelCardViewModel.ModelInfo.FileName, modelCard.FileName) == 0 &&
string.CompareOrdinal(modelCardViewModel.ModelInfo.Repository, modelCard.Repository) == 0 &&
string.CompareOrdinal(modelCardViewModel.ModelInfo.Publisher, modelCard.Publisher) == 0)
{
return modelInfoViewModel;
return modelCardViewModel;
}
}

return null;
}

public static ModelInfoViewModel? TryGetExistingModelInfoViewModel(string modelsFolderPath, ICollection<ModelInfoViewModel> modelInfoViewModels, Uri modelFileUri)
public static ModelInfoViewModel? TryGetExistingModelInfoViewModel(string modelsFolderPath, ICollection<ModelInfoViewModel> modelCardViewModels, Uri modelFileUri)
{
if (FileHelpers.GetModelInfoFromPath(modelFileUri.LocalPath, modelsFolderPath, out string publisher, out string repository, out string fileName))
{
foreach (var modelInfoViewModel in modelInfoViewModels)
foreach (var modelCardViewModel in modelCardViewModels)
{
if (string.CompareOrdinal(modelInfoViewModel.ModelInfo.FileName, fileName) == 0 &&
string.CompareOrdinal(modelInfoViewModel.ModelInfo.Repository, repository) == 0 &&
string.CompareOrdinal(modelInfoViewModel.ModelInfo.Publisher, publisher) == 0)
if (string.CompareOrdinal(modelCardViewModel.ModelInfo.FileName, fileName) == 0 &&
string.CompareOrdinal(modelCardViewModel.ModelInfo.Repository, repository) == 0 &&
string.CompareOrdinal(modelCardViewModel.ModelInfo.Publisher, publisher) == 0)
{
return modelInfoViewModel;
return modelCardViewModel;
}
}
}
else
{
//handling unsorted models.
foreach (var modelInfoViewModel in modelInfoViewModels)
foreach (var modelCardViewModel in modelCardViewModels)
{
if (modelInfoViewModel.ModelInfo.FileUri == modelFileUri)
if (modelCardViewModel.ModelInfo.ModelUri == modelFileUri)
{
return modelInfoViewModel;
return modelCardViewModel;
}
}
}

//Loïc: we have an architecture defect. We can reach this stage, especially at startup, while modelInfoViewModels is not completely loaded.
//Loïc: we have an architecture defect. We can reach this stage, especially at startup, while modelCardViewModels is not completely loaded.
//todo Evan: fix.
return new ModelInfoViewModel(new ModelInfo(publisher, repository, fileName, modelFileUri));
return new ModelInfoViewModel(new ModelCard(modelFileUri));
}
}
}
8 changes: 4 additions & 4 deletions LM-Kit-Maestro/LM-Kit-Maestro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@
</ItemGroup>

<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<PackageReference Include="LM-Kit.NET.Backend.Cuda12.Windows" Version="2024.12.7" />
<PackageReference Include="LM-Kit.NET.Backend.Cuda12.Windows" Version="2024.12.9" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="LM-Kit.NET" Version="2024.12.7" />
<PackageReference Include="LM-Kit.NET" Version="2024.12.9" />
<PackageReference Include="Majorsoft.Blazor.Components.Common.JsInterop" Version="1.5.0" />
<PackageReference Include="Markdig" Version="0.38.0" />
<PackageReference Include="Markdig" Version="0.39.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.21" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.21" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.21" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="CommunityToolkit.Maui" Version="9.1.1" />
<PackageReference Include="CommunityToolkit.Maui" Version="10.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="MetroLog.Maui" Version="2.1.0" />
<PackageReference Include="Mopups" Version="1.3.2" />
Expand Down
26 changes: 24 additions & 2 deletions LM-Kit-Maestro/LM-Kit-Maestro.dev.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,40 @@
<MauiCss Include="wwwroot\css\font-awesome.min.css" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\redist\runtimes\osx-64\LM-Kit.ggml.backend.blas.dylib" Link="LM-Kit.ggml.backend.blas.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\redist\runtimes\osx-64\LM-Kit.ggml.backend.dylib" Link="LM-Kit.ggml.backend.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\redist\runtimes\osx-64\LM-Kit.ggml.backend.metal.dylib" Link="LM-Kit.ggml.backend.metal.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\redist\runtimes\osx-64\LM-Kit.ggml.base.dylib" Link="LM-Kit.ggml.base.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\redist\runtimes\osx-64\LM-Kit.ggml.dylib" Link="LM-Kit.ggml.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\redist\runtimes\osx-64\LM-Kit.llama.dylib" Link="LM-Kit.llama.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Include="wwwroot\css\bootstrap.min.css" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="LM-Kit.NET" Version="2024.12.8" />
<PackageReference Include="Majorsoft.Blazor.Components.Common.JsInterop" Version="1.5.0" />
<PackageReference Include="Markdig" Version="0.38.0" />
<PackageReference Include="Markdig" Version="0.39.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.21" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.21" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.21" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="CommunityToolkit.Maui" Version="9.1.1" />
<PackageReference Include="CommunityToolkit.Maui" Version="10.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="MetroLog.Maui" Version="2.1.0" />
<PackageReference Include="Mopups" Version="1.3.2" />
Expand Down
31 changes: 23 additions & 8 deletions LM-Kit-Maestro/Services/AppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace LMKit.Maestro.Services;


public partial class AppSettingsService : ObservableObject, IAppSettingsService
{
protected IPreferences Settings { get; }
Expand All @@ -13,29 +12,45 @@ public AppSettingsService(IPreferences settings)
Settings = settings;
}


public string? LastLoadedModel
public Uri? LastLoadedModelUri
{
get
{
return Settings.Get(nameof(LastLoadedModel), default(string?));
string? uriString = Settings.Get(nameof(LastLoadedModelUri), default(string?));

if (!string.IsNullOrWhiteSpace(uriString))
{
return new Uri(uriString);
}
else
{
return null;
}
}
set
{
Settings.Set(nameof(LastLoadedModel), value);
Settings.Set(nameof(LastLoadedModelUri), value?.ToString());
OnPropertyChanged();
}
}

public string ModelsFolderPath
public string ModelStorageDirectory
{
get
{
return Settings.Get(nameof(ModelsFolderPath), LMKitDefaultSettings.DefaultModelsFolderPath);
string directory = Settings.Get(nameof(ModelStorageDirectory), LMKitDefaultSettings.DefaultModelStorageDirectory);

if(directory != LMKit.Global.Configuration.ModelStorageDirectory)
{
LMKit.Global.Configuration.ModelStorageDirectory = directory;
}

return directory;
}
set
{
Settings.Set(nameof(ModelsFolderPath), value);
Settings.Set(nameof(ModelStorageDirectory), value);
LMKit.Global.Configuration.ModelStorageDirectory = value;
OnPropertyChanged();
}
}
Expand Down
4 changes: 2 additions & 2 deletions LM-Kit-Maestro/Services/Interfaces/IAppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public interface IAppSettingsService
{
public string? LastLoadedModel { get; set; }
public string ModelsFolderPath { get; set; }
public Uri? LastLoadedModelUri { get; set; }
public string ModelStorageDirectory { get; set; }
public string SystemPrompt { get; set; }
public int MaximumCompletionTokens { get; set; }
public int RequestTimeout { get; set; }
Expand Down
9 changes: 5 additions & 4 deletions LM-Kit-Maestro/Services/Interfaces/ILLMFileManager.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.Collections.ObjectModel;
using LMKit.Model;
using System.Collections.ObjectModel;

namespace LMKit.Maestro.Services;

public interface ILLMFileManager
{
ObservableCollection<ModelInfo> UserModels { get; }
ObservableCollection<ModelCard> UserModels { get; }
ObservableCollection<Uri> UnsortedModels { get; }
bool FileCollectingInProgress { get; }
string ModelsFolderPath { get; set; }
string ModelStorageDirectory { get; set; }
event EventHandler? FileCollectingCompleted;
void Initialize();
void DeleteModel(ModelInfo modelInfo);
void DeleteModel(ModelCard modelCard);
}
Loading

0 comments on commit 7c17e92

Please sign in to comment.