Browse Source

Add CivitAI apis and checkpoint browser page

pull/5/head
Ionite 1 year ago
parent
commit
64b173c7ea
No known key found for this signature in database
  1. 11
      StabilityMatrix/Api/ICivitApi.cs
  2. 11
      StabilityMatrix/App.xaml.cs
  3. 34
      StabilityMatrix/CheckpointBrowserPage.xaml
  4. 20
      StabilityMatrix/CheckpointBrowserPage.xaml.cs
  5. 26
      StabilityMatrix/CheckpointManagerPage.xaml
  6. 13
      StabilityMatrix/MainWindow.xaml
  7. 14
      StabilityMatrix/Models/Api/CivitCommercialUse.cs
  8. 12
      StabilityMatrix/Models/Api/CivitCreator.cs
  9. 22
      StabilityMatrix/Models/Api/CivitFile.cs
  10. 15
      StabilityMatrix/Models/Api/CivitFileMetadata.cs
  11. 23
      StabilityMatrix/Models/Api/CivitImage.cs
  12. 25
      StabilityMatrix/Models/Api/CivitMetadata.cs
  13. 10
      StabilityMatrix/Models/Api/CivitMode.cs
  14. 36
      StabilityMatrix/Models/Api/CivitModel.cs
  15. 14
      StabilityMatrix/Models/Api/CivitModelFormat.cs
  16. 13
      StabilityMatrix/Models/Api/CivitModelFpType.cs
  17. 12
      StabilityMatrix/Models/Api/CivitModelSize.cs
  18. 12
      StabilityMatrix/Models/Api/CivitModelStats.cs
  19. 17
      StabilityMatrix/Models/Api/CivitModelType.cs
  20. 34
      StabilityMatrix/Models/Api/CivitModelVersion.cs
  21. 105
      StabilityMatrix/Models/Api/CivitModelsRequest.cs
  22. 12
      StabilityMatrix/Models/Api/CivitModelsResponse.cs
  23. 13
      StabilityMatrix/Models/Api/CivitPeriod.cs
  24. 16
      StabilityMatrix/Models/Api/CivitSortMode.cs
  25. 15
      StabilityMatrix/Models/Api/CivitStats.cs
  26. 5
      StabilityMatrix/StabilityMatrix.csproj
  27. 41
      StabilityMatrix/ViewModels/CheckpointBrowserViewModel.cs

11
StabilityMatrix/Api/ICivitApi.cs

@ -0,0 +1,11 @@
using System.Threading.Tasks;
using Refit;
using StabilityMatrix.Models.Api;
namespace StabilityMatrix.Api;
public interface ICivitApi
{
[Get("/api/v1/models")]
Task<CivitModelsResponse> GetModels([Body] CivitModelsRequest request);
}

11
StabilityMatrix/App.xaml.cs

@ -74,8 +74,9 @@ namespace StabilityMatrix
serviceCollection.AddTransient<PackageManagerPage>(); serviceCollection.AddTransient<PackageManagerPage>();
serviceCollection.AddTransient<TextToImagePage>(); serviceCollection.AddTransient<TextToImagePage>();
serviceCollection.AddTransient<CheckpointManagerPage>(); serviceCollection.AddTransient<CheckpointManagerPage>();
serviceCollection.AddTransient<CheckpointBrowserPage>();
serviceCollection.AddTransient<InstallerWindow>(); serviceCollection.AddTransient<InstallerWindow>();
serviceCollection.AddTransient<MainWindowViewModel>(); serviceCollection.AddTransient<MainWindowViewModel>();
serviceCollection.AddTransient<SnackbarViewModel>(); serviceCollection.AddTransient<SnackbarViewModel>();
serviceCollection.AddTransient<LaunchOptionsDialogViewModel>(); serviceCollection.AddTransient<LaunchOptionsDialogViewModel>();
@ -86,6 +87,7 @@ namespace StabilityMatrix
serviceCollection.AddTransient<InstallerViewModel>(); serviceCollection.AddTransient<InstallerViewModel>();
serviceCollection.AddTransient<OneClickInstallViewModel>(); serviceCollection.AddTransient<OneClickInstallViewModel>();
serviceCollection.AddTransient<CheckpointManagerViewModel>(); serviceCollection.AddTransient<CheckpointManagerViewModel>();
serviceCollection.AddTransient<CheckpointBrowserViewModel>();
var settingsManager = new SettingsManager(); var settingsManager = new SettingsManager();
serviceCollection.AddSingleton<ISettingsManager>(settingsManager); serviceCollection.AddSingleton<ISettingsManager>(settingsManager);
@ -136,6 +138,13 @@ namespace StabilityMatrix
c.Timeout = TimeSpan.FromSeconds(2); c.Timeout = TimeSpan.FromSeconds(2);
}) })
.AddPolicyHandler(retryPolicy); .AddPolicyHandler(retryPolicy);
serviceCollection.AddRefitClient<ICivitApi>(defaultRefitSettings)
.ConfigureHttpClient(c =>
{
c.BaseAddress = new Uri("https://civitai.com");
c.Timeout = TimeSpan.FromSeconds(8);
})
.AddPolicyHandler(retryPolicy);
// Logging configuration // Logging configuration
var logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"); var logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt");

34
StabilityMatrix/CheckpointBrowserPage.xaml

@ -0,0 +1,34 @@
<Page
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
d:DataContext="{d:DesignInstance viewModels:CheckpointBrowserViewModel,
IsDesignTimeCreatable=True}"
d:DesignHeight="500"
d:DesignWidth="650"
mc:Ignorable="d"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
x:Class="StabilityMatrix.CheckpointBrowserPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:designData="clr-namespace:StabilityMatrix.DesignData"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="clr-namespace:StabilityMatrix.Models"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:viewModels="clr-namespace:StabilityMatrix.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBlock
FontSize="24"
HorizontalAlignment="Center"
Text="Imagine very nice UI here."
VerticalAlignment="Center" />
<StackPanel Margin="16" Orientation="Vertical">
<ui:TextBox PlaceholderText="Query" Text="{Binding SearchQuery, Mode=TwoWay}" />
<ui:Button
Command="{Binding SearchModelsCommand}"
Content="Search"
Margin="0,16,0,0" />
</StackPanel>
</Grid>
</Page>

20
StabilityMatrix/CheckpointBrowserPage.xaml.cs

@ -0,0 +1,20 @@
using System.Diagnostics;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using StabilityMatrix.ViewModels;
using Wpf.Ui.Controls;
namespace StabilityMatrix;
public partial class CheckpointBrowserPage : Page
{
public CheckpointBrowserPage(CheckpointBrowserViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
}
}

26
StabilityMatrix/CheckpointManagerPage.xaml

@ -51,12 +51,26 @@
Header="{Binding Title}" Header="{Binding Title}"
IsExpanded="True" IsExpanded="True"
Margin="8"> Margin="8">
<ui:VirtualizingGridView <Grid>
ItemTemplate="{StaticResource CheckpointFileDataTemplate}" <ui:VirtualizingGridView
ItemsSource="{Binding CheckpointFiles}" ItemTemplate="{StaticResource CheckpointFileDataTemplate}"
Padding="5" ItemsSource="{Binding CheckpointFiles}"
PreviewMouseWheel="VirtualizingGridView_OnPreviewMouseWheel" Padding="5"
SpacingMode="StartAndEndOnly" /> PreviewMouseWheel="VirtualizingGridView_OnPreviewMouseWheel"
SpacingMode="StartAndEndOnly" />
<Border
Grid.RowSpan="4"
Opacity=".9"
Visibility="{Binding BlurVisibility, Mode=OneWay}"
x:Name="Splash">
<Border.Background>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="#8F202020" Offset="0.0" />
<GradientStop Color="#8F202020" Offset="1.0" />
</LinearGradientBrush>
</Border.Background>
</Border>
</Grid>
</Expander> </Expander>
</DataTemplate> </DataTemplate>

13
StabilityMatrix/MainWindow.xaml

@ -7,13 +7,13 @@
Title="Stability Matrix" Title="Stability Matrix"
Width="1100" Width="1100"
WindowBackdropType="Acrylic" WindowBackdropType="Acrylic"
d:DesignHeight="500"
d:DesignWidth="700"
d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel, d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel,
IsDesignTimeCreatable=True}" IsDesignTimeCreatable=True}"
d:DesignHeight="500"
d:DesignWidth="700"
mc:Ignorable="d"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}" ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}" ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d"
x:Class="StabilityMatrix.MainWindow" x:Class="StabilityMatrix.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -69,6 +69,11 @@
<ui:SymbolIcon Symbol="Notebook24" /> <ui:SymbolIcon Symbol="Notebook24" />
</ui:NavigationViewItem.Icon> </ui:NavigationViewItem.Icon>
</ui:NavigationViewItem> </ui:NavigationViewItem>
<ui:NavigationViewItem Content="Get Checkpoints" TargetPageType="{x:Type local:CheckpointBrowserPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="NotebookAdd24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Content="Text2Image (Beta™)" TargetPageType="{x:Type local:TextToImagePage}"> <ui:NavigationViewItem Content="Text2Image (Beta™)" TargetPageType="{x:Type local:TextToImagePage}">
<ui:NavigationViewItem.Icon> <ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Image24" /> <ui:SymbolIcon Symbol="Image24" />
@ -89,7 +94,7 @@
</ui:NavigationView.ContentOverlay> </ui:NavigationView.ContentOverlay>
</ui:NavigationView> </ui:NavigationView>
</Grid> </Grid>
<ContentPresenter Grid.Row="1" x:Name="RootContentDialog" /> <ContentPresenter Grid.Row="1" x:Name="RootContentDialog" />
</Grid> </Grid>
</ui:FluentWindow> </ui:FluentWindow>

14
StabilityMatrix/Models/Api/CivitCommercialUse.cs

@ -0,0 +1,14 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
[JsonConverter(typeof(JsonStringEnumConverter))]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum CivitCommercialUse
{
None,
Image,
Rent,
Sell
}

12
StabilityMatrix/Models/Api/CivitCreator.cs

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitCreator
{
[JsonPropertyName("username")]
public string Username { get; set; }
[JsonPropertyName("image")]
public string? Image { get; set; }
}

22
StabilityMatrix/Models/Api/CivitFile.cs

@ -0,0 +1,22 @@
using System;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitFile
{
[JsonPropertyName("sizeKb")]
public double SizeKb { get; set; }
[JsonPropertyName("pickleScanResult")]
public string PickleScanResult { get; set; }
[JsonPropertyName("virusScanResult")]
public string VirusScanResult { get; set; }
[JsonPropertyName("scannedAt")]
public DateTime? ScannedAt { get; set; }
[JsonPropertyName("metadata")]
public CivitFileMetadata Metadata { get; set; }
}

15
StabilityMatrix/Models/Api/CivitFileMetadata.cs

@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitFileMetadata
{
[JsonPropertyName("fp")]
public CivitModelFpType? Fp { get; set; }
[JsonPropertyName("size")]
public CivitModelSize? Size { get; set; }
[JsonPropertyName("format")]
public CivitModelFormat? Format { get; set; }
}

23
StabilityMatrix/Models/Api/CivitImage.cs

@ -0,0 +1,23 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitImage
{
[JsonPropertyName("url")]
public string Url { get; set; }
[JsonPropertyName("nsfw")]
public string Nsfw { get; set; }
[JsonPropertyName("width")]
public int Width { get; set; }
[JsonPropertyName("height")]
public int Height { get; set; }
[JsonPropertyName("hash")]
public string Hash { get; set; }
// TODO: "meta" ( object? )
}

25
StabilityMatrix/Models/Api/CivitMetadata.cs

@ -0,0 +1,25 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitMetadata
{
[JsonPropertyName("totalItems")]
public int TotalItems { get; set; }
[JsonPropertyName("currentPage")]
public int CurrentPage { get; set; }
[JsonPropertyName("pageSize")]
public int PageSize { get; set; }
[JsonPropertyName("totalPages")]
public int TotalPages { get; set; }
[JsonPropertyName("nextPage")]
public string? NextPage { get; set; }
[JsonPropertyName("prevPage")]
public string? PrevPage { get; set; }
}

10
StabilityMatrix/Models/Api/CivitMode.cs

@ -0,0 +1,10 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum CivitMode
{
Archived,
TakenDown
}

36
StabilityMatrix/Models/Api/CivitModel.cs

@ -0,0 +1,36 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitModel
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonPropertyName("type")]
public CivitModelType Type { get; set; }
[JsonPropertyName("nsfw")]
public bool Nsfw { get; set; }
[JsonPropertyName("tags")]
public string[] Tags { get; set; }
[JsonPropertyName("mode")]
public CivitMode? Mode { get; set; }
[JsonPropertyName("creator")]
public CivitCreator Creator { get; set; }
[JsonPropertyName("stats")]
public CivitModelStats Stats { get; set; }
[JsonPropertyName("modelVersions")]
public CivitModelVersion[] ModelVersions { get; set; }
}

14
StabilityMatrix/Models/Api/CivitModelFormat.cs

@ -0,0 +1,14 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
[JsonConverter(typeof(JsonStringEnumConverter))]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum CivitModelFormat
{
SafeTensor,
PickleTensor,
Other
}

13
StabilityMatrix/Models/Api/CivitModelFpType.cs

@ -0,0 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
[JsonConverter(typeof(JsonStringEnumConverter))]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum CivitModelFpType
{
fp16,
fp32
}

12
StabilityMatrix/Models/Api/CivitModelSize.cs

@ -0,0 +1,12 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
[JsonConverter(typeof(JsonStringEnumConverter))]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum CivitModelSize
{
full,
pruned,
}

12
StabilityMatrix/Models/Api/CivitModelStats.cs

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitModelStats : CivitStats
{
[JsonPropertyName("favoriteCount")]
public int FavoriteCount { get; set; }
[JsonPropertyName("commentCount")]
public int CommentCount { get; set; }
}

17
StabilityMatrix/Models/Api/CivitModelType.cs

@ -0,0 +1,17 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
[JsonConverter(typeof(JsonStringEnumConverter))]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum CivitModelType
{
Checkpoint,
TextualInversion,
Hypernetwork,
AestheticGradient,
LORA,
Controlnet,
Poses
}

34
StabilityMatrix/Models/Api/CivitModelVersion.cs

@ -0,0 +1,34 @@
using System;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitModelVersion
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonPropertyName("createdAt")]
public DateTime CreatedAt { get; set; }
[JsonPropertyName("downloadUrl")]
public string DownloadUrl { get; set; }
[JsonPropertyName("trainedWords")]
public string[] TrainedWords { get; set; }
[JsonPropertyName("files")]
public CivitFile[] Files { get; set; }
[JsonPropertyName("images")]
public CivitImage[] Images { get; set; }
[JsonPropertyName("stats")]
public CivitModelStats Stats { get; set; }
}

105
StabilityMatrix/Models/Api/CivitModelsRequest.cs

@ -0,0 +1,105 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitModelsRequest
{
/// <summary>
/// The number of results to be returned per page. This can be a number between 1 and 200. By default, each page will return 100 results
/// </summary>
[JsonPropertyName("limit")]
public int? Limit { get; set; }
/// <summary>
/// The page from which to start fetching models
/// </summary>
[JsonPropertyName("page")]
public int? Page { get; set; }
/// <summary>
/// Search query to filter models by name
/// </summary>
[JsonPropertyName("query")]
public string? Query { get; set; }
/// <summary>
/// Search query to filter models by tag
/// </summary>
[JsonPropertyName("tag")]
public string? Tag { get; set; }
/// <summary>
/// Search query to filter models by user
/// </summary>
[JsonPropertyName("username")]
public string? Username { get; set; }
/// <summary>
/// The type of model you want to filter with. If none is specified, it will return all types
/// </summary>
[JsonPropertyName("types")]
public CivitModelType[]? Types { get; set; }
/// <summary>
/// The order in which you wish to sort the results
/// </summary>
[JsonPropertyName("sort")]
public CivitSortMode? Sort { get; set; }
/// <summary>
/// The time frame in which the models will be sorted
/// </summary>
[JsonPropertyName("period")]
public CivitPeriod? Period { get; set; }
/// <summary>
/// The rating you wish to filter the models with. If none is specified, it will return models with any rating
/// </summary>
[JsonPropertyName("rating")]
public int? Rating { get; set; }
/// <summary>
/// Filter to models that require or don't require crediting the creator
/// <remarks>Requires Authentication</remarks>
/// </summary>
[JsonPropertyName("favorites")]
public bool? Favorites { get; set; }
/// <summary>
/// Filter to hidden models of the authenticated user
/// <remarks>Requires Authentication</remarks>
/// </summary>
[JsonPropertyName("hidden")]
public bool? Hidden { get; set; }
/// <summary>
/// Only include the primary file for each model (This will use your preferred format options if you use an API token or session cookie)
/// </summary>
[JsonPropertyName("primaryFileOnly")]
public bool? PrimaryFileOnly { get; set; }
/// <summary>
/// Filter to models that allow or don't allow creating derivatives
/// </summary>
[JsonPropertyName("allowDerivatives")]
public bool? AllowDerivatives { get; set; }
/// <summary>
/// Filter to models that allow or don't allow derivatives to have a different license
/// </summary>
[JsonPropertyName("allowDifferentLicenses")]
public bool? AllowDifferentLicenses { get; set; }
/// <summary>
/// Filter to models based on their commercial permissions
/// </summary>
[JsonPropertyName("allowCommercialUse")]
public CivitCommercialUse? AllowCommercialUse { get; set; }
/// <summary>
/// If false, will return safer images and hide models that don't have safe images
/// </summary>
[JsonPropertyName("nsfw")]
public bool? Nsfw { get; set; }
}

12
StabilityMatrix/Models/Api/CivitModelsResponse.cs

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitModelsResponse
{
[JsonPropertyName("items")]
public CivitModel[] Items { get; set; }
[JsonPropertyName("metadata")]
public CivitMetadata Metadata { get; set; }
}

13
StabilityMatrix/Models/Api/CivitPeriod.cs

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum CivitPeriod
{
AllTime,
Year,
Month,
Week,
Day
}

16
StabilityMatrix/Models/Api/CivitSortMode.cs

@ -0,0 +1,16 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum CivitSortMode
{
[EnumMember(Value = "Highest Rated")]
HighestRated,
[EnumMember(Value = "Most Downloaded")]
MostDownloaded,
[EnumMember(Value = "Newest")]
Newest
}

15
StabilityMatrix/Models/Api/CivitStats.cs

@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class CivitStats
{
[JsonPropertyName("downloadCount")]
public int DownloadCount { get; set; }
[JsonPropertyName("ratingCount")]
public int RatingCount { get; set; }
[JsonPropertyName("rating")]
public double Rating { get; set; }
}

5
StabilityMatrix/StabilityMatrix.csproj

@ -81,6 +81,11 @@
<XamlRuntime>Wpf</XamlRuntime> <XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Update="CheckpointBrowserPage.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">

41
StabilityMatrix/ViewModels/CheckpointBrowserViewModel.cs

@ -0,0 +1,41 @@
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using NLog;
using StabilityMatrix.Api;
using StabilityMatrix.Models.Api;
namespace StabilityMatrix.ViewModels;
public partial class CheckpointBrowserViewModel : ObservableObject
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ICivitApi civitApi;
[ObservableProperty]
private string? searchQuery;
public CheckpointBrowserViewModel(ICivitApi civitApi)
{
this.civitApi = civitApi;
}
[RelayCommand]
private async Task SearchModels()
{
if (string.IsNullOrWhiteSpace(SearchQuery))
{
return;
}
var models = await civitApi.GetModels(new CivitModelsRequest
{
Query = SearchQuery,
Limit = 5,
Nsfw = true,
});
Logger.Debug($"Found {models.Items.Length} models");
}
}
Loading…
Cancel
Save