From 4f1c586d9168ca10f10616d6ac068a90d63384c5 Mon Sep 17 00:00:00 2001 From: Jon Galloway Date: Mon, 7 Apr 2025 16:05:00 -0700 Subject: [PATCH 1/3] Add note on extending timeout for Ollama client Standard HttpClient timeout of 10 seconds applied by Service Defaults under .NET Aspire is likely too short for Ollama calls. Add note with code to extend this timeout. --- .../src/ChatWithCustomData/README.Aspire.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md b/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md index 5d211e3d96d..c5aea4355f0 100644 --- a/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md +++ b/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md @@ -70,6 +70,24 @@ This project is configured to run Ollama in a Docker container. To get started, download, install, and run Docker Desktop from the [official website](https://www.docker.com/). Follow the installation instructions specific to your operating system. +The response time from Ollama depends on your GPU. If you find that default resilience timout of 10 seconds used by .NET Aspire is timing out for the HTTP call from the web app to the Ollama service, you can update the web app's `Program.cs` to extend the timeout by adding the following below the line which reads `builder.AddServiceDefaults();`: + +```csharp +// Extend the HTTP Client timeout for Ollama +builder.Services.ConfigureHttpClientDefaults(http => +{ + #pragma warning disable EXTEXP0001 + http.RemoveAllResilienceHandlers(); + http.AddStandardResilienceHandler(config => + { + config.AttemptTimeout.Timeout = TimeSpan.FromMinutes(3); + config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(3) * 3; + config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(3); + }); + #pragma warning restore EXTEXP0001 +}); +``` + Note: Ollama and Docker are excellent open source products, but are not maintained by Microsoft. #### ---#endif #### ---#if (IsAzureOpenAI) From bf53a5a9e4f7302ccd87fae2e882f9f7c8627539 Mon Sep 17 00:00:00 2001 From: Jon Galloway Date: Mon, 7 Apr 2025 16:07:36 -0700 Subject: [PATCH 2/3] Update src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/ChatWithCustomData/README.Aspire.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md b/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md index c5aea4355f0..6fcdf2d4a9b 100644 --- a/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md +++ b/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md @@ -70,8 +70,7 @@ This project is configured to run Ollama in a Docker container. To get started, download, install, and run Docker Desktop from the [official website](https://www.docker.com/). Follow the installation instructions specific to your operating system. -The response time from Ollama depends on your GPU. If you find that default resilience timout of 10 seconds used by .NET Aspire is timing out for the HTTP call from the web app to the Ollama service, you can update the web app's `Program.cs` to extend the timeout by adding the following below the line which reads `builder.AddServiceDefaults();`: - +The response time from Ollama depends on your GPU. If you find that default resilience timeout of 10 seconds used by .NET Aspire is timing out for the HTTP call from the web app to the Ollama service, you can update the web app's `Program.cs` to extend the timeout by adding the following below the line which reads `builder.AddServiceDefaults();`: ```csharp // Extend the HTTP Client timeout for Ollama builder.Services.ConfigureHttpClientDefaults(http => From 5ce81b6dfdfd3781fc6918ec7848686dee948c16 Mon Sep 17 00:00:00 2001 From: Jon Galloway Date: Tue, 8 Apr 2025 15:31:27 -0700 Subject: [PATCH 3/3] Update src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md Co-authored-by: Mackinnon Buck --- .../src/ChatWithCustomData/README.Aspire.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md b/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md index 6fcdf2d4a9b..d3891eda86e 100644 --- a/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md +++ b/src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/README.Aspire.md @@ -80,8 +80,8 @@ builder.Services.ConfigureHttpClientDefaults(http => http.AddStandardResilienceHandler(config => { config.AttemptTimeout.Timeout = TimeSpan.FromMinutes(3); - config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(3) * 3; - config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(3); + config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(10); // must be at least double the AttemptTimeout to pass options validation + config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(10); }); #pragma warning restore EXTEXP0001 });