Skip to content

Instantly share code, notes, and snippets.

@amul047
Created July 4, 2024 22:25
Show Gist options
  • Save amul047/1407422842b71fe5d92e1a7003750632 to your computer and use it in GitHub Desktop.
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`
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