Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.

using Azure.AI.OpenAI;
using Azure.AI.OpenAI.Chat;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using xRetry;

namespace ChatCompletion;
Expand Down Expand Up @@ -47,8 +47,8 @@ public async Task ExampleWithChatCompletionAsync()
chatHistory.AddUserMessage(ask);

// Chat Completion example
var chatExtensionsOptions = GetAzureChatExtensionsOptions();
var promptExecutionSettings = new OpenAIPromptExecutionSettings { AzureChatExtensionsOptions = chatExtensionsOptions };
var dataSource = GetAzureSearchDataSource();
var promptExecutionSettings = new AzureOpenAIPromptExecutionSettings { AzureChatDataSource = dataSource };

var chatCompletion = kernel.GetRequiredService<IChatCompletionService>();

Expand Down Expand Up @@ -98,8 +98,8 @@ public async Task ExampleWithKernelAsync()

var function = kernel.CreateFunctionFromPrompt("Question: {{$input}}");

var chatExtensionsOptions = GetAzureChatExtensionsOptions();
var promptExecutionSettings = new OpenAIPromptExecutionSettings { AzureChatExtensionsOptions = chatExtensionsOptions };
var dataSource = GetAzureSearchDataSource();
var promptExecutionSettings = new AzureOpenAIPromptExecutionSettings { AzureChatDataSource = dataSource };

// First question without previous context based on uploaded content.
var response = await kernel.InvokeAsync(function, new(promptExecutionSettings) { ["input"] = ask });
Expand All @@ -125,20 +125,15 @@ public async Task ExampleWithKernelAsync()
}

/// <summary>
/// Initializes a new instance of the <see cref="AzureOpenAIChatCompletionWithDataConfig"/> class.
/// Initializes a new instance of the <see cref="AzureSearchChatDataSource"/> class.
/// </summary>
private static AzureChatExtensionsOptions GetAzureChatExtensionsOptions()
private static AzureSearchChatDataSource GetAzureSearchDataSource()
{
var azureSearchExtensionConfiguration = new AzureSearchChatExtensionConfiguration
return new AzureSearchChatDataSource
{
SearchEndpoint = new Uri(TestConfiguration.AzureAISearch.Endpoint),
Authentication = new OnYourDataApiKeyAuthenticationOptions(TestConfiguration.AzureAISearch.ApiKey),
Endpoint = new Uri(TestConfiguration.AzureAISearch.Endpoint),
Authentication = DataSourceAuthentication.FromApiKey(TestConfiguration.AzureAISearch.ApiKey),
IndexName = TestConfiguration.AzureAISearch.IndexName
};

return new AzureChatExtensionsOptions
{
Extensions = { azureSearchExtensionConfiguration }
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using Microsoft.SemanticKernel.Connectors.OpenAI;

namespace ChatCompletion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using Microsoft.SemanticKernel.Connectors.OpenAI;

namespace ChatCompletion;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using Microsoft.SemanticKernel.Connectors.OpenAI;

namespace ChatCompletion;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.

using System.ClientModel.Primitives;
using Azure;
using Azure.AI.OpenAI;
using Azure.Core.Pipeline;
using Microsoft.SemanticKernel;

namespace ChatCompletion;
Expand All @@ -28,12 +28,12 @@ public async Task RunAsync()
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("My-Custom-Header", "My Custom Value");

// Configure OpenAIClient to use the customized HttpClient
var clientOptions = new OpenAIClientOptions
// Configure AzureOpenAIClient to use the customized HttpClient
var clientOptions = new AzureOpenAIClientOptions
{
Transport = new HttpClientTransport(httpClient),
Transport = new HttpClientPipelineTransport(httpClient),
};
var openAIClient = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(apiKey), clientOptions);
var openAIClient = new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(apiKey), clientOptions);

IKernelBuilder builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(deploymentName, openAIClient);
Expand Down
Loading