I am going through the exercises in a great lab series on Generative AI in .NET. I chose the Azure AI Foundry path in which I deploy chatgpt-40-mini model and talk to it. I was struck to discover I could get results in only this amount of code.
using System.ClientModel;
using Azure.AI.OpenAI;
using Microsoft.Extensions.AI;
var deploymentName = "gpt-4o-mini";
var endpoint = new Uri("https://david-XXXXXXX-eastus2.openai.azure.com/");
var azureAiSecret = Environment.GetEnvironmentVariable("AZURE_AI_SECRET") ??
throw new InvalidOperationException("Missing AZURE_AI_SECRET environment variable.");
var apiKey = new ApiKeyCredential(azureAiSecret);
IChatClient client = new AzureOpenAIClient(endpoint, apiKey)
.AsChatClient(deploymentName);
var response = await client.GetResponseAsync("What is AI? Explain in one sentence.");
Console.WriteLine(response.Message);
Nothing amazing here, just marveling at the ease with which this worked.
It’s a really well done set of labs. Highly recommended.