Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of deployment templates and scripts #704

Merged
merged 39 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b7d7644
Add deployment templates
glahaye Apr 26, 2023
7cf25d3
Update README.md
glahaye Apr 26, 2023
65576a6
Correct "Deploy Now" URL's
glahaye Apr 26, 2023
6f87376
Update Readme
glahaye Apr 26, 2023
7648971
First batch of fixes post bug bash
glahaye Apr 26, 2023
58af950
Second batch of bug bash fixes
glahaye Apr 27, 2023
c489bbf
Third batch of bug bash fixes
glahaye Apr 27, 2023
32b1e86
Fourth batch of fixes
glahaye Apr 27, 2023
0eca656
Final changes to README based on bug bash
glahaye Apr 27, 2023
1917afa
Edited comments
glahaye Apr 27, 2023
ab803bd
Updated another comment
glahaye Apr 27, 2023
dc7ff4d
Prevent example URL from choking the detector of broken links
glahaye Apr 27, 2023
118cdde
Second attempt at preventing link check for example URL
glahaye Apr 27, 2023
2b65a9f
Set App Insights connection string instead of instrumentation key
glahaye Apr 27, 2023
1a9cf20
Add characteristics to facilitate metrics on template usage
glahaye Apr 27, 2023
1682003
Update ARM templates
glahaye Apr 28, 2023
50b045d
Add deployment templates
glahaye Apr 26, 2023
10a71e7
Update README.md
glahaye Apr 26, 2023
32d3841
Correct "Deploy Now" URL's
glahaye Apr 26, 2023
16bb557
Update Readme
glahaye Apr 26, 2023
7390736
First batch of fixes post bug bash
glahaye Apr 26, 2023
a34343a
Second batch of bug bash fixes
glahaye Apr 27, 2023
4944f7d
Third batch of bug bash fixes
glahaye Apr 27, 2023
40a4891
Fourth batch of fixes
glahaye Apr 27, 2023
6b1a8fd
Final changes to README based on bug bash
glahaye Apr 27, 2023
33ffa1b
Edited comments
glahaye Apr 27, 2023
8ef8235
Updated another comment
glahaye Apr 27, 2023
be1dc57
Prevent example URL from choking the detector of broken links
glahaye Apr 27, 2023
008f913
Second attempt at preventing link check for example URL
glahaye Apr 27, 2023
a5a8eed
Set App Insights connection string instead of instrumentation key
glahaye Apr 27, 2023
e690eb9
Merge branch 'main' into deploy
lemillermicrosoft Apr 28, 2023
31341d6
Merge main in
glahaye Apr 28, 2023
522a689
Address PR comments
glahaye Apr 30, 2023
9f46f68
More PR comments addressed
glahaye May 1, 2023
9d52979
Merge branch 'main' into deploy
glahaye May 1, 2023
a47ee6b
Merge branch 'main' into deploy
adrianwyatt May 1, 2023
e5cdd06
Add bash versions of the deployment scripts
glahaye May 2, 2023
2228503
Merge branch 'deploy' of https://github.com/glahaye/semantic-kernel i…
glahaye May 2, 2023
e03adbb
Merge branch 'main' into deploy
dluc May 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Script to create a Semantic Kernel service deployment using an
# existing OpenAI or Azure OpenAI instance.

param(
glahaye marked this conversation as resolved.
Show resolved Hide resolved
[Parameter(Mandatory)]
[string]
$DeploymentName,

[Parameter(Mandatory)]
[string]
glahaye marked this conversation as resolved.
Show resolved Hide resolved
$ApiKey,

[string]
$Endpoint = "",

[string]
$AIService = "AzureOpenAI",
glahaye marked this conversation as resolved.
Show resolved Hide resolved

[string]
$CompletionModel = "gpt-35-turbo",

[string]
$EmbeddingModel = "text-embedding-ada-002",

[Parameter(Mandatory)]
[string]
$Subscription,

[string]
$ResourceGroup = "",

[string]
$Region = "South Central US",

[string]
$PackageUri = 'https://skaasdeploy.blob.core.windows.net/api/skaas.zip',

[switch]
$DebugDeployment
)

$ErrorActionPreference = "Stop"

$templateFile = "$($PSScriptRoot)/sk-existing-ai.bicep"

if (!$ResourceGroup)
{
$ResourceGroup = $DeploymentName + "-rg"
glahaye marked this conversation as resolved.
Show resolved Hide resolved
}

Write-Host "Log into your Azure account"
az login | out-null

az account set -s $Subscription

Write-Host "Creating resource group $($ResourceGroup) if it doesn't exist..."
az group create --location $Region --name $ResourceGroup --tags Creator=$env:UserName
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

Write-Host "Validating template file..."
az deployment group validate --name $DeploymentName --resource-group $ResourceGroup --template-file $templateFile --parameters name=$DeploymentName packageUri=$PackageUri aiService=$AIService completionModel=$CompletionModel embeddingModel=$EmbeddingModel endpoint=$Endpoint apiKey=$ApiKey
glahaye marked this conversation as resolved.
Show resolved Hide resolved
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

Write-Host "Deploying..."
if ($DebugDeployment) {
az deployment group create --name $DeploymentName --resource-group $ResourceGroup --template-file $templateFile --debug --parameters name=$DeploymentName packageUri=$PackageUri aiService=$AIService completionModel=$CompletionModel embeddingModel=$EmbeddingModel endpoint=$Endpoint apiKey=$ApiKey
}
else {
az deployment group create --name $DeploymentName --resource-group $ResourceGroup --template-file $templateFile --parameters name=$DeploymentName packageUri=$PackageUri aiService=$AIService completionModel=$CompletionModel embeddingModel=$EmbeddingModel endpoint=$Endpoint apiKey=$ApiKey
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Script to create a Semantic Kernel service deployment

param(
[Parameter(Mandatory)]
[string]
$DeploymentName,

[Parameter(Mandatory)]
[string]
$Subscription,

[string]
$ResourceGroup = "",

[string]
$Region = "South Central US",

[string]
$PackageUri = 'https://skaasdeploy.blob.core.windows.net/api/skaas.zip',

[switch]
$DebugDeployment
)

$ErrorActionPreference = "Stop"

$templateFile = "$($PSScriptRoot)/sk.bicep"

if (!$ResourceGroup)
{
$ResourceGroup = $DeploymentName + "-rg"
}

Write-Host "Log into your Azure account"
az login | out-null

az account set -s $Subscription

Write-Host "Creating resource group $($ResourceGroup) if it doesn't exist..."
az group create --location $Region --name $ResourceGroup --tags Creator=$env:UserName
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

Write-Host "Validating template file..."
az deployment group validate --name $DeploymentName --resource-group $ResourceGroup --template-file $templateFile --parameters name=$DeploymentName packageUri=$PackageUri
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

Write-Host "Deploying..."
if ($DebugDeployment) {
az deployment group create --name $DeploymentName --resource-group $ResourceGroup --template-file $templateFile --debug --parameters name=$DeploymentName packageUri=$PackageUri
}
else {
az deployment group create --name $DeploymentName --resource-group $ResourceGroup --template-file $templateFile --parameters name=$DeploymentName packageUri=$PackageUri
}
103 changes: 103 additions & 0 deletions samples/apps/copilot-chat-app/webapi/DeploymentTemplates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Deploying Semantic Kernel to Azure in a web app service

## Things to know

Azure currently limits the number of OpenAI resources per region per subscription to 3. Also, OpenAI is not available in every region.
(Refer to this [availability map](https://azure.microsoft.com/en-us/explore/global-infrastructure/products-by-region/?products=cognitive-services))
Bearing this in mind, you might want to use the same Azure OpenAI instance for multiple deployments of Semantic Kernel to Azure.

To do so, or to use an OpenAI instance from [openai.com](https://openai.com), use the version of the deployment template that uses existing OpenAI resources.

Either way, you also need to have the necessary permissions to create resources in the target subscription.

Also note that the F1 and D1 App Service SKU's (the Free and Shared ones) are not supported for this deployment.

## Deploying with a new Azure OpenAI instance

Use the [DeploySK.ps1](DeploySK.ps1) file found in this folder:
```powershell
.\DeploySK.ps1 -DeploymentName YOUR_DEPLOYMENT_NAME -Subscription YOUR_SUBSCRIPTION_ID
```

This will deploy an instance of Semantic Kernel in a web app service in a resource group that will bear the name YOUR_DEPLOYMENT_NAME followed by the "-rg" suffix in the specified subscription.

For more options, see the deployment script.

Alternatively, you can deploy by clicking on the following button:

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fglahaye%2Fsemantic-kernel%2Fdeploy%2Fsamples%2Fapps%2Fcopilot-chat-app%2Fwebapi%2FDeploymentTemplates%2Fsk.json)

## Deploying with an existing OpenAI / Azure OpenAI instance

Use the [DeploySK-Existing-AI.ps1](DeploySK-Existing-AI.ps1) file found in this folder:
```powershell
.\DeploySK-Existing-AI.ps1 -DeploymentName YOUR_DEPLOYMENT_NAME -Subscription YOUR_SUBSCRIPTION_ID -Endpoint "YOUR_AZURE_OPENAI_ENDPOINT"
```

After entering the command above, you will be prompted to enter your OpenAI or Azure OpenAI API key. (You can also pass in the API key using the -ApiKey parameter followed by a SecureString)

Note: the Azure OpenAI endpoint is ignored and can be omitted when you are using an OpenAI instance from [openai.com](https://openai.com).

Alternatively, you can deploy by clicking on the following button:

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fglahaye%2Fsemantic-kernel%2Fdeploy%2Fsamples%2Fapps%2Fcopilot-chat-app%2Fwebapi%2FDeploymentTemplates%2Fsk-existing-ai.json)

## Verifying the deployment

To make sure your web app service is running, go to https://YOUR_INSTANCE_NAME.azurewebsites.net/probe

To get your instance's URL, click on the "Go to resource group" button you see at the end of your deployment. Then click on the resource whose name ends with "-web".
This will bring you to the Overview page on your web service. Your instance's URL is the value that appears next to the "Default domain" field.

## Changing your configuration, monitoring your deployment and troubleshooting

From the page just mentioned in the section above, you can change your configuration by clicking on the "Configuration" item in the "Settings" section of the left pane.

Scrolling down in that same pane to the "Monitoring" section gives you access to a multitude of ways to monitor your deployment.

In addition to this, the "Diagnose and "solve problems" item near the top of the pane can yield crucial insight into some problems your deployment may be experiencing.

If the service itself if functioning properly but you keep getting errors (perhaps reported as 400 HTTP errors) when making calls to the Semantic Kernel,
check that you have correctly entered the values for the following settings:
- Completion:AzureOpenAI
- Completion:DeploymentOrModelId
- Completion:Endpoint
- Completion:Label
- Embedding:AzureOpenAI
- Embedding:DeploymentOrModelId
- Embedding:Endpoint
- Embedding:Label

Both Completion:Endpoint and Embedding:Endpoint are ignored for OpenAI instances from [openai.com](https://openai.com) but MUST be properly populated when using Azure OpenAI instances.

## Using web frontends to access your deployment

Make sure to include your frontend's URL as an allowed origin in your deployment's CORS settings. Otherwise, web browsers will refuse to let JavaScript make calls to your deployment.

# Deploying your custom version of Semantic Kernel

You can build and upload a customized version of the Semantic Kernel service.

To do so, clone the code from this repo then modify it to your needs (for example, by adding your own skills). Once that is done, go into the ../semantic-kernel/samples/apps/copilot-chat-app/webapi
directory and enter the following command:
```powershell
dotnet publish CopilotChatApi.csproj --configuration Release --arch x64 --os win
```

This will create the following directory, which will contain all the files needed for a deployment:
../semantic-kernel/samples/apps/copilot-chat-app/webapi/bin/Release/net6.0/win-x64/publish

Zip the contents of that directory then put the resulting zip file on the web.

Put its URI in the "Package Uri" field in the web deployment page you access through the "Deploy to Azure" buttons above, or use its URI as the value for the PackageUri parameter of the Powershell scripts above.

Your deployment will then use your customized deployment package.


## Cleaning up
glahaye marked this conversation as resolved.
Show resolved Hide resolved

Once you are done with your resources, you can delete them from the Azure portal. You can also simply delete the resource group in which they are from the portal or through the
following [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/) command:
```powershell
az group delete --name YOUR_RESOURCE_GROUP
```