Created
July 4, 2024 22:25
-
-
Save amul047/1407422842b71fe5d92e1a7003750632 to your computer and use it in GitHub Desktop.
RAG with `Azure Search` (Retrieval) and (Augmented) `Azure OpenAI` (Generation) using `Microsoft.SemanticKernel.Connectors.OpenAI` `1.15.1` and `Azure.AI.OpenAI` `2.0.0-beta2`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Azure; | |
using Azure.AI.OpenAI; | |
using Azure.AI.OpenAI.Chat; | |
using OpenAI.Chat; | |
var prompt = ".."; | |
var azureOpenaiEndpoint = "https://...openai.azure.com/"; | |
var azureOpenaiApiKey= ".."; | |
var azureOpenAiDeploymentName = ".."; | |
var azureSearchApiKey= ".."; | |
var azureSearchEndpoint = "https://...search.windows.net"; | |
var azureSearchIndexName = ".."; | |
AzureOpenAIClient azureClient = new AzureOpenAIClient(new Uri(azureOpenaiEndpoint), new AzureKeyCredential(azureOpenaiApiKey)); | |
var chatCompletionOptions = new ChatCompletionOptions(); | |
chatCompletionOptions.AddDataSource(new AzureSearchChatDataSource() | |
{ | |
Endpoint = new Uri(azureSearchEndpoint), | |
IndexName = azureSearchIndexName, | |
Authentication = DataSourceAuthentication.FromApiKey(azureSearchApiKey), | |
}); | |
var clientResult = azureClient.GetChatClient(azureOpenAiDeploymentName) | |
.CompleteChat(new[] | |
{ | |
new UserChatMessage(prompt) | |
}, chatCompletionOptions); | |
Console.WriteLine(clientResult.Value.Content[0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment