Browse Source

Add PackagePair overload for ConnectAsync

pull/165/head
Ionite 1 year ago
parent
commit
479ceafc2e
No known key found for this signature in database
  1. 7
      StabilityMatrix.Avalonia/DesignData/MockInferenceClientManager.cs
  2. 3
      StabilityMatrix.Avalonia/Services/IInferenceClientManager.cs
  3. 29
      StabilityMatrix.Avalonia/Services/InferenceClientManager.cs

7
StabilityMatrix.Avalonia/DesignData/MockInferenceClientManager.cs

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Core.Inference; using StabilityMatrix.Core.Inference;
using StabilityMatrix.Core.Models;
namespace StabilityMatrix.Avalonia.DesignData; namespace StabilityMatrix.Avalonia.DesignData;
@ -30,6 +31,12 @@ public class MockInferenceClientManager : ObservableObject, IInferenceClientMana
return Task.CompletedTask; return Task.CompletedTask;
} }
/// <inheritdoc />
public Task ConnectAsync(PackagePair packagePair)
{
return Task.CompletedTask;
}
public Task CloseAsync() public Task CloseAsync()
{ {
return Task.CompletedTask; return Task.CompletedTask;

3
StabilityMatrix.Avalonia/Services/IInferenceClientManager.cs

@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks; using System.Threading.Tasks;
using StabilityMatrix.Core.Inference; using StabilityMatrix.Core.Inference;
using StabilityMatrix.Core.Models;
namespace StabilityMatrix.Avalonia.Services; namespace StabilityMatrix.Avalonia.Services;
@ -19,5 +20,7 @@ public interface IInferenceClientManager : IDisposable, INotifyPropertyChanged,
Task ConnectAsync(); Task ConnectAsync();
Task ConnectAsync(PackagePair packagePair);
Task CloseAsync(); Task CloseAsync();
} }

29
StabilityMatrix.Avalonia/Services/InferenceClientManager.cs

@ -3,8 +3,13 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using Sentry;
using StabilityMatrix.Core.Api; using StabilityMatrix.Core.Api;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Inference; using StabilityMatrix.Core.Inference;
using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Models.Packages;
namespace StabilityMatrix.Avalonia.Services; namespace StabilityMatrix.Avalonia.Services;
@ -16,6 +21,8 @@ public partial class InferenceClientManager : ObservableObject, IInferenceClient
{ {
private readonly IApiFactory apiFactory; private readonly IApiFactory apiFactory;
// Current
[ObservableProperty, NotifyPropertyChangedFor(nameof(IsConnected))] [ObservableProperty, NotifyPropertyChangedFor(nameof(IsConnected))]
private ComfyClient? client; private ComfyClient? client;
@ -57,6 +64,28 @@ public partial class InferenceClientManager : ObservableObject, IInferenceClient
await LoadSharedPropertiesAsync(); await LoadSharedPropertiesAsync();
} }
public async Task ConnectAsync(PackagePair packagePair)
{
if (IsConnected) return;
if (packagePair.BasePackage is not ComfyUI)
{
throw new ArgumentException("Base package is not ComfyUI", nameof(packagePair));
}
var tempClient = new ComfyClient(apiFactory, new Uri("http://127.0.0.1:8188"));
// Add output dir if available
if (packagePair.InstalledPackage.FullPath is { } path)
{
tempClient.OutputImagesDir = new DirectoryPath(path, "output");
}
await tempClient.ConnectAsync();
Client = tempClient;
await LoadSharedPropertiesAsync();
}
public async Task CloseAsync() public async Task CloseAsync()
{ {
if (!IsConnected) return; if (!IsConnected) return;

Loading…
Cancel
Save