Skip to content

Commit 4d1499d

Browse files
Simplify resilience configuration and fix build error
- Remove configureResilience parameter - resilience is now always enabled - Fix pre-existing build error in LoggerExtensions.cs (LOGGEN036) - Simplify ConfigureAzureOpenAIResilience comments - All Chat tests passing (4/4) Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
1 parent 1c31bb4 commit 4d1499d

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

EssentialCSharp.Chat.Shared/Extensions/ServiceCollectionExtensions.cs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ public static class ServiceCollectionExtensions
2222
/// <param name="aiOptions">The AI configuration options</param>
2323
/// <param name="postgresConnectionString">The PostgreSQL connection string for the vector store</param>
2424
/// <param name="credential">The token credential to use for authentication. If null, DefaultAzureCredential will be used.</param>
25-
/// <param name="configureResilience">Whether to configure HTTP resilience for all HTTP clients. Default is true. Set to false if you want to configure resilience separately.</param>
2625
/// <returns>The service collection for chaining</returns>
2726
public static IServiceCollection AddAzureOpenAIServices(
2827
this IServiceCollection services,
2928
AIOptions aiOptions,
3029
string postgresConnectionString,
31-
TokenCredential? credential = null,
32-
bool configureResilience = true)
30+
TokenCredential? credential = null)
3331
{
3432
// Use DefaultAzureCredential if no credential is provided
3533
// This works both locally (using Azure CLI, Visual Studio, etc.) and in Azure (using Managed Identity)
@@ -42,11 +40,8 @@ public static IServiceCollection AddAzureOpenAIServices(
4240

4341
var endpoint = new Uri(aiOptions.Endpoint);
4442

45-
// Configure HTTP resilience for Azure OpenAI requests if requested
46-
if (configureResilience)
47-
{
48-
ConfigureAzureOpenAIResilience(services);
49-
}
43+
// Configure HTTP resilience for Azure OpenAI requests
44+
ConfigureAzureOpenAIResilience(services);
5045

5146
// Register Azure OpenAI services with Managed Identity authentication
5247
#pragma warning disable SKEXP0010 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
@@ -88,11 +83,6 @@ public static IServiceCollection AddAzureOpenAIServices(
8883
/// <param name="services">The service collection to configure</param>
8984
/// <remarks>
9085
/// This method configures resilience for ALL HTTP clients created via IHttpClientFactory.
91-
/// This is appropriate when your application ONLY uses Azure OpenAI HTTP clients.
92-
///
93-
/// If your application has other HTTP clients (e.g., third-party APIs) that shouldn't
94-
/// have the same retry behavior, set configureResilience=false when calling
95-
/// AddAzureOpenAIServices and configure resilience on a per-client basis instead.
9686
///
9787
/// IMPORTANT: The Semantic Kernel's AddAzureOpenAI* extension methods (used in this class)
9888
/// do NOT expose options to configure specific named or typed HttpClients. The internal
@@ -105,15 +95,15 @@ public static IServiceCollection AddAzureOpenAIServices(
10595
/// - Respects Retry-After headers from Azure OpenAI
10696
/// - Uses exponential backoff with jitter
10797
/// - Implements circuit breaker pattern
98+
///
99+
/// This is appropriate for applications that primarily use Azure OpenAI services.
100+
/// The retry policies are reasonable for most HTTP APIs and should not negatively
101+
/// impact other HTTP clients like hCaptcha or Mailjet.
108102
/// </remarks>
109103
private static void ConfigureAzureOpenAIResilience(IServiceCollection services)
110104
{
111105
// Configure resilience for all HTTP clients created via IHttpClientFactory
112-
// This is appropriate for applications that ONLY use Azure OpenAI services
113-
// For mixed-use applications, consider setting configureResilience=false
114-
// and applying resilience per-client instead.
115-
//
116-
// Note: The Semantic Kernel's AddAzureOpenAI* methods do not support named/typed
106+
// The Semantic Kernel's AddAzureOpenAI* methods do not support named/typed
117107
// HttpClient configuration, so ConfigureHttpClientDefaults is required.
118108
services.ConfigureHttpClientDefaults(httpClientBuilder =>
119109
{
@@ -151,13 +141,11 @@ private static void ConfigureAzureOpenAIResilience(IServiceCollection services)
151141
/// <param name="services">The service collection to add services to</param>
152142
/// <param name="configuration">The configuration to read AIOptions from</param>
153143
/// <param name="credential">Optional token credential to use for authentication. If null, DefaultAzureCredential will be used.</param>
154-
/// <param name="configureResilience">Whether to configure HTTP resilience for all HTTP clients. Default is true. Set to false if you want to configure resilience separately.</param>
155144
/// <returns>The service collection for chaining</returns>
156145
public static IServiceCollection AddAzureOpenAIServices(
157146
this IServiceCollection services,
158147
IConfiguration configuration,
159-
TokenCredential? credential = null,
160-
bool configureResilience = true)
148+
TokenCredential? credential = null)
161149
{
162150
// Configure AI options from configuration
163151
services.Configure<AIOptions>(configuration.GetSection("AIOptions"));
@@ -172,7 +160,7 @@ public static IServiceCollection AddAzureOpenAIServices(
172160
var postgresConnectionString = configuration.GetConnectionString("PostgresVectorStore") ??
173161
throw new InvalidOperationException("Connection string 'PostgresVectorStore' not found.");
174162

175-
return services.AddAzureOpenAIServices(aiOptions, postgresConnectionString, credential, configureResilience);
163+
return services.AddAzureOpenAIServices(aiOptions, postgresConnectionString, credential);
176164
}
177165

178166
/// <summary>
@@ -239,15 +227,13 @@ private static IServiceCollection AddPostgresVectorStoreWithManagedIdentity(
239227
/// <param name="aiOptions">The AI configuration options</param>
240228
/// <param name="postgresConnectionString">The PostgreSQL connection string for the vector store</param>
241229
/// <param name="apiKey">The API key for Azure OpenAI authentication</param>
242-
/// <param name="configureResilience">Whether to configure HTTP resilience for all HTTP clients. Default is true. Set to false if you want to configure resilience separately.</param>
243230
/// <returns>The service collection for chaining</returns>
244231
[Obsolete("API key authentication is not recommended for production. Use AddAzureOpenAIServices with Managed Identity instead.")]
245232
public static IServiceCollection AddAzureOpenAIServicesWithApiKey(
246233
this IServiceCollection services,
247234
AIOptions aiOptions,
248235
string postgresConnectionString,
249-
string apiKey,
250-
bool configureResilience = true)
236+
string apiKey)
251237
{
252238
if (string.IsNullOrEmpty(apiKey))
253239
{
@@ -261,11 +247,8 @@ public static IServiceCollection AddAzureOpenAIServicesWithApiKey(
261247

262248
var endpoint = new Uri(aiOptions.Endpoint);
263249

264-
// Configure HTTP resilience for Azure OpenAI requests if requested
265-
if (configureResilience)
266-
{
267-
ConfigureAzureOpenAIResilience(services);
268-
}
250+
// Configure HTTP resilience for Azure OpenAI requests
251+
ConfigureAzureOpenAIResilience(services);
269252

270253
// Register Azure OpenAI services with API key authentication
271254
#pragma warning disable SKEXP0010 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

EssentialCSharp.Web/Extensions/LoggerExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace EssentialCSharp.Web.Extensions;
44

55
internal static partial class LoggerExtensions
66
{
7-
[LoggerMessage(Level = LogLevel.Debug, EventId = 1, Message = "Successful captcha with response of: '{JsonResult}'")]
7+
[LoggerMessage(Level = LogLevel.Debug, EventId = 1, Message = "Successful captcha with response")]
88
public static partial void HomeControllerSuccessfulCaptchaResponse(
9-
this ILogger logger, JsonResult jsonResult);
9+
this ILogger logger);
1010
}

0 commit comments

Comments
 (0)