Skip to content

Commit

Permalink
Copy Files From Source Repo (2024-03-01 16:25)
Browse files Browse the repository at this point in the history
  • Loading branch information
stonezy123 committed Mar 1, 2024
1 parent ac2573a commit 18e3067
Show file tree
Hide file tree
Showing 49 changed files with 1,100 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contributing to Microsoft Learning Repositories

MCT contributions are a key part of keeping the lab and demo content current as the Azure platform changes. We want to make it as easy as possible for you to contribute changes to the lab files. Here are a few guidelines to keep in mind as you contribute changes.

## GitHub Use & Purpose

Microsoft Learning is using GitHub to publish the lab steps and lab scripts for courses that cover cloud services like Azure. Using GitHub allows the course’s authors and MCTs to keep the lab content current with Azure platform changes. Using GitHub allows the MCTs to provide feedback and suggestions for lab changes, and then the course authors can update lab steps and scripts quickly and relatively easily.

> When you prepare to teach these courses, you should ensure that you are using the latest lab steps and scripts by downloading the appropriate files from GitHub. GitHub should not be used to discuss technical content in the course, or how to prep. It should only be used to address changes in the labs.
It is strongly recommended that MCTs and Partners access these materials and in turn, provide them separately to students. Pointing students directly to GitHub to access Lab steps as part of an ongoing class will require them to access yet another UI as part of the course, contributing to a confusing experience for the student. An explanation to the student regarding why they are receiving separate Lab instructions can highlight the nature of an always-changing cloud-based interface and platform. Microsoft Learning support for accessing files on GitHub and support for navigation of the GitHub site is limited to MCTs teaching this course only.

> As an alternative to pointing students directly to the GitHub repository, you can point students to the GitHub Pages website to view the lab instructions. The URL for the GitHub Pages website can be found at the top of the repository.
To address general comments about the course and demos, or how to prepare for a course delivery, please use the existing MCT forums.

## Additional Resources

A user guide has been provided for MCTs who are new to GitHub. It provides steps for connecting to GitHub, downloading and printing course materials, updating the scripts that students use in labs, and explaining how you can help ensure that this course’s content remains current.

<https://microsoftlearning.github.io/MCT-User-Guide/>
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Module: 00
## Lab/Demo: 00
### Task: 00
#### Step: 00

Description of issue

Repro steps:

1.
1.
1.
10 changes: 10 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Module: 00
## Lab/Demo: 00

Fixes # .

Changes proposed in this pull request:

-
-
-
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
obj
21 changes: 21 additions & 0 deletions Labfiles/02-nlp-azure-openai/CSharp/CSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions Labfiles/02-nlp-azure-openai/CSharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Implicit using statements are included
using System.Text;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Azure;

// Add Azure OpenAI package


// Build a config object and retrieve user settings.
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
string? oaiEndpoint = config["AzureOAIEndpoint"];
string? oaiKey = config["AzureOAIKey"];
string? oaiDeploymentName = config["AzureOAIDeploymentName"];

// Read sample text file into a string
string textToSummarize = System.IO.File.ReadAllText(@"../text-files/sample-text.txt");

// Generate summary from Azure OpenAI
GetSummaryFromOpenAI(textToSummarize);

void GetSummaryFromOpenAI(string text)
{
Console.WriteLine("\nSending request for summary to Azure OpenAI endpoint...\n\n");

if(string.IsNullOrEmpty(oaiEndpoint) || string.IsNullOrEmpty(oaiKey) || string.IsNullOrEmpty(oaiDeploymentName) )
{
Console.WriteLine("Please check your appsettings.json file for missing or incorrect values.");
return;
}

// Add code to build request...

}
5 changes: 5 additions & 0 deletions Labfiles/02-nlp-azure-openai/CSharp/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"AzureOAIEndpoint": "",
"AzureOAIKey": "",
"AzureOAIDeploymentName": ""
}
3 changes: 3 additions & 0 deletions Labfiles/02-nlp-azure-openai/Python/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AZURE_OAI_ENDPOINT=
AZURE_OAI_KEY=
AZURE_OAI_DEPLOYMENT=
29 changes: 29 additions & 0 deletions Labfiles/02-nlp-azure-openai/Python/test-openai-model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
from dotenv import load_dotenv

# Add Azure OpenAI package


def main():

try:

# Get configuration settings
load_dotenv()
azure_oai_endpoint = os.getenv("AZURE_OAI_ENDPOINT")
azure_oai_key = os.getenv("AZURE_OAI_KEY")
azure_oai_deployment = os.getenv("AZURE_OAI_DEPLOYMENT")

# Read text from file
text = open(file="../text-files/sample-text.txt", encoding="utf8").read()

print("\nSending request for summary to Azure OpenAI endpoint...\n\n")

# Add code to build request...


except Exception as ex:
print(ex)

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions Labfiles/02-nlp-azure-openai/text-files/sample-text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The process of making maple syrup begins by tapping a spout (sometimes called a spile) into the sugar maple tree. The spile is inserted into the tree about 2 inches deep and the sap is collected as it flows out. The sap is then taken to a sugar shack where it is boiled down to concentrate the sugars. As the sap boils, water in the sap is evaporated and the syrup becomes more and more thick. Once the syrup reaches the right sugar content, which is usually when the boiling point reaches 219 degrees Fahrenheit, it is bottled and enjoyed.
21 changes: 21 additions & 0 deletions Labfiles/03-prompt-engineering/CSharp/CSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
86 changes: 86 additions & 0 deletions Labfiles/03-prompt-engineering/CSharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Implicit using statements are included
using System.Text;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Azure;

// Add Azure OpenAI package

// Build a config object and retrieve user settings.
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
string? oaiEndpoint = config["AzureOAIEndpoint"];
string? oaiKey = config["AzureOAIKey"];
string? oaiDeploymentName = config["AzureOAIDeploymentName"];

string command;
bool printFullResponse = false;

do {
Console.WriteLine("\n1: Basic prompt (no prompt engineering)\n" +
"2: Prompt with email formatting and basic system message\n" +
"3: Prompt with formatting and specifying content\n" +
"4: Prompt adjusting system message to be light and use jokes\n" +
"\"quit\" to exit the program\n\n" +
"Enter a number to select a prompt:");

command = Console.ReadLine() ?? "";

switch (command) {
case "1":
await GetResponseFromOpenAI("../prompts/basic.txt");
break;
case "2":
await GetResponseFromOpenAI("../prompts/email-format.txt");
break;
case "3":
await GetResponseFromOpenAI("../prompts/specify-content.txt");
break;
case "4":
await GetResponseFromOpenAI("../prompts/specify-tone.txt");
break;
case "quit":
Console.WriteLine("Exiting program...");
break;
default:
Console.WriteLine("Invalid input. Please try again.");
break;
}
} while (command != "quit");

async Task GetResponseFromOpenAI(string fileText)
{
Console.WriteLine("\nSending prompt to Azure OpenAI endpoint...\n\n");

if(string.IsNullOrEmpty(oaiEndpoint) || string.IsNullOrEmpty(oaiKey) || string.IsNullOrEmpty(oaiDeploymentName) )
{
Console.WriteLine("Please check your appsettings.json file for missing or incorrect values.");
return;
}

// Configure the Azure OpenAI client

// Read text file into system and user prompts
string[] prompts = System.IO.File.ReadAllLines(fileText);
string systemPrompt = prompts[0].Split(":", 2)[1].Trim();
string userPrompt = prompts[1].Split(":", 2)[1].Trim();

// Write prompts to console
Console.WriteLine("System prompt: " + systemPrompt);
Console.WriteLine("User prompt: " + userPrompt);

// Format and send the request to the model



// Write response full response to console, if requested
if (printFullResponse)
{
Console.WriteLine($"\nFull response: {JsonSerializer.Serialize(completions, new JsonSerializerOptions { WriteIndented = true })}\n\n");
}

// Write response to console
Console.WriteLine($"\nResponse: {completion}\n\n");
}
5 changes: 5 additions & 0 deletions Labfiles/03-prompt-engineering/CSharp/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"AzureOAIEndpoint": "",
"AzureOAIKey": "",
"AzureOAIDeploymentName": ""
}
3 changes: 3 additions & 0 deletions Labfiles/03-prompt-engineering/Python/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AZURE_OAI_ENDPOINT=
AZURE_OAI_KEY=
AZURE_OAI_DEPLOYMENT=
67 changes: 67 additions & 0 deletions Labfiles/03-prompt-engineering/Python/prompt-engineering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
from dotenv import load_dotenv

# Add Azure OpenAI package

# Set to True to print the full response from OpenAI for each call
printFullResponse = False

def main():

try:

# Get configuration settings
load_dotenv()
azure_oai_endpoint = os.getenv("AZURE_OAI_ENDPOINT")
azure_oai_key = os.getenv("AZURE_OAI_KEY")
azure_oai_deployment = os.getenv("AZURE_OAI_DEPLOYMENT")

# Configure the Azure OpenAI client


while True:
print('1: Basic prompt (no prompt engineering)\n' +
'2: Prompt with email formatting and basic system message\n' +
'3: Prompt with formatting and specifying content\n' +
'4: Prompt adjusting system message to be light and use jokes\n' +
'\'quit\' to exit the program\n')
command = input('Enter a number:')
if command == '1':
call_openai_model(messages="../prompts/basic.txt", model=azure_oai_deployment, client=client)
elif command =='2':
call_openai_model(messages="../prompts/email-format.txt", model=azure_oai_deployment, client=client)
elif command =='3':
call_openai_model(messages="../prompts/specify-content.txt", model=azure_oai_deployment, client=client)
elif command =='4':
call_openai_model(messages="../prompts/specify-tone.txt", model=azure_oai_deployment, client=client)
elif command.lower() == 'quit':
print('Exiting program...')
break
else :
print("Invalid input. Please try again.")

except Exception as ex:
print(ex)

def call_openai_model(messages, model, client):
# In this sample, each file contains both the system and user messages
# First, read them into variables, strip whitespace, then build the messages array
file = open(file=messages, encoding="utf8")
system_message = file.readline().split(':', 1)[1].strip()
user_message = file.readline().split(':', 1)[1].strip()

# Print the messages to the console
print("System message: " + system_message)
print("User message: " + user_message)

# Format and send the request to the model



if printFullResponse:
print(response)

print("Completion: \n\n" + response.choices[0].message.content + "\n")

if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions Labfiles/03-prompt-engineering/prompts/basic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System:You are an AI assistant
Prompt:Write an intro for a new wildlife Rescue
2 changes: 2 additions & 0 deletions Labfiles/03-prompt-engineering/prompts/email-format.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System:You are an AI assistant helping to write emails
Prompt:Write a promotional email for a new wildlife rescue, including the following: - Rescue name is Contoso - It specializes in elephants - Call for donations to be given at our website
2 changes: 2 additions & 0 deletions Labfiles/03-prompt-engineering/prompts/specify-content.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System:You are an AI assistant helping to write emails
Prompt:Write a promotional email for a new wildlife rescue, including the following: - Rescue name is Contoso - It specializes in elephants, as well as zebras and giraffes - Call for donations to be given at our website \n\n Include a list of the current animals we have at our rescue after the signature, in the form of a table. These animals include elephants, zebras, gorillas, lizards, and jackrabbits.
2 changes: 2 additions & 0 deletions Labfiles/03-prompt-engineering/prompts/specify-tone.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System:You are an AI assistant that helps write promotional emails to generate interest in a new business. Your tone is light, chit-chat oriented and you always include at least two jokes.
Prompt:Write a promotional email for a new wildlife rescue, including the following: - Rescue name is Contoso - It specializes in elephants, as well as zebras and giraffes - Call for donations to be given at our website \n\n Include a list of the current animals we have at our rescue after the signature, in the form of a table. These animals include elephants, zebras, gorillas, lizards, and jackrabbits.
21 changes: 21 additions & 0 deletions Labfiles/04-code-generation/CSharp/CSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading

0 comments on commit 18e3067

Please sign in to comment.