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

Docs: Update user quick-start readme and fix scripts #71

Closed
346 changes: 211 additions & 135 deletions README.md

Large diffs are not rendered by default.

Binary file modified images/Cert-Issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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