Back to contents

Chapter 2A

Code Execution Requirements

Static reading edition generated from the Code Execution Requirements notebook.

Workshop (Setup) - Code Execution Requirements

📝 Note: A configuration setup will be repeated throughout each of the notebook scenarios. This will ensure notebooks are re-runnable from beginning to end; not requiring previous notebook outputs. This allows the user of the Decision Intelligence Workshop to consume as they like, by jumping around between decision intelligence scenarios and not having to start from the beginning each time.


Step 1 - Configuration Builder

In this step Microsoft NuGet packages are installed, so that you can create access to your resources using API keys. These keys should be protected and not checked in. Therefore, the secrets.settings.json is ignored in the .gitignore file. This is the place you should add the API key information.

You will need either of the tested AI providers:

  • Azure OpenAI - Model Deployment Name, Endpoint URL and the API Key
  • OpenAI - Model Id, OpenAI API Key

The tested AI models for this course on the Azure OpenAI or OpenAI platforms are:

  • OpenAI GPT-5.x-mini (for speed/accuracy/cost performance balance)
  • GPT-5.x-mini (for accuracy performance optimization)

📝 Note: As of creation of this workshop, GPT-5-mini & GPT-5.2 are the latest versions. Most of the decision-making exercises will use GPT-5-mini. Other open-source models or older OpenAI models may not support some of the advanced features like reasoning & advanced function calling.

Use the local.settings.json template to create the secrets.settings.json

{
  "AzureOpenAI": {
    "Endpoint": "https://YOURENDPOINT.openai.azure.com",
    "APIKey": "AZUREOPENAIAPIKEY",
    "ModelDeploymentName": "MODELDEPLOYMENTNAME",

    "reasoningEndpoint": "https://YOURENDPOINT.openai.azure.com",
    "reasoningAPIKey": "AZUREOPENAIAPIKEY",
    "reasoningModelDeploymentName": "MODELDEPLOYMENTNAME",

  },
  "OpenAI": {
    "APIKey": "OPENAIAPIKEY",
    "ModelId": "MODELID"
  }
}
In [1]:
// Run this cell to see information about the Polyglot Notebook environment
#!about 

.NET Interactive

© 2020-2025 Microsoft Corporation

Version: 1.0.712001+df4e5cbcbe1b5d0ea85247226b7b896765a54611

Library version: 1.0.0-beta.26120.1+df4e5cbcbe1b5d0ea85247226b7b896765a54611

https://github.com/dotnet/interactive

In [2]:
// Import the required NuGet configuration packages
#r "nuget: Microsoft.Extensions.Configuration, 10.0.8"
#r "nuget: Microsoft.Extensions.Configuration.Json, 10.0.8"

using Microsoft.Extensions.Configuration.Json;
using Microsoft.Extensions.Configuration;
using System.IO;

// Load the configuration settings from the local.settings.json and secrets.settings.json files
// The secrets.settings.json file is used to store sensitive information such as API keys
var configurationBuilder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
    .AddJsonFile("secrets.settings.json", optional: true, reloadOnChange: true);
var config = configurationBuilder.Build();

// IMPORTANT: You ONLY NEED either Azure OpenAI or OpenAI connectiopn info, not both.
// Azure OpenAI Connection Info
var azureOpenAIEndpoint = config["AzureOpenAI:Endpoint"];
var azureOpenAIAPIKey = config["AzureOpenAI:APIKey"];
var azureOpenAIModelDeploymentName = config["AzureOpenAI:ModelDeploymentName"];
// OpenAI Connection Info 
var openAIAPIKey = config["OpenAI:APIKey"];
var openAIModelId = config["OpenAI:ModelId"];
Installed Packages
  • Microsoft.Extensions.Configuration, 10.0.8
  • Microsoft.Extensions.Configuration.Json, 10.0.8

Step 2 - Test Secrets Configuration

If the keys were properly entered in the JSON file, they should be available to be loaded.

Note: If you run the cell, ensure to clear out the output not to cache nor persist any API keys in the output.

In [3]:
var azureOpenAIEndpoint = config["AzureOpenAI:Endpoint"];
var azureOpenAIAPIKey = config["AzureOpenAI:APIKey"];
var azureOpenAIModelDeploymentName = config["AzureOpenAI:ModelDeploymentName"];

// Test the configuration, You should see the values in the Polyglot Notebook output

// Uncomment the relevant lines to view the configuration settings
// Console.WriteLine(azureOpenAIEndpoint);
// Console.WriteLine(azureOpenAIAPIKey);
// Console.WriteLine(azureOpenAIModelDeploymentName);
// Console.WriteLine(config["OpenAI:APIKey"]);
// Console.WriteLine(config["OpenAI:ModelId"]);

Step 3 - Install & Instantiate Microsoft Extensions AI

This is just a test to show the installation some Microsoft Extensions AI packages. Note that Microsoft Extensions AI includes a variety of packages with different release state lifecycles. Executing the cell below should be error free if the configurations are set up correctly.

Note: Some packages are in alpha state or even experimental. These packages may eventually be made available and supported, but should be considered not ready for production.

In [4]:
// Import the Microdoft Extensions AI NuGet Packages
#r "nuget: Microsoft.Extensions.AI, 10.5.0"
#r "nuget: Microsoft.Extensions.AI.Abstractions, 10.5.0"
#r "nuget: Microsoft.Extensions.AI.OpenAI, 10.5.0"
// Import Azure & OpenAI NuGet Packages
#r "nuget: Azure.AI.OpenAI, 2.9.0-beta.1"
#r "nuget: Azure.Identity, 1.21.0"
#r "nuget: OpenAI, 2.10.0"

using Azure;
using Azure.AI.OpenAI;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using OpenAI.Chat;
using System.ClientModel;
using System.ComponentModel;
using System.Runtime.InteropServices;

var apiKeyCredential = new ApiKeyCredential(azureOpenAIAPIKey);
var azureOpenAIClientOptions = new AzureOpenAIClientOptions(AzureOpenAIClientOptions.ServiceVersion.V2025_04_01_Preview);

// #pragma warning disable OPENAI001
var azureOpenAIClient =
    new AzureOpenAIClient(new Uri(azureOpenAIEndpoint), apiKeyCredential, azureOpenAIClientOptions);

#pragma warning disable OPENAI001
var azureOpenAIChatClient = azureOpenAIClient.GetChatClient(azureOpenAIModelDeploymentName).AsIChatClient();

Console.WriteLine("""
Code execution has made it this far, therefore the Microsoft AI NuGet packages appear to be correctly installed.
"""); 

// Display information about the .NET runtime environment
string frameworkDescription = RuntimeInformation.FrameworkDescription;
Console.WriteLine($"The application is running on: {frameworkDescription}");
Installed Packages
  • Azure.AI.OpenAI, 2.9.0-beta.1
  • Azure.Identity, 1.21.0
  • Microsoft.Extensions.AI, 10.5.0
  • Microsoft.Extensions.AI.Abstractions, 10.5.0
  • Microsoft.Extensions.AI.OpenAI, 10.5.0
  • OpenAI, 2.10.0
Code execution has made it this far, therefore the Microsoft AI NuGet packages appear to be correctly installed.
The application is running on: .NET 10.0.7
warning CS1701: Assuming assembly reference 'System.ClientModel, Version=1.9.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' used by 'Azure.AI.OpenAI' matches identity 'System.ClientModel, Version=1.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' of 'System.ClientModel', you may need to supply runtime policy

warning CS1701: Assuming assembly reference 'System.ClientModel, Version=1.9.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' used by 'Azure.AI.OpenAI' matches identity 'System.ClientModel, Version=1.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' of 'System.ClientModel', you may need to supply runtime policy

warning CS1701: Assuming assembly reference 'OpenAI, Version=2.9.1.0, Culture=neutral, PublicKeyToken=b4187f3e65366280' used by 'Azure.AI.OpenAI' matches identity 'OpenAI, Version=2.10.0.0, Culture=neutral, PublicKeyToken=b4187f3e65366280' of 'OpenAI', you may need to supply runtime policy

warning CS1701: Assuming assembly reference 'System.ClientModel, Version=1.9.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' used by 'Azure.AI.OpenAI' matches identity 'System.ClientModel, Version=1.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' of 'System.ClientModel', you may need to supply runtime policy

warning CS1701: Assuming assembly reference 'OpenAI, Version=2.9.1.0, Culture=neutral, PublicKeyToken=b4187f3e65366280' used by 'Azure.AI.OpenAI' matches identity 'OpenAI, Version=2.10.0.0, Culture=neutral, PublicKeyToken=b4187f3e65366280' of 'OpenAI', you may need to supply runtime policy

📌 Note:
This workshop will use certain conventions to balance readability as well as interactivity of the content. For example, Markdown rendering will be used for output, but can be turned off to make the content streamable. You can use alternative AI models, OSS packages to add aditional capabilities to enhance exercises.