|
51 | 51 | using StabilityMatrix.Avalonia.ViewModels.Progress; |
52 | 52 | using StabilityMatrix.Avalonia.Views; |
53 | 53 | using StabilityMatrix.Core.Api; |
| 54 | +using StabilityMatrix.Core.Api.Handlers; |
54 | 55 | using StabilityMatrix.Core.Api.LykosAuthApi; |
55 | 56 | using StabilityMatrix.Core.Api.PromptGenApi; |
56 | 57 | using StabilityMatrix.Core.Attributes; |
|
65 | 66 | using StabilityMatrix.Core.Models.Settings; |
66 | 67 | using StabilityMatrix.Core.Python; |
67 | 68 | using StabilityMatrix.Core.Services; |
| 69 | +using StabilityMatrix.Core.Services.ImageGeneration; |
68 | 70 | using StabilityMatrix.Core.Updater; |
69 | 71 | using ApiOptions = StabilityMatrix.Core.Models.Configs.ApiOptions; |
70 | 72 | using Application = Avalonia.Application; |
@@ -149,6 +151,11 @@ public override void OnFrameworkInitializationCompleted() |
149 | 151 | { |
150 | 152 | base.OnFrameworkInitializationCompleted(); |
151 | 153 |
|
| 154 | + if (!Debugger.IsAttached || Program.Args.DebugExceptionDialog) |
| 155 | + { |
| 156 | + Dispatcher.UIThread.UnhandledException += Dispatcher_UnhandledException; |
| 157 | + } |
| 158 | + |
152 | 159 | if (Design.IsDesignMode) |
153 | 160 | { |
154 | 161 | DesignData.DesignData.Initialize(); |
@@ -389,6 +396,7 @@ internal static void ConfigurePageViewModels(IServiceCollection services) |
389 | 396 | { |
390 | 397 | provider.GetRequiredService<PackageManagerViewModel>(), |
391 | 398 | provider.GetRequiredService<InferenceViewModel>(), |
| 399 | + provider.GetRequiredService<BananaVisionPageViewModel>(), |
392 | 400 | provider.GetRequiredService<CheckpointsPageViewModel>(), |
393 | 401 | provider.GetRequiredService<CheckpointBrowserViewModel>(), |
394 | 402 | provider.GetRequiredService<OutputsPageViewModel>(), |
@@ -503,8 +511,21 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte |
503 | 511 | { |
504 | 512 | services.AddSingleton<ILiteDbContext, LiteDbContext>(); |
505 | 513 | services.AddSingleton<IDisposable>(p => p.GetRequiredService<ILiteDbContext>()); |
| 514 | + |
| 515 | + // BananaVision has its own database to preserve conversations when main DB is cleared |
| 516 | + services.AddSingleton<IBananaVisionDbContext, BananaVisionDbContext>(); |
| 517 | + services.AddSingleton<IDisposable>(p => p.GetRequiredService<IBananaVisionDbContext>()); |
506 | 518 | } |
507 | 519 |
|
| 520 | + // Image generation services |
| 521 | + services.AddSingleton<IImageGenerationProvider, GeminiImageGenerationProvider>(); |
| 522 | + services.AddSingleton<IImageGenerationProvider, Gemini31FlashImageGenerationProvider>(); |
| 523 | + services.AddSingleton<IImageGenerationProvider, Gemini3ProImageGenerationProvider>(); |
| 524 | + services.AddSingleton<IImageGenerationProvider, FluxKontextProvider>(); |
| 525 | + services.AddSingleton<IImageGenerationProvider, QwenImageEditProvider>(); |
| 526 | + services.AddSingleton<IImageGenerationProvider, Flux2KleinProvider>(); |
| 527 | + services.AddSingleton<IImageGenerationChatService, ImageGenerationChatService>(); |
| 528 | + |
508 | 529 | services.AddTransient<IGitHubClient, GitHubClient>(_ => |
509 | 530 | { |
510 | 531 | var client = new GitHubClient(new ProductHeaderValue("StabilityMatrix")); |
@@ -728,7 +749,7 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte |
728 | 749 | } |
729 | 750 | ) |
730 | 751 | .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { AllowAutoRedirect = false }) |
731 | | - .AddPolicyHandler(retryPolicy) |
| 752 | + .AddPolicyHandler(retryPolicyLonger) |
732 | 753 | .AddHttpMessageHandler(serviceProvider => new TokenAuthHeaderHandler( |
733 | 754 | serviceProvider.GetRequiredService<LykosAuthTokenProvider>() |
734 | 755 | )); |
@@ -764,6 +785,19 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte |
764 | 785 | }) |
765 | 786 | .AddPolicyHandler(retryPolicy); // Assuming retryPolicy is suitable |
766 | 787 |
|
| 788 | + services |
| 789 | + .AddRefitClient<IGeminiApi>(defaultRefitSettings) |
| 790 | + .ConfigureHttpClient(c => |
| 791 | + { |
| 792 | + c.BaseAddress = new Uri("https://generativelanguage.googleapis.com"); |
| 793 | + c.Timeout = TimeSpan.FromMinutes(5); // Higher timeout for image generation |
| 794 | + }) |
| 795 | + .AddHttpMessageHandler<GeminiApiKeyHandler>() |
| 796 | + .AddPolicyHandler(retryPolicyLonger); |
| 797 | + |
| 798 | + // Register GeminiApiKeyHandler |
| 799 | + services.AddTransient<GeminiApiKeyHandler>(); |
| 800 | + |
767 | 801 | // Apizr clients |
768 | 802 | services.AddApizrManagerFor<IOpenModelDbApi, OpenModelDbManager>(options => |
769 | 803 | { |
@@ -1039,6 +1073,14 @@ private static void OnServiceProviderDisposing(ServiceProvider serviceProvider) |
1039 | 1073 | Logger.Trace("Disposing {Count} Disposables", disposables.Count); |
1040 | 1074 | } |
1041 | 1075 |
|
| 1076 | + private static void Dispatcher_UnhandledException(object? sender, DispatcherUnhandledExceptionEventArgs e) |
| 1077 | + { |
| 1078 | + if (Program.ShowExceptionDialog(e.Exception, true)) |
| 1079 | + { |
| 1080 | + e.Handled = true; |
| 1081 | + } |
| 1082 | + } |
| 1083 | + |
1042 | 1084 | private static void TaskScheduler_UnobservedTaskException( |
1043 | 1085 | object? sender, |
1044 | 1086 | UnobservedTaskExceptionEventArgs e |
|
0 commit comments