forked from Azure-Samples/azure-search-openai-demo-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepdocs.ps1
69 lines (54 loc) · 2.58 KB
/
prepdocs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
if (-not $script:azdCmd) {
$script:azdCmd = Get-Command azd -ErrorAction SilentlyContinue
}
# Check if 'azd' command is available
if (-not $script:azdCmd) {
throw "Error: 'azd' command is not found. Please ensure you have 'azd' installed. For installation instructions, visit: https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/install-azd"
}
if (-not $script:dotnetCmd) {
$script:dotnetCmd = Get-Command dotnet -ErrorAction SilentlyContinue
}
# Check if 'dotnet' command is available
if (-not $script:dotnetCmd) {
throw "Error: 'dotnet' command is not found. Please ensure you have 'dotnet' installed. For installation instructions, visit: https://learn.microsoft.com/en-us/dotnet/core/tools/"
}
function Invoke-ExternalCommand {
param (
[Parameter(Mandatory = $true)]
[string]$Command,
[Parameter(Mandatory = $false)]
[string]$Arguments
)
$processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
$processStartInfo.FileName = $Command
$processStartInfo.Arguments = $Arguments
$processStartInfo.RedirectStandardOutput = $true
$processStartInfo.RedirectStandardError = $true
$processStartInfo.UseShellExecute = $false
$processStartInfo.CreateNoWindow = $true
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $processStartInfo
$process.Start() | Out-Null
$output = $process.StandardOutput.ReadToEnd()
$errorOutput = $process.StandardError.ReadToEnd()
$process.WaitForExit()
if ($errorOutput) {
Write-Error $errorOutput
}
return $output
}
if ([string]::IsNullOrEmpty($env:AZD_PREPDOCS_RAN) -or $env:AZD_PREPDOCS_RAN -eq "false") {
Write-Host 'Running "PrepareDocs.dll"'
Get-Location | Select-Object -ExpandProperty Path
$dotnetArguments = @"
run --project "app/prepdocs/PrepareDocs/PrepareDocs.csproj" "./data/*.pdf" --storageendpoint $($env:AZURE_STORAGE_BLOB_ENDPOINT) --container $($env:AZURE_STORAGE_CONTAINER) --searchendpoint $($env:AZURE_SEARCH_SERVICE_ENDPOINT) --searchindex $($env:AZURE_SEARCH_INDEX) --openaiendpoint $($env:AZURE_OPENAI_ENDPOINT) --embeddingmodel $($env:AZURE_OPENAI_EMBEDDING_DEPLOYMENT) --formrecognizerendpoint $($env:AZURE_FORMRECOGNIZER_SERVICE_ENDPOINT) --tenantid $($env:AZURE_TENANT_ID) --verbose
"@
$output = Invoke-ExternalCommand -Command "dotnet" -Arguments $dotnetArguments
Write-Host $output
Invoke-ExternalCommand -Command ($azdCmd).Source -Arguments @"
env set AZD_PREPDOCS_RAN "true"
"@
}
else {
Write-Host "AZD_PREPDOCS_RAN is set to true. Skipping the run."
}