diff --git a/app/MindWork AI Studio/Components/Settings/SettingsPanelApp.razor b/app/MindWork AI Studio/Components/Settings/SettingsPanelApp.razor index c5ae753f..2237ebb0 100644 --- a/app/MindWork AI Studio/Components/Settings/SettingsPanelApp.razor +++ b/app/MindWork AI Studio/Components/Settings/SettingsPanelApp.razor @@ -14,6 +14,7 @@ + diff --git a/app/MindWork AI Studio/Provider/BaseProvider.cs b/app/MindWork AI Studio/Provider/BaseProvider.cs index 123c4a86..d3bcd005 100644 --- a/app/MindWork AI Studio/Provider/BaseProvider.cs +++ b/app/MindWork AI Studio/Provider/BaseProvider.cs @@ -406,6 +406,18 @@ public abstract class BaseProvider : IProvider, ISecretId // while (true) { + try + { + if(streamReader.EndOfStream) + break; + } + catch (Exception e) + { + await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Stream, string.Format(TB("Tried to stream the LLM provider '{0}' answer. There were some problems with the stream. The message is: '{1}'"), this.InstanceName, e.Message))); + this.logger.LogWarning($"Failed to read the end-of-stream state from {providerName} '{this.InstanceName}': {e.Message}"); + break; + } + // Check if the token is canceled: if (token.IsCancellationRequested) { @@ -588,6 +600,18 @@ public abstract class BaseProvider : IProvider, ISecretId // while (true) { + try + { + if(streamReader.EndOfStream) + break; + } + catch (Exception e) + { + await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Stream, string.Format(TB("Tried to stream the LLM provider '{0}' answer. There were some problems with the stream. The message is: '{1}'"), this.InstanceName, e.Message))); + this.logger.LogWarning($"Failed to read the end-of-stream state from {providerName} '{this.InstanceName}': {e.Message}"); + break; + } + // Check if the token is canceled: if (token.IsCancellationRequested) { diff --git a/app/MindWork AI Studio/Tools/ExternalHttpClientTimeout.cs b/app/MindWork AI Studio/Tools/ExternalHttpClientTimeout.cs index b467f2c5..2cb9fa45 100644 --- a/app/MindWork AI Studio/Tools/ExternalHttpClientTimeout.cs +++ b/app/MindWork AI Studio/Tools/ExternalHttpClientTimeout.cs @@ -8,8 +8,12 @@ namespace AIStudio.Tools; /// public static class ExternalHttpClientTimeout { + public const int MIN_HTTP_CLIENT_TIMEOUT_SECONDS = 120; + public const int MAX_HTTP_CLIENT_TIMEOUT_SECONDS = 3600; public const int DEFAULT_HTTP_CLIENT_TIMEOUT_SECONDS = 3600; + private static readonly Lazy SETTINGS_MANAGER = new(() => Program.SERVICE_PROVIDER.GetRequiredService()); + public static HttpClient CreateHttpClient(Uri? baseAddress = null) { var httpClient = new HttpClient(); @@ -60,11 +64,11 @@ public static class ExternalHttpClientTimeout private static TimeSpan GetTimeout() { - var settingsManager = Program.SERVICE_PROVIDER.GetRequiredService(); - var seconds = settingsManager.ConfigurationData.App.HttpClientTimeoutSeconds; + var seconds = SETTINGS_MANAGER.Value.ConfigurationData.App.HttpClientTimeoutSeconds; if (seconds <= 0) seconds = DEFAULT_HTTP_CLIENT_TIMEOUT_SECONDS; + seconds = Math.Clamp(seconds, MIN_HTTP_CLIENT_TIMEOUT_SECONDS, MAX_HTTP_CLIENT_TIMEOUT_SECONDS); return TimeSpan.FromSeconds(seconds); } @@ -74,4 +78,4 @@ public static class ExternalHttpClientTimeout if (baseAddress is not null) httpClient.BaseAddress = baseAddress; } -} +} \ No newline at end of file