Skip to content

Commit

Permalink
Merge branch 'main' into refactor-webapi-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dehoward committed Aug 3, 2023
2 parents 3eca13f + d3027a2 commit 2f760e8
Show file tree
Hide file tree
Showing 31 changed files with 643 additions and 511 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/copilot-chat-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ jobs:
REACT_APP_TEST_USER_ACCOUNT1: ${{ secrets.COPILOT_CHAT_TEST_USER_ACCOUNT1 }}
REACT_APP_TEST_USER_ACCOUNT1_INITIALS: ${{ secrets.COPILOT_CHAT_TEST_USER_ACCOUNT1_INITIALS }}
REACT_APP_TEST_USER_ACCOUNT2: ${{ secrets.COPILOT_CHAT_TEST_USER_ACCOUNT2 }}
REACT_APP_TEST_USER_PASSWORD: ${{ secrets.COPILOT_CHAT_TEST_USER_PASSWORD }}
REACT_APP_TEST_USER_PASSWORD1: ${{ secrets.COPILOT_CHAT_TEST_USER_PASSWORD1 }}
REACT_APP_TEST_USER_PASSWORD2: ${{ secrets.COPILOT_CHAT_TEST_USER_PASSWORD2 }}

REACT_APP_TEST_JIRA_EMAIL: ${{ secrets.COPILOT_CHAT_TEST_JIRA_EMAIL }}
REACT_APP_TEST_JIRA_ACCESS_TOKEN: ${{ secrets.COPILOT_CHAT_TEST_JIRA_ACCESS_TOKEN }}
Expand Down
298 changes: 159 additions & 139 deletions README.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions scripts/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Default environment file to be read by scripts

# Default values
ENV_COMPLETION_MODEL_OPEN_AI="gpt-3.5-turbo"
ENV_PLANNER_MODEL_OPEN_AI="gpt-3.5-turbo"
ENV_COMPLETION_MODEL_AZURE_OPEN_AI="gpt-35-turbo"
ENV_PLANNER_MODEL_AZURE_OPEN_AI="gpt-35-turbo"
ENV_EMBEDDING_MODEL="text-embedding-ada-002"
ENV_TENANT_ID="common"
ENV_ASPNETCORE="Development"

# Constants
ENV_AZURE_OPEN_AI="AzureOpenAI"
ENV_OPEN_AI="OpenAI"
151 changes: 89 additions & 62 deletions scripts/Configure.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<#
.SYNOPSIS
Configure user secrets, appsettings.Development.json, and .env for Copilot Chat.
Configure user secrets, appsettings.Development.json, and webapp/.env for Chat Copilot.
.PARAMETER OpenAI
Switch to configure for OpenAI.
.PARAMETER AIService
The service type used: OpenAI or Azure OpenAI.
.PARAMETER AzureOpenAI
Switch to configure for Azure OpenAI.
.PARAMETER APIKey
The API key for the AI service.
.PARAMETER ClientId
The client (application) ID associated with your AAD app registration.
.PARAMETER Endpoint
Set when using Azure OpenAI.
.PARAMETER ApiKey
The API key for the AI service.
.PARAMETER CompletionModel
The chat completion model to use (e.g., gpt-3.5-turbo or gpt-4).
Expand All @@ -23,44 +23,91 @@ The embedding model to use (e.g., text-embedding-ada-002).
.PARAMETER PlannerModel
The chat completion model to use for planning (e.g., gpt-3.5-turbo or gpt-4).
.PARAMETER ClientID
The client (application) ID associated with your AAD app registration.
.PARAMETER Tenant
.PARAMETER TenantId
The tenant (directory) associated with your AAD app registration.
Defaults to 'common'.
See https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-client-application-configuration#authority.
#>

param(
[Parameter(ParameterSetName='OpenAI',Mandatory=$false)]
[switch]$OpenAI,

[Parameter(ParameterSetName='AzureOpenAI',Mandatory=$false)]
[switch]$AzureOpenAI,

[Parameter(ParameterSetName='AzureOpenAI',Mandatory=$true)]
[string]$Endpoint,
[Parameter(Mandatory=$true)]
[string]$AIService,

[Parameter(Mandatory=$true)]
[string]$ApiKey,
[string]$APIKey,

[Parameter(Mandatory=$false)]
[string]$CompletionModel = "gpt-3.5-turbo",
[Parameter(Mandatory = $true)]
[string] $ClientId,

[Parameter(Mandatory=$false)]
[string]$EmbeddingModel = "text-embedding-ada-002",
[string]$Endpoint,

[Parameter(Mandatory=$false)]
[string]$CompletionModel,

[Parameter(Mandatory=$false)]
[string]$PlannerModel = "gpt-3.5-turbo",
[string]$EmbeddingModel,

[Parameter(Mandatory = $true)]
[string] $ClientId,
[Parameter(Mandatory=$false)]
[string]$PlannerModel,

[Parameter(Mandatory = $false)]
[string] $Tenant = 'common'
[string] $TenantId
)

# Get defaults and constants
$varScriptFilePath = Join-Path "$PSScriptRoot" 'Variables.ps1'
. $varScriptFilePath

# Set remaining values from Variables.ps1
if ($AIService -eq $varOpenAI)
{
if (!$CompletionModel)
{
$CompletionModel = $varCompletionModelOpenAI
}
if (!$PlannerModel)
{
$PlannerModel = $varPlannerModelOpenAI
}

# TO DO: Validate model values if set by command line.
}
elseif ($AIService -eq $varAzureOpenAI)
{
if (!$CompletionModel)
{
$CompletionModel = $varCompletionModelAzureOpenAI
}
if (!$PlannerModel)
{
$PlannerModel = $varPlannerModelAzureOpenAI
}

# TO DO: Validate model values if set by command line.

if (!$Endpoint)
{
Write-Error "Please specify an endpoint for -Endpoint when using AzureOpenAI."
exit(1)
}
}
else {
Write-Error "Please specify an AI service (AzureOpenAI or OpenAI) for -AIService."
exit(1)
}

if (!$EmbeddingModel)
{
$EmbeddingModel = $varEmbeddingModel
# TO DO: Validate model values if set by command line.
}
if (!$TenantId)
{
$TenantId = $varTenantId
# TO DO: Validate tenantID value if set by command line.
}

Write-Host "#########################"
Write-Host "# Backend configuration #"
Write-Host "#########################"
Expand All @@ -77,35 +124,17 @@ else # Windows/MacOS
if ($LASTEXITCODE -ne 0) { exit(1) }
}

if ($OpenAI)
{
$aiServiceType = "OpenAI"
$Endpoint = ""
}
elseif ($AzureOpenAI)
{
$aiServiceType = "AzureOpenAI"

# Azure OpenAI has a different model name for gpt-3.5-turbo (no decimal).
$CompletionModel = $CompletionModel.Replace("3.5", "35")
$EmbeddingModel = $EmbeddingModel.Replace("3.5", "35")
$PlannerModel = $PlannerModel.Replace("3.5", "35")
}
else {
Write-Error "Please specify either -OpenAI or -AzureOpenAI"
exit(1)
}

$appsettingsOverrides = @{ AIService = @{ Type = $aiServiceType; Endpoint = $Endpoint; Models = @{ Completion = $CompletionModel; Embedding = $EmbeddingModel; Planner = $PlannerModel } } }

$webapiProjectPath = Join-Path "$PSScriptRoot" '../webapi'
$appsettingsOverridesFilePath = Join-Path $webapiProjectPath 'appsettings.Development.json'

Write-Host "Setting 'AIService:Key' user secret for $aiServiceType..."
Write-Host "Setting 'AIService:Key' user secret for $AIService..."
dotnet user-secrets set --project $webapiProjectPath AIService:Key $ApiKey
if ($LASTEXITCODE -ne 0) { exit(1) }

Write-Host "Setting up 'appsettings.Development.json' for $aiServiceType..."
$appsettingsOverrides = @{ AIService = @{ Type = $AIService; Endpoint = $Endpoint; Models = @{ Completion = $CompletionModel; Embedding = $EmbeddingModel; Planner = $PlannerModel } } }
$appSettingsJson = -join ("appsettings.", $varASPNetCore, ".json");
$appsettingsOverridesFilePath = Join-Path $webapiProjectPath $appSettingsJson

Write-Host "Setting up '$appSettingsJson' for $AIService..."
ConvertTo-Json $appsettingsOverrides | Out-File -Encoding utf8 $appsettingsOverridesFilePath

Write-Host "($appsettingsOverridesFilePath)"
Expand All @@ -118,19 +147,17 @@ Write-Host "##########################"
Write-Host "# Frontend configuration #"
Write-Host "##########################"

$envFilePath = Join-Path "$PSScriptRoot" '../webapp/.env'
$webappProjectPath = Join-Path "$PSScriptRoot" '../webapp'
$webappEnvFilePath = Join-Path "$webappProjectPath" '/.env'

Write-Host "Setting up '.env'..."
Set-Content -Path $envFilePath -Value "REACT_APP_BACKEND_URI=https://localhost:40443/"
Add-Content -Path $envFilePath -Value "REACT_APP_AAD_AUTHORITY=https://login.microsoftonline.com/$Tenant"
Add-Content -Path $envFilePath -Value "REACT_APP_AAD_CLIENT_ID=$ClientId"
Add-Content -Path $envFilePath -Value ""
Add-Content -Path $envFilePath -Value "# Web Service API key (not required when running locally)"
Add-Content -Path $envFilePath -Value "REACT_APP_SK_API_KEY="

Write-Host "($envFilePath)"
Set-Content -Path $webappEnvFilePath -Value "REACT_APP_BACKEND_URI=https://localhost:40443/"
Add-Content -Path $webappEnvFilePath -Value "REACT_APP_AAD_AUTHORITY=https://login.microsoftonline.com/$TenantId"
Add-Content -Path $webappEnvFilePath -Value "REACT_APP_AAD_CLIENT_ID=$ClientId"

Write-Host "($webappEnvFilePath)"
Write-Host "========"
Get-Content $envFilePath | Write-Host
Get-Content $webappEnvFilePath | Write-Host
Write-Host "========"

Write-Host "Done!"
Loading

0 comments on commit 2f760e8

Please sign in to comment.