Skip to content

Commit

Permalink
Get model name from connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSandersonMS committed May 27, 2024
1 parent d2b378e commit a00d258
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Azure.AI.OpenAI;
using System.Data.Common;
using Azure.AI.OpenAI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
Expand All @@ -18,11 +20,17 @@ public static void AddChatCompletionService(this IHostApplicationBuilder builder
{
builder.AddAzureOpenAIClient(name);

var deploymentName = "gpt-35-1106"; // TODO: Get from connection string
var connectionStringBuilder = new DbConnectionStringBuilder();
connectionStringBuilder.ConnectionString = builder.Configuration.GetConnectionString(name);
if (!connectionStringBuilder.TryGetValue("Deployment", out var deploymentName))
{
throw new InvalidOperationException($"The connection string named '{name}' does not specify a value for 'Deployment', but this is required.");
}

builder.Services.AddScoped<IChatCompletionService>(services =>
{
var client = services.GetRequiredService<OpenAIClient>();
return new AzureOpenAIChatCompletionService(deploymentName, client);
return new AzureOpenAIChatCompletionService((string)deploymentName, client);
});
}
}
Expand Down

0 comments on commit a00d258

Please sign in to comment.