In this post, we will show how to build AI applications using Azure AI Foundry and the benefits of using the SDK for Foundry.
Introduction
The world of Artificial Intelligence (AI) is expanding rapidly, and businesses are increasingly seeking ways to leverage this technology to gain a competitive edge. One powerful tool in this space is Azure Foundry AI. Designed to simplify the integration of AI into various business processes, Azure Foundry AI is a game-changer for companies looking to innovate and streamline their operations.
What is Azure AI Foundry
Azure AI Foundry is a comprehensive platform on Microsoft Azure designed to streamline AI solution development by providing centralized project organization, resource management, and advanced development tools.
It offers a web-based interface (Azure AI Foundry portal) for managing AI projects efficiently, along with an Azure AI Foundry SDK for programmatic solution development. The platform is structured around hubs and projects:
- Hubs: Top-level containers managing shared resources, data, and security configurations.
- Projects: Subsections within hubs, facilitating collaborative AI solution development.
- Role Inheritance: Ensures seamless collaboration by inheriting permissions and resources from hubs to projects.
This hierarchical organization helps maintain efficient resource utilization while promoting secure collaboration.
Within Azure AI Foundry, hubs include essential Azure AI resources, such as Azure AI services, Key Vaults, and storage accounts. Projects under these hubs benefit from powerful tools, including:
- Model Catalog: Machine learning models from Azure OpenAI, Hugging Face, and other sources.
- Interactive Playgrounds: Experiment with generative AI models in a hands-on environment.
- Model Fine-Tuning: Customize AI models with specific datasets.
- Prompt Flow: Orchestrate AI interactions efficiently.
- Development Environments: Integrated Visual Studio Code containers for coding and testing.
- AI Assessments: Tools for tracing, evaluation, and content safety management.
This cohesive ecosystem allows developers to build, test, and deploy AI solutions effectively within a unified framework.
Getting Started with the Azure Foundry AI SDK
The Azure Foundry AI Software Development Kit (SDK) is a powerful tool that allows developers to build and deploy AI models quickly and efficiently.
Below, is a step-by-step guide to help you get started with the SDK for .NET using a C# console application
Step 1: Setting Up Your Environment
Before you can start using the Azure Foundry AI SDK, you need to set up your development environment. This involves creating a C# Console application and installing the necessary software and configuring your Azure account.
- Set Up Your Azure Account: If you don’t already have an Azure account, you will need to create one. You can sign up for a free account, which provides access to a range of Azure services at no cost for the first 12 months.
- Create a Hub, project and Azure OpenAI service (https://ai.azure.com)
- Install the SDK: You can install the Azure Foundry AI SDK and related packages using the following:
dotnet add package Azure.AI.Projects --prerelease
dotnet add package Azure.Identity
dotnet add package Azure.AI.TextAnalytics
dotnet add package Azure.AI.Inference
Copy Connection String
The initial step in most Azure AI Foundry SDK code involves connecting to an Azure AI Foundry project. Each project possesses a unique connection string, which is available on the project’s Overview page in the Azure AI Foundry portal.

Code
Once you have installed the necessary packages and copied the connection string, you can proceed by adding the following code snippet to your application. This code snippet demonstrates how to set up the connection to your Azure AI Foundry project and initialize the necessary services.
Make sure to replace the placeholder in line 3 with your actual connection string. Additionally, in line 29, insert the name of your GPT model, which can be found under the Model + endpoints section in the Azure AI Foundry portal.
using System;
using Azure;
using Azure.AI.Projects;
using Azure.Identity;
using Azure.AI.Inference;
namespace foundrySDK
{
class Program
{
static void Main(string[] args)
{
try
{
// Initialize the project client with the connection string and default Azure credentials
var connectionString = "Connection String Goes here ";
var projectClient = new AIProjectClient(connectionString, new DefaultAzureCredential());
// Get a chat completions client from the project client
ChatCompletionsClient chatClient = projectClient.GetChatCompletionsClient();
// Prompt the user to enter a question
Console.WriteLine("Enter a question:");
var userPrompt = Console.ReadLine();
// Create chat completions options with the specified model and messages
var requestOptions = new ChatCompletionsOptions()
{
Model = "gpt-4o",
Messages =
{
new ChatRequestSystemMessage("You are a helpful AI assistant that answers questions."),
new ChatRequestUserMessage(userPrompt),
}
};
// Get a chat completion response based on the user-provided prompt
Response<ChatCompletions> response = chatClient.Complete(requestOptions);
// Output the response content to the console
Console.WriteLine(response.Value.Content);
}
catch (Exception ex)
{
// Output any exceptions to the console
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
}
Run Program
After handling exceptions, you can run the C# console application to test the integration and functionality of your AI-powered solutions.
The program’s output is displayed below.
Enter a question:
Where does Paris located
Paris is the capital city of **France**, located in the north-central part of the country. It lies along the **Seine River**, and its geographic coordinates are approximately **48.8566° N latitude** and **2.3522° E longitude**. Paris is one of the most iconic cities in the world, known for its cultural landmarks, such as the Eiffel Tower, Louvre Museum, and Notre-Dame Cathedral.
Conclusion
Azure Foundry AI offers a powerful and flexible platform for integrating AI into your business processes.
By leveraging the capabilities of the Azure Foundry AI SDK, managers can drive innovation and efficiency within their organizations. Whether you are new to AI or an experienced developer, the tools and resources provided by Azure Foundry AI make it easier than ever to harness the power of Artificial Intelligence.
Follow this guide to start using Azure Foundry AI and transform your business with advanced AI technology.
Discover more from CPI Consulting Pty Ltd Experts in Cloud, AI and Cybersecurity
Subscribe to get the latest posts sent to your email.