Skip to content

Commit

Permalink
Replaced ModelInfo by LMKit.ModelCard
Browse files Browse the repository at this point in the history
  • Loading branch information
lcarrere committed Dec 20, 2024
1 parent fee176b commit 1332528
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 218 deletions.
13 changes: 7 additions & 6 deletions LM-Kit-Maestro/Helpers/FileHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LMKit.Maestro.Services;
using LMKit.Model;
using System.Web;

namespace LMKit.Maestro.Helpers;
Expand Down Expand Up @@ -108,14 +109,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)

Check failure on line 112 in LM-Kit-Maestro/Helpers/FileHelpers.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ModelCard' could not be found (are you missing a using directive or an assembly reference?)
{
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)

Check failure on line 117 in LM-Kit-Maestro/Helpers/FileHelpers.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ModelCard' could not be found (are you missing a using directive or an assembly reference?)
{
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 +177,9 @@ public static long GetFileSize(string path)
return new FileInfo(path).Length;
}

public static string GetModelFileRelativeName(ModelInfo modelInfo)
public static string GetModelFileRelativeName(ModelCard modelCard)

Check failure on line 180 in LM-Kit-Maestro/Helpers/FileHelpers.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ModelCard' could not be found (are you missing a using directive or an assembly reference?)
{
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
42 changes: 24 additions & 18 deletions LM-Kit-Maestro/Helpers/MaestroHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
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)

Check failure on line 9 in LM-Kit-Maestro/Helpers/MaestroHelpers.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ModelCard' could not be found (are you missing a using directive or an assembly reference?)
{
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()
{
Publisher = publisher,
Repository = repository,
ModelUri = modelFileUri
});
}
}
}
7 changes: 4 additions & 3 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; }

Check failure on line 8 in LM-Kit-Maestro/Services/Interfaces/ILLMFileManager.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ModelCard' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 8 in LM-Kit-Maestro/Services/Interfaces/ILLMFileManager.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ModelCard' could not be found (are you missing a using directive or an assembly reference?)
ObservableCollection<Uri> UnsortedModels { get; }
bool FileCollectingInProgress { get; }
string ModelStorageDirectory { get; set; }
event EventHandler? FileCollectingCompleted;
void Initialize();
void DeleteModel(ModelInfo modelInfo);
void DeleteModel(ModelCard modelCard);

Check failure on line 14 in LM-Kit-Maestro/Services/Interfaces/ILLMFileManager.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ModelCard' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 14 in LM-Kit-Maestro/Services/Interfaces/ILLMFileManager.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ModelCard' could not be found (are you missing a using directive or an assembly reference?)
}
Loading

0 comments on commit 1332528

Please sign in to comment.