Skip to content

Commit

Permalink
Fixed AI log level configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-kondratov committed Aug 15, 2024
1 parent 94c82e5 commit 38b945e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Serilog;

namespace PillsBot.Server.Configuration
{
Expand All @@ -24,7 +26,9 @@ public static IServiceCollection AddPillsBot(this IServiceCollection services, I
{
AIOptions.AzureOpenAIOptions options = provider.GetRequiredService<IOptions<PillsBotOptions>>().Value.AI.Azure;

return new AzureOpenAIChatCompletionService(options.DeploymentName, options.Endpoint, options.Key);
return new AzureOpenAIChatCompletionService(options.DeploymentName, options.Endpoint, options.Key,
loggerFactory: new LoggerFactory()
.AddSerilog(provider.GetRequiredService<Serilog.ILogger>()));
})
.AddSingleton<AzureOpenAIMessageProvider>()
.AddTransient<ConfigurationMessageProvider>()
Expand Down
2 changes: 2 additions & 0 deletions src/PillsBot/PillsBot.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using PillsBot.Server.Configuration;
using Serilog;
using Serilog.Events;
Expand Down Expand Up @@ -39,6 +40,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) => Host
.AddPillsBot(context.Configuration.GetSection("PillsBot")))
.UseSerilog((context, services, configuration) => configuration
.MinimumLevel.Is(context.HostingEnvironment.IsDevelopment() ? LogEventLevel.Debug : LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.SemanticKernel", (LogEventLevel) services.GetRequiredService<IOptions<PillsBotOptions>>().Value.AI.LogLevel)
.Enrich.FromLogContext()
.Enrich.WithProperty("Environment", context.HostingEnvironment.EnvironmentName)
.Enrich.WithProperty("Version", typeof(Program).Assembly.GetName().Version.ToString(3), true)
Expand Down

0 comments on commit 38b945e

Please sign in to comment.