|
51 | 51 | builder.Services.AddScoped<DataIngestor>(); |
52 | 52 | builder.Services.AddSingleton<SemanticSearch>(); |
53 | 53 | #if (IsOllama) |
54 | | -// Get the IHttpClientBuilder for chat_httpClient |
55 | | -var chatClientBuilder = builder.Services.AddHttpClient("chat_httpClient"); |
56 | | -#pragma warning disable EXTEXP0001 // RemoveAllResilienceHandlers is experimental |
57 | | -chatClientBuilder.RemoveAllResilienceHandlers(); |
58 | | -#pragma warning restore EXTEXP0001 |
59 | | -// Override resilience for this client |
60 | | -chatClientBuilder.AddStandardResilienceHandler(config => |
61 | | -{ |
62 | | - // Extend the HTTP Client timeout for Ollama |
63 | | - config.AttemptTimeout.Timeout = TimeSpan.FromMinutes(3); |
64 | | - // Must be at least double the AttemptTimeout to pass options validation |
65 | | - config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(10); |
66 | | - config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(10); |
67 | | -}); |
68 | | -chatClientBuilder.AddServiceDiscovery(); |
69 | | -// Get the IHttpClientBuilder for embeddings_httpClient |
70 | | -var embeddingsClientBuilder = builder.Services.AddHttpClient("embeddings_httpClient"); |
71 | | -#pragma warning disable EXTEXP0001 // RemoveAllResilienceHandlers is experimental |
72 | | -embeddingsClientBuilder.RemoveAllResilienceHandlers(); |
73 | | -#pragma warning restore EXTEXP0001 |
74 | | -// Override resilience for this client |
75 | | -embeddingsClientBuilder.AddStandardResilienceHandler(config => |
76 | | -{ |
77 | | - // Extend the HTTP Client timeout for Ollama |
78 | | - config.AttemptTimeout.Timeout = TimeSpan.FromMinutes(3); |
79 | | - // Must be at least double the AttemptTimeout to pass options validation |
80 | | - config.CircuitBreaker.SamplingDuration = TimeSpan.FromMinutes(10); |
81 | | - config.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(10); |
82 | | -}); |
83 | | -embeddingsClientBuilder.AddServiceDiscovery(); |
| 54 | +// Applies robust HTTP resilience settings for all HttpClients in the Web project, |
| 55 | +// not across the entire solution. It's aimed at supporting Ollama scenarios due |
| 56 | +// to its self-hosted nature and potentially slow responses. |
| 57 | +// Remove this if you want to use the global or a different HTTP resilience policy instead. |
| 58 | +builder.Services.AddOllamaHttpClientResilience(); |
84 | 59 | #endif |
85 | 60 |
|
86 | 61 | var app = builder.Build(); |
|
0 commit comments