From e4e243b64e98826349614ee19a4fae1d6aabeeba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Carr=C3=A8re?= Date: Tue, 24 Dec 2024 11:23:30 +0100 Subject: [PATCH 1/9] improve exception handling --- LM-Kit-Maestro/Services/LMKitService.cs | 70 +++++++++++++------------ 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/LM-Kit-Maestro/Services/LMKitService.cs b/LM-Kit-Maestro/Services/LMKitService.cs index 37f57c4..e9c65ee 100644 --- a/LM-Kit-Maestro/Services/LMKitService.cs +++ b/LM-Kit-Maestro/Services/LMKitService.cs @@ -211,35 +211,20 @@ private async Task HandleLMKitRequest(LMKitRequest request) // Ensuring we don't touch anything until Lm-Kit objects' state has been set to handle this request. _lmKitServiceSemaphore.Wait(); - LMKitResult result; - - if (request.CancellationTokenSource.IsCancellationRequested || ModelLoadingState == LMKitModelLoadingState.Unloaded) + try { - result = new LMKitResult() - { - Status = LMKitTextGenerationStatus.Cancelled - }; + LMKitResult result; - _lmKitServiceSemaphore.Release(); - } - else - { - if (request.RequestType == LMKitRequest.LMKitRequestType.Prompt || request.RequestType == LMKitRequest.LMKitRequestType.RegenerateResponse) + if (request.CancellationTokenSource.IsCancellationRequested || ModelLoadingState == LMKitModelLoadingState.Unloaded) { - var conversation = request.RequestType == LMKitRequest.LMKitRequestType.Prompt ? - ((LMKitRequest.PromptRequestParameters)request.Parameters!).Conversation : - ((LMKitRequest.RegenerateResponseParameters)request.Parameters!).Conversation; - - BeforeSubmittingPrompt(conversation); - } - - _lmKitServiceSemaphore.Release(); + result = new LMKitResult() + { + Status = LMKitTextGenerationStatus.Cancelled + }; - try - { - result = await SubmitRequest(request); + _lmKitServiceSemaphore.Release(); } - finally + else { if (request.RequestType == LMKitRequest.LMKitRequestType.Prompt || request.RequestType == LMKitRequest.LMKitRequestType.RegenerateResponse) { @@ -247,20 +232,39 @@ private async Task HandleLMKitRequest(LMKitRequest request) ((LMKitRequest.PromptRequestParameters)request.Parameters!).Conversation : ((LMKitRequest.RegenerateResponseParameters)request.Parameters!).Conversation; - AfterSubmittingPrompt(conversation); + BeforeSubmittingPrompt(conversation); } - } - } - if (_requestSchedule.Contains(request)) - { - _requestSchedule.Remove(request); - } + _lmKitServiceSemaphore.Release(); - request.ResponseTask.TrySetResult(result); + try + { + result = await SubmitRequest(request); + } + finally + { + if (request.RequestType == LMKitRequest.LMKitRequestType.Prompt || request.RequestType == LMKitRequest.LMKitRequestType.RegenerateResponse) + { + var conversation = request.RequestType == LMKitRequest.LMKitRequestType.Prompt ? + ((LMKitRequest.PromptRequestParameters)request.Parameters!).Conversation : + ((LMKitRequest.RegenerateResponseParameters)request.Parameters!).Conversation; + + AfterSubmittingPrompt(conversation); + } + } + } - return result; + request.ResponseTask.TrySetResult(result); + return result; + } + finally + { + if (_requestSchedule.Contains(request)) + { + _requestSchedule.Remove(request); + } + } } private async Task SubmitRequest(LMKitRequest request) From 7511c389ff5a0804a060700e778009052d134e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Carr=C3=A8re?= Date: Tue, 24 Dec 2024 11:23:43 +0100 Subject: [PATCH 2/9] improve model pannel page --- LM-Kit-Maestro/UI/Pages/ModelsPage.xaml | 15 +++++++++------ LM-Kit-Maestro/ViewModels/ModelInfoViewModel.cs | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/LM-Kit-Maestro/UI/Pages/ModelsPage.xaml b/LM-Kit-Maestro/UI/Pages/ModelsPage.xaml index cf08b90..1a3b8ce 100644 --- a/LM-Kit-Maestro/UI/Pages/ModelsPage.xaml +++ b/LM-Kit-Maestro/UI/Pages/ModelsPage.xaml @@ -198,6 +198,7 @@ + @@ -216,7 +217,6 @@ Text="{Binding ModelInfo.Publisher}" ToolTipProperties.Text="{Binding ModelPath}"/> -