Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
"*.sln"
]
},
{
"condition": "(!IsAspire || !IsOllama)",
"exclude": [
"ChatWithCustomData-CSharp.Web/OllamaResilienceHandlerExtensions.cs"
]
},
{
"condition": "(IsAspire)",
"exclude": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@ public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where
http.RemoveAllResilienceHandlers();
#pragma warning restore EXTEXP0001

#if (IsOllama)
// Turn on resilience by default
http.AddStandardResilienceHandler(config =>
{
// Extend the HTTP Client timeout for Ollama
config.AttemptTimeout.Timeout = TimeSpan.FromMinutes(3);

// Must be at least double the AttemptTimeout to pass options validation
config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(10);
config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(10);
});
#else
// Turn on resilience by default
http.AddStandardResilienceHandler();
#endif

// Turn on service discovery by default
http.AddServiceDiscovery();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Microsoft.Extensions.DependencyInjection;

namespace ChatWithCustomData_CSharp.Web.Services;

public static class OllamaResilienceHandlerExtensions
{
public static IServiceCollection AddOllamaResilienceHandler(this IServiceCollection services)
{
services.ConfigureHttpClientDefaults(http =>
{
#pragma warning disable EXTEXP0001 // RemoveAllResilienceHandlers is experimental
http.RemoveAllResilienceHandlers();
#pragma warning restore EXTEXP0001

// Turn on resilience by default
http.AddStandardResilienceHandler(config =>
{
// Extend the HTTP Client timeout for Ollama
config.AttemptTimeout.Timeout = TimeSpan.FromMinutes(3);

// Must be at least double the AttemptTimeout to pass options validation
config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(10);
config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(10);
});

// Turn on service discovery by default
http.AddServiceDiscovery();
});

return services;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
#endif
builder.Services.AddScoped<DataIngestor>();
builder.Services.AddSingleton<SemanticSearch>();
#if (IsOllama)
// Applies robust HTTP resilience settings for all HttpClients in the Web project,
// not across the entire solution. It's aimed at supporting Ollama scenarios due
// to its self-hosted nature and potentially slow responses.
// Remove this if you want to use the global or a different HTTP resilience policy instead.
builder.Services.AddOllamaResilienceHandler();
#endif

var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where
#pragma warning restore EXTEXP0001

// Turn on resilience by default
http.AddStandardResilienceHandler(config =>
{
// Extend the HTTP Client timeout for Ollama
config.AttemptTimeout.Timeout = TimeSpan.FromMinutes(3);

// Must be at least double the AttemptTimeout to pass options validation
config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(10);
config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(10);
});
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.AddServiceDiscovery();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Microsoft.Extensions.DependencyInjection;

namespace aichatweb.Web.Services;

public static class OllamaResilienceHandlerExtensions
{
public static IServiceCollection AddOllamaResilienceHandler(this IServiceCollection services)
{
services.ConfigureHttpClientDefaults(http =>
{
#pragma warning disable EXTEXP0001 // RemoveAllResilienceHandlers is experimental
http.RemoveAllResilienceHandlers();
#pragma warning restore EXTEXP0001

// Turn on resilience by default
http.AddStandardResilienceHandler(config =>
{
// Extend the HTTP Client timeout for Ollama
config.AttemptTimeout.Timeout = TimeSpan.FromMinutes(3);

// Must be at least double the AttemptTimeout to pass options validation
config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(10);
config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(10);
});

// Turn on service discovery by default
http.AddServiceDiscovery();
});

return services;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
builder.Services.AddQdrantCollection<Guid, IngestedDocument>("data-aichatweb-documents");
builder.Services.AddScoped<DataIngestor>();
builder.Services.AddSingleton<SemanticSearch>();
// Applies robust HTTP resilience settings for all HttpClients in the Web project,
// not across the entire solution. It's aimed at supporting Ollama scenarios due
// to its self-hosted nature and potentially slow responses.
// Remove this if you want to use the global or a different HTTP resilience policy instead.
builder.Services.AddOllamaResilienceHandler();

var app = builder.Build();

Expand Down
Loading