From 80ed02c3615145310bf5c3bc55232d93e77a30de Mon Sep 17 00:00:00 2001 From: Lauren Mills Date: Wed, 1 May 2019 10:52:55 -0700 Subject: [PATCH 1/3] small fixes --- .../Scripts/deploy_cognitive_models.ps1 | 15 +-- .../Scripts/update_cognitive_models.ps1 | 97 +++++++++++++++++++ .../Skill/Controllers/BotController.cs | 23 ++--- .../Scripts/deploy_cognitive_models.ps1 | 9 +- .../Scripts/update_cognitive_models.ps1 | 97 +++++++++++++++++++ .../Template/Skill/MyTemplate.vstemplate | 1 + 6 files changed, 222 insertions(+), 20 deletions(-) create mode 100644 templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/update_cognitive_models.ps1 create mode 100644 templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/update_cognitive_models.ps1 diff --git a/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/deploy_cognitive_models.ps1 b/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/deploy_cognitive_models.ps1 index 9e84b7d17f..850800b9f0 100644 --- a/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/deploy_cognitive_models.ps1 +++ b/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/deploy_cognitive_models.ps1 @@ -55,12 +55,15 @@ if (-not $luisAuthoringKey) { } } +# Get languages +$languageArr = $languages -split "," + # Initialize settings obj -$settings = @{ cognitiveModels = New-Object PSObject } +$settings = @{ defaultLocale = $languageArr[0]; cognitiveModels = New-Object PSObject } # Deploy localized resources -Write-Host "Deploying cognitive models ..." -foreach ($language in $languages -split ",") +Write-Host "> Deploying cognitive models ..." +foreach ($language in $languageArr) { $langCode = ($language -split "-")[0] @@ -81,10 +84,10 @@ foreach ($language in $languages -split ",") id = $lu.BaseName name = $luisApp.name appid = $luisApp.id - authoringkey = $luisAuthoringKey - subscriptionkey = $luisAuthoringKey + authoringkey = $luisauthoringkey + subscriptionkey = $luisauthoringkey version = $luisApp.activeVersion - region = $luisAuthoringRegion + region = $location } RunLuisGen $lu "$($lu.BaseName)" $(Join-Path $outFolder Services) diff --git a/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/update_cognitive_models.ps1 b/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/update_cognitive_models.ps1 new file mode 100644 index 0000000000..5c7646c315 --- /dev/null +++ b/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/update_cognitive_models.ps1 @@ -0,0 +1,97 @@ +#Requires -Version 6 + +Param( + [string] $configFile = $(Join-Path (Get-Location) 'cognitivemodels.json'), + [switch] $RemoteToLocal, + [string] $dispatchFolder = $(Join-Path $PSScriptRoot '..' 'Resources' 'Dispatch'), + [string] $luisFolder = $(Join-Path $PSScriptRoot '..' 'Resources' 'LU'), + [string] $qnaFolder = $(Join-Path $PSScriptRoot '..' 'Resources' 'QnA'), + [string] $lgOutFolder = $(Join-Path (Get-Location) 'Services'), + [string] $logFile = $(Join-Path $PSScriptRoot .. "update_cognitive_models_log.txt") +) + +. $PSScriptRoot\luis_functions.ps1 +. $PSScriptRoot\qna_functions.ps1 + +# Reset log file +if (Test-Path $logFile) { + Clear-Content $logFile -Force | Out-Null +} +else { + New-Item -Path $logFile | Out-Null +} + +Write-Host "> Getting config file ..." +$languageMap = @{} +$config = Get-Content -Raw -Path $configFile | ConvertFrom-Json +$config.cognitiveModels.PSObject.Properties | Foreach-Object { $languageMap[$_.Name] = $_.Value } + +foreach ($langCode in $languageMap.Keys) { + $models = $languageMap[$langCode] + + if($RemoteToLocal) + { + # Update local LU files based on hosted models + foreach ($luisApp in $models.languageModels) + { + Write-Host "> Updating local $($luisApp.id).lu file ..." + luis export version ` + --appId $luisApp.appid ` + --versionId $luisApp.version ` + --authoringKey $luisApp.authoringKey | ludown refresh ` + --stdin ` + -n "$($luisApp.id).lu" ` + -o $(Join-Path $luisFolder $langCode) + } + + # Update local LU files based on hosted QnA KBs + foreach ($kb in $models.knowledgebases) + { + Write-Host "> Updating local $($kb.id).lu file ..." + qnamaker export kb ` + --environment Prod ` + --kbId $kb.kbId ` + --subscriptionKey $kb.subscriptionKey | ludown refresh ` + --stdin ` + -n "$($kb.id).lu" ` + -o $(Join-Path $qnaFolder $langCode) + } + } + else + { + # Update each luis model based on local LU files + foreach ($luisApp in $models.languageModels) { + Write-Host "> Updating hosted $($luisApp.id) app..." + $lu = Get-Item -Path $(Join-Path $luisFolder $langCode "$($luisApp.id).lu") + UpdateLUIS ` + -lu_file $lu ` + -appId $luisApp.appid ` + -version $luisApp.version ` + -authoringKey $luisApp.authoringKey ` + -subscriptionKey $app.subscriptionKey + } + + # Update each knowledgebase based on local LU files + foreach ($kb in $models.knowledgebases) { + Write-Host "> Updating hosted $($kb.id) kb..." + $lu = Get-Item -Path $(Join-Path $qnaFolder $langCode "$($kb.id).lu") + UpdateKB ` + -lu_file $lu ` + -kbId $kb.kbId ` + -qnaSubscriptionKey $kb.subscriptionKey + } + } +} + +# Update dispatch model +Write-Host "> Updating dispatch model ..." +$dispatch = $models.dispatchModel +dispatch refresh ` + --dispatch $(Join-Path $dispatchFolder $langCode "$($dispatch.name).dispatch") ` + --dataFolder $dispatchFolder 2>> $logFile | Out-Null + +# Update dispatch.cs file +Write-Host "> Running LuisGen ..." +luisgen $(Join-Path $dispatchFolder $langCode "$($dispatch.name).json") -cs "DispatchLuis" -o $lgOutFolder 2>> $logFile | Out-Null + +Write-Host "> Done." \ No newline at end of file diff --git a/templates/Skill-Template/csharp/Template/Skill/Controllers/BotController.cs b/templates/Skill-Template/csharp/Template/Skill/Controllers/BotController.cs index 515b999545..efe8911a9a 100644 --- a/templates/Skill-Template/csharp/Template/Skill/Controllers/BotController.cs +++ b/templates/Skill-Template/csharp/Template/Skill/Controllers/BotController.cs @@ -7,15 +7,16 @@ namespace $safeprojectname$.Controllers { [ApiController] -public class BotController : SkillController -{ - public BotController( - IBotFrameworkHttpAdapter botFrameworkHttpAdapter, - SkillHttpAdapter skillHttpAdapter, - SkillWebSocketAdapter skillWebSocketAdapter, - IBot bot, - BotSettingsBase botSettings) - : base(botFrameworkHttpAdapter, skillHttpAdapter, skillWebSocketAdapter, bot, botSettings) - { - } + public class BotController : SkillController + { + public BotController( + IBotFrameworkHttpAdapter botFrameworkHttpAdapter, + SkillHttpAdapter skillHttpAdapter, + SkillWebSocketAdapter skillWebSocketAdapter, + IBot bot, + BotSettingsBase botSettings) + : base(botFrameworkHttpAdapter, skillHttpAdapter, skillWebSocketAdapter, bot, botSettings) + { + } + } } \ No newline at end of file diff --git a/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/deploy_cognitive_models.ps1 b/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/deploy_cognitive_models.ps1 index 9f13fabaa0..850800b9f0 100644 --- a/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/deploy_cognitive_models.ps1 +++ b/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/deploy_cognitive_models.ps1 @@ -55,12 +55,15 @@ if (-not $luisAuthoringKey) { } } +# Get languages +$languageArr = $languages -split "," + # Initialize settings obj -$settings = @{ cognitiveModels = New-Object PSObject } +$settings = @{ defaultLocale = $languageArr[0]; cognitiveModels = New-Object PSObject } # Deploy localized resources -Write-Host "Deploying cognitive models ..." -foreach ($language in $languages -split ",") +Write-Host "> Deploying cognitive models ..." +foreach ($language in $languageArr) { $langCode = ($language -split "-")[0] diff --git a/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/update_cognitive_models.ps1 b/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/update_cognitive_models.ps1 new file mode 100644 index 0000000000..5c7646c315 --- /dev/null +++ b/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/update_cognitive_models.ps1 @@ -0,0 +1,97 @@ +#Requires -Version 6 + +Param( + [string] $configFile = $(Join-Path (Get-Location) 'cognitivemodels.json'), + [switch] $RemoteToLocal, + [string] $dispatchFolder = $(Join-Path $PSScriptRoot '..' 'Resources' 'Dispatch'), + [string] $luisFolder = $(Join-Path $PSScriptRoot '..' 'Resources' 'LU'), + [string] $qnaFolder = $(Join-Path $PSScriptRoot '..' 'Resources' 'QnA'), + [string] $lgOutFolder = $(Join-Path (Get-Location) 'Services'), + [string] $logFile = $(Join-Path $PSScriptRoot .. "update_cognitive_models_log.txt") +) + +. $PSScriptRoot\luis_functions.ps1 +. $PSScriptRoot\qna_functions.ps1 + +# Reset log file +if (Test-Path $logFile) { + Clear-Content $logFile -Force | Out-Null +} +else { + New-Item -Path $logFile | Out-Null +} + +Write-Host "> Getting config file ..." +$languageMap = @{} +$config = Get-Content -Raw -Path $configFile | ConvertFrom-Json +$config.cognitiveModels.PSObject.Properties | Foreach-Object { $languageMap[$_.Name] = $_.Value } + +foreach ($langCode in $languageMap.Keys) { + $models = $languageMap[$langCode] + + if($RemoteToLocal) + { + # Update local LU files based on hosted models + foreach ($luisApp in $models.languageModels) + { + Write-Host "> Updating local $($luisApp.id).lu file ..." + luis export version ` + --appId $luisApp.appid ` + --versionId $luisApp.version ` + --authoringKey $luisApp.authoringKey | ludown refresh ` + --stdin ` + -n "$($luisApp.id).lu" ` + -o $(Join-Path $luisFolder $langCode) + } + + # Update local LU files based on hosted QnA KBs + foreach ($kb in $models.knowledgebases) + { + Write-Host "> Updating local $($kb.id).lu file ..." + qnamaker export kb ` + --environment Prod ` + --kbId $kb.kbId ` + --subscriptionKey $kb.subscriptionKey | ludown refresh ` + --stdin ` + -n "$($kb.id).lu" ` + -o $(Join-Path $qnaFolder $langCode) + } + } + else + { + # Update each luis model based on local LU files + foreach ($luisApp in $models.languageModels) { + Write-Host "> Updating hosted $($luisApp.id) app..." + $lu = Get-Item -Path $(Join-Path $luisFolder $langCode "$($luisApp.id).lu") + UpdateLUIS ` + -lu_file $lu ` + -appId $luisApp.appid ` + -version $luisApp.version ` + -authoringKey $luisApp.authoringKey ` + -subscriptionKey $app.subscriptionKey + } + + # Update each knowledgebase based on local LU files + foreach ($kb in $models.knowledgebases) { + Write-Host "> Updating hosted $($kb.id) kb..." + $lu = Get-Item -Path $(Join-Path $qnaFolder $langCode "$($kb.id).lu") + UpdateKB ` + -lu_file $lu ` + -kbId $kb.kbId ` + -qnaSubscriptionKey $kb.subscriptionKey + } + } +} + +# Update dispatch model +Write-Host "> Updating dispatch model ..." +$dispatch = $models.dispatchModel +dispatch refresh ` + --dispatch $(Join-Path $dispatchFolder $langCode "$($dispatch.name).dispatch") ` + --dataFolder $dispatchFolder 2>> $logFile | Out-Null + +# Update dispatch.cs file +Write-Host "> Running LuisGen ..." +luisgen $(Join-Path $dispatchFolder $langCode "$($dispatch.name).json") -cs "DispatchLuis" -o $lgOutFolder 2>> $logFile | Out-Null + +Write-Host "> Done." \ No newline at end of file diff --git a/templates/Skill-Template/csharp/Template/Skill/MyTemplate.vstemplate b/templates/Skill-Template/csharp/Template/Skill/MyTemplate.vstemplate index a2e8347f4d..3b013216a1 100644 --- a/templates/Skill-Template/csharp/Template/Skill/MyTemplate.vstemplate +++ b/templates/Skill-Template/csharp/Template/Skill/MyTemplate.vstemplate @@ -69,6 +69,7 @@ deploy.ps1 deploy_cognitive_models.ps1 luis_functions.ps1 + update_cognitive_models.ps1 From 9e79e4cef45d97e45f78c45f088aa98172f34b30 Mon Sep 17 00:00:00 2001 From: Lauren Mills Date: Wed, 1 May 2019 11:48:41 -0700 Subject: [PATCH 2/3] fixes for bot controller issue --- .../SkillSample/Controllers/BotController.cs | 25 +++++++++---------- .../Sample/SkillSample/SkillSample.csproj | 4 +-- .../Sample/SkillSample/appsettings.json | 7 +----- .../Sample/SkillSample/cognitivemodels.json | 11 ++++---- .../Skill/Controllers/BotController.cs | 9 +++---- .../csharp/Template/Skill/Skill.csproj | 4 +-- .../csharp/Template/Skill/appsettings.json | 7 +----- .../Template/Skill/cognitivemodels.json | 5 ++-- 8 files changed, 31 insertions(+), 41 deletions(-) diff --git a/templates/Skill-Template/csharp/Sample/SkillSample/Controllers/BotController.cs b/templates/Skill-Template/csharp/Sample/SkillSample/Controllers/BotController.cs index eb76c6ec7e..880785ae7c 100644 --- a/templates/Skill-Template/csharp/Sample/SkillSample/Controllers/BotController.cs +++ b/templates/Skill-Template/csharp/Sample/SkillSample/Controllers/BotController.cs @@ -6,17 +6,16 @@ namespace SkillSample.Controllers { - [ApiController] - public class BotController : SkillController - { - public BotController( - IBotFrameworkHttpAdapter botFrameworkHttpAdapter, - SkillHttpAdapter skillHttpAdapter, - SkillWebSocketAdapter skillWebSocketAdapter, - IBot bot, - BotSettingsBase botSettings) - : base(botFrameworkHttpAdapter, skillHttpAdapter, skillWebSocketAdapter, bot, botSettings) - { - } - } + [ApiController] + public class BotController : SkillController + { + public BotController( + IBot bot, + BotSettingsBase botSettings, + IBotFrameworkHttpAdapter botFrameworkHttpAdapter, + SkillWebSocketAdapter skillWebSocketAdapter) + : base(bot, botSettings, botFrameworkHttpAdapter, skillWebSocketAdapter) + { + } + } } \ No newline at end of file diff --git a/templates/Skill-Template/csharp/Sample/SkillSample/SkillSample.csproj b/templates/Skill-Template/csharp/Sample/SkillSample/SkillSample.csproj index 1303f14229..d152ecc9cf 100644 --- a/templates/Skill-Template/csharp/Sample/SkillSample/SkillSample.csproj +++ b/templates/Skill-Template/csharp/Sample/SkillSample/SkillSample.csproj @@ -62,8 +62,8 @@ - - + + diff --git a/templates/Skill-Template/csharp/Sample/SkillSample/appsettings.json b/templates/Skill-Template/csharp/Sample/SkillSample/appsettings.json index 1160a05f47..8f2f91ed98 100644 --- a/templates/Skill-Template/csharp/Sample/SkillSample/appsettings.json +++ b/templates/Skill-Template/csharp/Sample/SkillSample/appsettings.json @@ -1,12 +1,7 @@ { "microsoftAppId": "", "microsoftAppPassword": "", - "oauthConnections": [ - { - "name": "", - "provider": "" - } - ], + "oauthConnections": [], "appInsights": { "appId": "", "instrumentationKey": "" diff --git a/templates/Skill-Template/csharp/Sample/SkillSample/cognitivemodels.json b/templates/Skill-Template/csharp/Sample/SkillSample/cognitivemodels.json index d8042c09cf..85442b8589 100644 --- a/templates/Skill-Template/csharp/Sample/SkillSample/cognitivemodels.json +++ b/templates/Skill-Template/csharp/Sample/SkillSample/cognitivemodels.json @@ -3,24 +3,25 @@ "en": { "languageModels": [ { + "id": "general", + "name": "", "appid": "", "version": "0.1", "region": "", - "name": "", "authoringkey": "", - "id": "general", "subscriptionkey": "" }, { + "id": "skill", + "name": "", "appid": "", "version": "0.1", "region": "", - "name": "", "authoringkey": "", - "id": "skill", "subscriptionkey": "" } ] } - } + }, + "defaultLocale": "en-us" } diff --git a/templates/Skill-Template/csharp/Template/Skill/Controllers/BotController.cs b/templates/Skill-Template/csharp/Template/Skill/Controllers/BotController.cs index efe8911a9a..3fc8270018 100644 --- a/templates/Skill-Template/csharp/Template/Skill/Controllers/BotController.cs +++ b/templates/Skill-Template/csharp/Template/Skill/Controllers/BotController.cs @@ -10,12 +10,11 @@ namespace $safeprojectname$.Controllers public class BotController : SkillController { public BotController( - IBotFrameworkHttpAdapter botFrameworkHttpAdapter, - SkillHttpAdapter skillHttpAdapter, - SkillWebSocketAdapter skillWebSocketAdapter, IBot bot, - BotSettingsBase botSettings) - : base(botFrameworkHttpAdapter, skillHttpAdapter, skillWebSocketAdapter, bot, botSettings) + BotSettingsBase botSettings, + IBotFrameworkHttpAdapter botFrameworkHttpAdapter, + SkillWebSocketAdapter skillWebSocketAdapter) + : base(bot, botSettings, botFrameworkHttpAdapter, skillWebSocketAdapter) { } } diff --git a/templates/Skill-Template/csharp/Template/Skill/Skill.csproj b/templates/Skill-Template/csharp/Template/Skill/Skill.csproj index 1303f14229..d152ecc9cf 100644 --- a/templates/Skill-Template/csharp/Template/Skill/Skill.csproj +++ b/templates/Skill-Template/csharp/Template/Skill/Skill.csproj @@ -62,8 +62,8 @@ - - + + diff --git a/templates/Skill-Template/csharp/Template/Skill/appsettings.json b/templates/Skill-Template/csharp/Template/Skill/appsettings.json index 101b347233..8f2f91ed98 100644 --- a/templates/Skill-Template/csharp/Template/Skill/appsettings.json +++ b/templates/Skill-Template/csharp/Template/Skill/appsettings.json @@ -1,6 +1,7 @@ { "microsoftAppId": "", "microsoftAppPassword": "", + "oauthConnections": [], "appInsights": { "appId": "", "instrumentationKey": "" @@ -15,11 +16,5 @@ "collectionId": "botstate-collection", "databaseId": "botstate-db" }, - "oauthConnections": [ - { - "name": "", - "provider": "" - } - ], "properties": {} } diff --git a/templates/Skill-Template/csharp/Template/Skill/cognitivemodels.json b/templates/Skill-Template/csharp/Template/Skill/cognitivemodels.json index 98d766d4c9..fa041f1e99 100644 --- a/templates/Skill-Template/csharp/Template/Skill/cognitivemodels.json +++ b/templates/Skill-Template/csharp/Template/Skill/cognitivemodels.json @@ -22,5 +22,6 @@ } ] } - } -} + }, + "defaultLocale": "en-us" +} \ No newline at end of file From a5d8a16fb6bdacadb4eb770dfd063a9f3488c62b Mon Sep 17 00:00:00 2001 From: Lauren Mills Date: Wed, 1 May 2019 11:53:59 -0700 Subject: [PATCH 3/3] fixed location for deploy models --- .../Deployment/Scripts/deploy_cognitive_models.ps1 | 8 ++++---- .../Skill/Deployment/Scripts/deploy_cognitive_models.ps1 | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/deploy_cognitive_models.ps1 b/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/deploy_cognitive_models.ps1 index 850800b9f0..47644591b0 100644 --- a/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/deploy_cognitive_models.ps1 +++ b/templates/Skill-Template/csharp/Sample/SkillSample/Deployment/Scripts/deploy_cognitive_models.ps1 @@ -76,7 +76,7 @@ foreach ($language in $languageArr) foreach ($lu in $luisFiles) { # Deploy LUIS model - $luisApp = DeployLUIS -name $name -lu_file $lu -region $location -luisAuthoringKey $luisAuthoringKey -language $language -log $logFile + $luisApp = DeployLUIS -name $name -lu_file $lu -region $luisAuthoringRegion -luisAuthoringKey $luisAuthoringKey -language $language -log $logFile if ($luisApp) { # Add to config @@ -84,10 +84,10 @@ foreach ($language in $languageArr) id = $lu.BaseName name = $luisApp.name appid = $luisApp.id - authoringkey = $luisauthoringkey - subscriptionkey = $luisauthoringkey + authoringkey = $luisAuthoringKey + subscriptionkey = $luisAuthoringKey version = $luisApp.activeVersion - region = $location + region = $luisAuthoringRegion } RunLuisGen $lu "$($lu.BaseName)" $(Join-Path $outFolder Services) diff --git a/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/deploy_cognitive_models.ps1 b/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/deploy_cognitive_models.ps1 index 850800b9f0..47644591b0 100644 --- a/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/deploy_cognitive_models.ps1 +++ b/templates/Skill-Template/csharp/Template/Skill/Deployment/Scripts/deploy_cognitive_models.ps1 @@ -76,7 +76,7 @@ foreach ($language in $languageArr) foreach ($lu in $luisFiles) { # Deploy LUIS model - $luisApp = DeployLUIS -name $name -lu_file $lu -region $location -luisAuthoringKey $luisAuthoringKey -language $language -log $logFile + $luisApp = DeployLUIS -name $name -lu_file $lu -region $luisAuthoringRegion -luisAuthoringKey $luisAuthoringKey -language $language -log $logFile if ($luisApp) { # Add to config @@ -84,10 +84,10 @@ foreach ($language in $languageArr) id = $lu.BaseName name = $luisApp.name appid = $luisApp.id - authoringkey = $luisauthoringkey - subscriptionkey = $luisauthoringkey + authoringkey = $luisAuthoringKey + subscriptionkey = $luisAuthoringKey version = $luisApp.activeVersion - region = $location + region = $luisAuthoringRegion } RunLuisGen $lu "$($lu.BaseName)" $(Join-Path $outFolder Services)