Skip to content

Instantly share code, notes, and snippets.

@amul047
Last active July 4, 2024 02:41
Show Gist options
  • Save amul047/f9821c1a834c2a86434c6e4dde7a5e18 to your computer and use it in GitHub Desktop.
Save amul047/f9821c1a834c2a86434c6e4dde7a5e18 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`
using Azure;
using Azure.AI.OpenAI;
var prompt = "..";
var azureOpenaiEndpoint = "https://...openai.azure.com/";
var azureOpenaiApiKey= "..";
var azureOpenAiDeploymentName = "..";
var azureSearchApiKey= "..";
var azureSearchEndpoint = "https://...search.windows.net";
var azureSearchIndexName = "..";
var openAiClient = new OpenAIClient(new Uri(azureOpenaiEndpoint), new AzureKeyCredential(azureOpenaiApiKey));
var chatCompletions = openAiClient.GetChatCompletions(new ChatCompletionsOptions
{
DeploymentName = azureOpenAiDeploymentName,
Messages =
{
new ChatRequestUserMessage(prompt),
},
AzureExtensionsOptions = new AzureChatExtensionsOptions
{
Extensions =
{
new AzureSearchChatExtensionConfiguration
{
Authentication = new OnYourDataApiKeyAuthenticationOptions(azureSearchApiKey),
SearchEndpoint = new Uri(azureSearchEndpoint),
IndexName = azureSearchIndexName,
}
}
}
});
Console.WriteLine(chatCompletions.Value.Choices.First().Message.Content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment