-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsetup.ps1
782 lines (683 loc) · 30 KB
/
setup.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
# DocsGPT Setup PowerShell Script for Windows
# PowerShell -ExecutionPolicy Bypass -File .\setup.ps1
# Script execution policy - uncomment if needed
# Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
# Set error action preference
$ErrorActionPreference = "Stop"
# Get current script directory
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition
$COMPOSE_FILE = Join-Path -Path $SCRIPT_DIR -ChildPath "deployment\docker-compose.yaml"
$ENV_FILE = Join-Path -Path $SCRIPT_DIR -ChildPath ".env"
# Function to write colored text
function Write-ColorText {
param (
[Parameter(Mandatory=$true)][string]$Text,
[Parameter()][string]$ForegroundColor = "White",
[Parameter()][switch]$Bold
)
$params = @{
ForegroundColor = $ForegroundColor
NoNewline = $false
}
if ($Bold) {
# PowerShell doesn't have bold
Write-Host $Text @params
} else {
Write-Host $Text @params
}
}
# Animation function (Windows PowerShell version of animate_dino)
function Animate-Dino {
[Console]::CursorVisible = $false
# Clear screen
Clear-Host
# Static DocsGPT text
$static_text = @(
" ____ ____ ____ _____ "
" | _ \ ___ ___ ___ / ___| _ \_ _|"
" | | | |/ _ \ / __/ __| | _| |_) || | "
" | |_| | (_) | (__\__ \ |_| | __/ | | "
" |____/ \___/ \___|___/\____|_| |_| "
" "
)
# Print static text
foreach ($line in $static_text) {
Write-Host $line
}
# Dino ASCII art
$dino_lines = @(
" ######### "
" ############# "
" ##################"
" ####################"
" ######################"
" ####################### ######"
" ############################### "
" ################################## "
" ################ ############ "
" ################## ########## "
" ##################### ######## "
" ###################### ###### ### "
" ############ ########## #### ## "
" ############# ######### ##### "
" ############## ######### "
" ############## ########## "
"############ ####### "
" ###### ###### #### "
" ################ "
" ################# "
)
# Save cursor position
$cursorPos = $Host.UI.RawUI.CursorPosition
# Build-up animation
for ($i = 0; $i -lt $dino_lines.Count; $i++) {
# Restore cursor position
$Host.UI.RawUI.CursorPosition = $cursorPos
# Display lines up to current index
for ($j = 0; $j -le $i; $j++) {
Write-Host $dino_lines[$j]
}
# Slow down animation
Start-Sleep -Milliseconds 50
}
# Pause at end of animation
Start-Sleep -Milliseconds 500
# Clear the animation
$Host.UI.RawUI.CursorPosition = $cursorPos
# Clear from cursor to end of screen
for ($i = 0; $i -lt $dino_lines.Count; $i++) {
Write-Host (" " * $dino_lines[0].Length)
}
# Restore cursor position for next output
$Host.UI.RawUI.CursorPosition = $cursorPos
# Show cursor again
[Console]::CursorVisible = $true
}
# Check and start Docker function
function Check-AndStartDocker {
# Check if Docker is running
try {
$dockerRunning = $false
# First try with 'docker info' which should work if Docker is fully operational
try {
$dockerInfo = docker info 2>&1
# If we get here without an exception, Docker is running
Write-ColorText "Docker is already running." -ForegroundColor "Green"
return $true
} catch {
# Docker info command failed
}
# Check if Docker process is running
$dockerProcess = Get-Process "Docker Desktop" -ErrorAction SilentlyContinue
if ($dockerProcess) {
# Docker Desktop is running, but might not be fully initialized
Write-ColorText "Docker Desktop is starting up. Waiting for it to be ready..." -ForegroundColor "Yellow"
# Wait for Docker to become operational
$attempts = 0
$maxAttempts = 30
while ($attempts -lt $maxAttempts) {
try {
$null = docker ps 2>&1
Write-ColorText "Docker is now operational." -ForegroundColor "Green"
return $true
} catch {
Write-Host "." -NoNewline
Start-Sleep -Seconds 2
$attempts++
}
}
Write-ColorText "`nDocker Desktop is running but not responding to commands. Please check Docker status." -ForegroundColor "Red"
return $false
}
# Docker is not running, attempt to start it
Write-ColorText "Docker is not running. Attempting to start Docker Desktop..." -ForegroundColor "Yellow"
# Docker Desktop locations to check
$dockerPaths = @(
"${env:ProgramFiles}\Docker\Docker\Docker Desktop.exe",
"${env:ProgramFiles(x86)}\Docker\Docker\Docker Desktop.exe",
"$env:LOCALAPPDATA\Docker\Docker\Docker Desktop.exe"
)
$dockerPath = $null
foreach ($path in $dockerPaths) {
if (Test-Path $path) {
$dockerPath = $path
break
}
}
if ($null -eq $dockerPath) {
Write-ColorText "Docker Desktop not found. Please install Docker Desktop or start it manually." -ForegroundColor "Red"
return $false
}
# Start Docker Desktop
try {
Start-Process $dockerPath
Write-Host -NoNewline "Waiting for Docker to start"
# Wait for Docker to be ready
$attempts = 0
$maxAttempts = 60 # 60 x 2 seconds = maximum 2 minutes wait
while ($attempts -lt $maxAttempts) {
try {
$null = docker ps 2>&1
Write-Host "`nDocker has started successfully!"
return $true
} catch {
# Show waiting animation
Write-Host -NoNewline "."
Start-Sleep -Seconds 2
$attempts++
if ($attempts % 3 -eq 0) {
Write-Host "`r" -NoNewline
Write-Host "Waiting for Docker to start " -NoNewline
}
}
}
Write-ColorText "`nDocker did not start within the expected time. Please start Docker Desktop manually." -ForegroundColor "Red"
return $false
} catch {
Write-ColorText "Failed to start Docker Desktop. Please start it manually." -ForegroundColor "Red"
return $false
}
} catch {
Write-ColorText "Error checking Docker status: $_" -ForegroundColor "Red"
return $false
}
}
# Function to prompt the user for the main menu choice
function Prompt-MainMenu {
Write-Host ""
Write-ColorText "Welcome to DocsGPT Setup!" -ForegroundColor "White" -Bold
Write-ColorText "How would you like to proceed?" -ForegroundColor "White"
Write-ColorText "1) Use DocsGPT Public API Endpoint (simple and free)" -ForegroundColor "Yellow"
Write-ColorText "2) Serve Local (with Ollama)" -ForegroundColor "Yellow"
Write-ColorText "3) Connect Local Inference Engine" -ForegroundColor "Yellow"
Write-ColorText "4) Connect Cloud API Provider" -ForegroundColor "Yellow"
Write-Host ""
$script:main_choice = Read-Host "Choose option (1-4)"
}
# Function to prompt for Local Inference Engine options
function Prompt-LocalInferenceEngineOptions {
Clear-Host
Write-Host ""
Write-ColorText "Connect Local Inference Engine" -ForegroundColor "White" -Bold
Write-ColorText "Choose your local inference engine:" -ForegroundColor "White"
Write-ColorText "1) LLaMa.cpp" -ForegroundColor "Yellow"
Write-ColorText "2) Ollama" -ForegroundColor "Yellow"
Write-ColorText "3) Text Generation Inference (TGI)" -ForegroundColor "Yellow"
Write-ColorText "4) SGLang" -ForegroundColor "Yellow"
Write-ColorText "5) vLLM" -ForegroundColor "Yellow"
Write-ColorText "6) Aphrodite" -ForegroundColor "Yellow"
Write-ColorText "7) FriendliAI" -ForegroundColor "Yellow"
Write-ColorText "8) LMDeploy" -ForegroundColor "Yellow"
Write-ColorText "b) Back to Main Menu" -ForegroundColor "Yellow"
Write-Host ""
$script:engine_choice = Read-Host "Choose option (1-8, or b)"
}
# Function to prompt for Cloud API Provider options
function Prompt-CloudAPIProviderOptions {
Clear-Host
Write-Host ""
Write-ColorText "Connect Cloud API Provider" -ForegroundColor "White" -Bold
Write-ColorText "Choose your Cloud API Provider:" -ForegroundColor "White"
Write-ColorText "1) OpenAI" -ForegroundColor "Yellow"
Write-ColorText "2) Google (Vertex AI, Gemini)" -ForegroundColor "Yellow"
Write-ColorText "3) Anthropic (Claude)" -ForegroundColor "Yellow"
Write-ColorText "4) Groq" -ForegroundColor "Yellow"
Write-ColorText "5) HuggingFace Inference API" -ForegroundColor "Yellow"
Write-ColorText "6) Azure OpenAI" -ForegroundColor "Yellow"
Write-ColorText "7) Novita" -ForegroundColor "Yellow"
Write-ColorText "b) Back to Main Menu" -ForegroundColor "Yellow"
Write-Host ""
$script:provider_choice = Read-Host "Choose option (1-7, or b)"
}
# Function to prompt for Ollama CPU/GPU options
function Prompt-OllamaOptions {
Clear-Host
Write-Host ""
Write-ColorText "Serve Local with Ollama" -ForegroundColor "White" -Bold
Write-ColorText "Choose how to serve Ollama:" -ForegroundColor "White"
Write-ColorText "1) CPU" -ForegroundColor "Yellow"
Write-ColorText "2) GPU" -ForegroundColor "Yellow"
Write-ColorText "b) Back to Main Menu" -ForegroundColor "Yellow"
Write-Host ""
$script:ollama_choice = Read-Host "Choose option (1-2, or b)"
}
# 1) Use DocsGPT Public API Endpoint (simple and free)
function Use-DocsPublicAPIEndpoint {
Write-Host ""
Write-ColorText "Setting up DocsGPT Public API Endpoint..." -ForegroundColor "White"
# Create .env file
"LLM_NAME=docsgpt" | Out-File -FilePath $ENV_FILE -Encoding utf8 -Force
"VITE_API_STREAMING=true" | Add-Content -Path $ENV_FILE -Encoding utf8
Write-ColorText ".env file configured for DocsGPT Public API." -ForegroundColor "Green"
# Start Docker if needed
$dockerRunning = Check-AndStartDocker
if (-not $dockerRunning) {
Write-ColorText "Docker is required but could not be started. Please start Docker Desktop manually and try again." -ForegroundColor "Red"
return
}
Write-Host ""
Write-ColorText "Starting Docker Compose..." -ForegroundColor "White"
# Run Docker compose commands
try {
& docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" build
if ($LASTEXITCODE -ne 0) {
throw "Docker compose build failed with exit code $LASTEXITCODE"
}
& docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" up -d
if ($LASTEXITCODE -ne 0) {
throw "Docker compose up failed with exit code $LASTEXITCODE"
}
Write-Host ""
Write-ColorText "DocsGPT is now running on http://localhost:5173" -ForegroundColor "Green"
Write-ColorText "You can stop the application by running: docker compose -f `"$COMPOSE_FILE`" down" -ForegroundColor "Yellow"
}
catch {
Write-Host ""
Write-ColorText "Error starting Docker Compose: $_" -ForegroundColor "Red"
Write-ColorText "Please ensure Docker Compose is installed and in your PATH." -ForegroundColor "Red"
Write-ColorText "Refer to Docker documentation for installation instructions: https://docs.docker.com/compose/install/" -ForegroundColor "Red"
exit 1 # Exit script with error
}
}
# 2) Serve Local (with Ollama)
function Serve-LocalOllama {
$script:model_name = ""
$default_model = "llama3.2:1b"
$docker_compose_file_suffix = ""
function Get-ModelNameOllama {
$model_name_input = Read-Host "Enter Ollama Model Name (press Enter for default: $default_model (1.3GB))"
if ([string]::IsNullOrEmpty($model_name_input)) {
$script:model_name = $default_model
} else {
$script:model_name = $model_name_input
}
}
while ($true) {
Clear-Host
Prompt-OllamaOptions
switch ($ollama_choice) {
"1" { # CPU
$docker_compose_file_suffix = "cpu"
Get-ModelNameOllama
break
}
"2" { # GPU
Write-Host ""
Write-ColorText "For this option to work correctly you need to have a supported GPU and configure Docker to utilize it." -ForegroundColor "Yellow"
Write-ColorText "Refer to: https://hub.docker.com/r/ollama/ollama for more information." -ForegroundColor "Yellow"
$confirm_gpu = Read-Host "Continue with GPU setup? (y/b)"
if ($confirm_gpu -eq "y" -or $confirm_gpu -eq "Y") {
$docker_compose_file_suffix = "gpu"
Get-ModelNameOllama
break
}
elseif ($confirm_gpu -eq "b" -or $confirm_gpu -eq "B") {
Clear-Host
return
}
else {
Write-Host ""
Write-ColorText "Invalid choice. Please choose y or b." -ForegroundColor "Red"
Start-Sleep -Seconds 1
}
}
"b" { Clear-Host; return }
"B" { Clear-Host; return }
default {
Write-Host ""
Write-ColorText "Invalid choice. Please choose 1-2, or b." -ForegroundColor "Red"
Start-Sleep -Seconds 1
}
}
if (-not [string]::IsNullOrEmpty($docker_compose_file_suffix)) {
break
}
}
Write-Host ""
Write-ColorText "Configuring for Ollama ($($docker_compose_file_suffix.ToUpper()))..." -ForegroundColor "White"
# Create .env file
"API_KEY=xxxx" | Out-File -FilePath $ENV_FILE -Encoding utf8 -Force
"LLM_NAME=openai" | Add-Content -Path $ENV_FILE -Encoding utf8
"MODEL_NAME=$model_name" | Add-Content -Path $ENV_FILE -Encoding utf8
"VITE_API_STREAMING=true" | Add-Content -Path $ENV_FILE -Encoding utf8
"OPENAI_BASE_URL=http://host.docker.internal:11434/v1" | Add-Content -Path $ENV_FILE -Encoding utf8
"EMBEDDINGS_NAME=huggingface_sentence-transformers/all-mpnet-base-v2" | Add-Content -Path $ENV_FILE -Encoding utf8
Write-ColorText ".env file configured for Ollama ($($docker_compose_file_suffix.ToUpper()))." -ForegroundColor "Green"
Write-ColorText "Note: MODEL_NAME is set to '$model_name'. You can change it later in the .env file." -ForegroundColor "Yellow"
# Start Docker if needed
$dockerRunning = Check-AndStartDocker
if (-not $dockerRunning) {
Write-ColorText "Docker is required but could not be started. Please start Docker Desktop manually and try again." -ForegroundColor "Red"
return
}
# Setup compose file paths
$optional_compose = Join-Path -Path (Split-Path -Parent $COMPOSE_FILE) -ChildPath "optional\docker-compose.optional.ollama-$docker_compose_file_suffix.yaml"
try {
Write-Host ""
Write-ColorText "Starting Docker Compose with Ollama ($docker_compose_file_suffix)..." -ForegroundColor "White"
# Build the containers
& docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" -f "$optional_compose" build
if ($LASTEXITCODE -ne 0) {
throw "Docker compose build failed with exit code $LASTEXITCODE"
}
# Start the containers
& docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" -f "$optional_compose" up -d
if ($LASTEXITCODE -ne 0) {
throw "Docker compose up failed with exit code $LASTEXITCODE"
}
# Wait for Ollama container to be ready
Write-ColorText "Waiting for Ollama container to be ready..." -ForegroundColor "White"
$ollamaReady = $false
$maxAttempts = 30 # Maximum number of attempts (30 x 5 seconds = 2.5 minutes)
$attempts = 0
while (-not $ollamaReady -and $attempts -lt $maxAttempts) {
$containerStatus = & docker compose -f "$COMPOSE_FILE" -f "$optional_compose" ps --services --filter "status=running" --format "{{.Service}}"
if ($containerStatus -like "*ollama*") {
$ollamaReady = $true
Write-ColorText "Ollama container is running." -ForegroundColor "Green"
} else {
Write-Host "Ollama container not yet ready, waiting... (Attempt $($attempts+1)/$maxAttempts)"
Start-Sleep -Seconds 5
$attempts++
}
}
if (-not $ollamaReady) {
Write-ColorText "Ollama container did not start within the expected time. Please check Docker logs for errors." -ForegroundColor "Red"
return
}
# Pull the Ollama model
Write-ColorText "Pulling $model_name model for Ollama..." -ForegroundColor "White"
& docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" -f "$optional_compose" exec -it ollama ollama pull "$model_name"
Write-Host ""
Write-ColorText "DocsGPT is now running with Ollama ($docker_compose_file_suffix) on http://localhost:5173" -ForegroundColor "Green"
Write-ColorText "You can stop the application by running: docker compose -f `"$COMPOSE_FILE`" -f `"$optional_compose`" down" -ForegroundColor "Yellow"
}
catch {
Write-Host ""
Write-ColorText "Error running Docker Compose: $_" -ForegroundColor "Red"
Write-ColorText "Please ensure Docker Compose is installed and in your PATH." -ForegroundColor "Red"
Write-ColorText "Refer to Docker documentation for installation instructions: https://docs.docker.com/compose/install/" -ForegroundColor "Red"
exit 1
}
}
# 3) Connect Local Inference Engine
function Connect-LocalInferenceEngine {
$script:engine_name = ""
$script:openai_base_url = ""
$script:model_name = ""
function Get-ModelName {
$model_name_input = Read-Host "Enter Model Name (press Enter for None)"
if ([string]::IsNullOrEmpty($model_name_input)) {
$script:model_name = "None"
} else {
$script:model_name = $model_name_input
}
}
while ($true) {
Clear-Host
Prompt-LocalInferenceEngineOptions
switch ($engine_choice) {
"1" { # LLaMa.cpp
$script:engine_name = "LLaMa.cpp"
$script:openai_base_url = "http://localhost:8000/v1"
Get-ModelName
break
}
"2" { # Ollama
$script:engine_name = "Ollama"
$script:openai_base_url = "http://localhost:11434/v1"
Get-ModelName
break
}
"3" { # TGI
$script:engine_name = "TGI"
$script:openai_base_url = "http://localhost:8080/v1"
Get-ModelName
break
}
"4" { # SGLang
$script:engine_name = "SGLang"
$script:openai_base_url = "http://localhost:30000/v1"
Get-ModelName
break
}
"5" { # vLLM
$script:engine_name = "vLLM"
$script:openai_base_url = "http://localhost:8000/v1"
Get-ModelName
break
}
"6" { # Aphrodite
$script:engine_name = "Aphrodite"
$script:openai_base_url = "http://localhost:2242/v1"
Get-ModelName
break
}
"7" { # FriendliAI
$script:engine_name = "FriendliAI"
$script:openai_base_url = "http://localhost:8997/v1"
Get-ModelName
break
}
"8" { # LMDeploy
$script:engine_name = "LMDeploy"
$script:openai_base_url = "http://localhost:23333/v1"
Get-ModelName
break
}
"b" { Clear-Host; return }
"B" { Clear-Host; return }
default {
Write-Host ""
Write-ColorText "Invalid choice. Please choose 1-8, or b." -ForegroundColor "Red"
Start-Sleep -Seconds 1
}
}
if (-not [string]::IsNullOrEmpty($script:engine_name)) {
break
}
}
Write-Host ""
Write-ColorText "Configuring for Local Inference Engine: $engine_name..." -ForegroundColor "White"
# Create .env file
"API_KEY=None" | Out-File -FilePath $ENV_FILE -Encoding utf8 -Force
"LLM_NAME=openai" | Add-Content -Path $ENV_FILE -Encoding utf8
"MODEL_NAME=$model_name" | Add-Content -Path $ENV_FILE -Encoding utf8
"VITE_API_STREAMING=true" | Add-Content -Path $ENV_FILE -Encoding utf8
"OPENAI_BASE_URL=$openai_base_url" | Add-Content -Path $ENV_FILE -Encoding utf8
"EMBEDDINGS_NAME=huggingface_sentence-transformers/all-mpnet-base-v2" | Add-Content -Path $ENV_FILE -Encoding utf8
Write-ColorText ".env file configured for $engine_name with OpenAI API format." -ForegroundColor "Green"
Write-ColorText "Note: MODEL_NAME is set to '$model_name'. You can change it later in the .env file." -ForegroundColor "Yellow"
# Start Docker if needed
$dockerRunning = Check-AndStartDocker
if (-not $dockerRunning) {
Write-ColorText "Docker is required but could not be started. Please start Docker Desktop manually and try again." -ForegroundColor "Red"
return
}
try {
Write-Host ""
Write-ColorText "Starting Docker Compose..." -ForegroundColor "White"
# Build the containers
& docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" build
if ($LASTEXITCODE -ne 0) {
throw "Docker compose build failed with exit code $LASTEXITCODE"
}
# Start the containers
& docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" up -d
if ($LASTEXITCODE -ne 0) {
throw "Docker compose up failed with exit code $LASTEXITCODE"
}
Write-Host ""
Write-ColorText "DocsGPT is now configured to connect to $engine_name at $openai_base_url" -ForegroundColor "Green"
Write-ColorText "Ensure your $engine_name inference server is running at that address" -ForegroundColor "Yellow"
Write-Host ""
Write-ColorText "DocsGPT is running at http://localhost:5173" -ForegroundColor "Green"
Write-ColorText "You can stop the application by running: docker compose -f `"$COMPOSE_FILE`" down" -ForegroundColor "Yellow"
}
catch {
Write-Host ""
Write-ColorText "Error running Docker Compose: $_" -ForegroundColor "Red"
Write-ColorText "Please ensure Docker Compose is installed and in your PATH." -ForegroundColor "Red"
Write-ColorText "Refer to Docker documentation for installation instructions: https://docs.docker.com/compose/install/" -ForegroundColor "Red"
exit 1
}
}
# 4) Connect Cloud API Provider
function Connect-CloudAPIProvider {
$script:provider_name = ""
$script:llm_name = ""
$script:model_name = ""
$script:api_key = ""
function Get-APIKey {
Write-ColorText "Your API key will be stored locally in the .env file and will not be sent anywhere else" -ForegroundColor "Yellow"
$script:api_key = Read-Host "Please enter your API key"
}
while ($true) {
Clear-Host
Prompt-CloudAPIProviderOptions
switch ($provider_choice) {
"1" { # OpenAI
$script:provider_name = "OpenAI"
$script:llm_name = "openai"
$script:model_name = "gpt-4o"
Get-APIKey
break
}
"2" { # Google
$script:provider_name = "Google (Vertex AI, Gemini)"
$script:llm_name = "google"
$script:model_name = "gemini-2.0-flash"
Get-APIKey
break
}
"3" { # Anthropic
$script:provider_name = "Anthropic (Claude)"
$script:llm_name = "anthropic"
$script:model_name = "claude-3-5-sonnet-latest"
Get-APIKey
break
}
"4" { # Groq
$script:provider_name = "Groq"
$script:llm_name = "groq"
$script:model_name = "llama-3.1-8b-instant"
Get-APIKey
break
}
"5" { # HuggingFace Inference API
$script:provider_name = "HuggingFace Inference API"
$script:llm_name = "huggingface"
$script:model_name = "meta-llama/Llama-3.1-8B-Instruct"
Get-APIKey
break
}
"6" { # Azure OpenAI
$script:provider_name = "Azure OpenAI"
$script:llm_name = "azure_openai"
$script:model_name = "gpt-4o"
Get-APIKey
break
}
"7" { # Novita
$script:provider_name = "Novita"
$script:llm_name = "novita"
$script:model_name = "deepseek/deepseek-r1"
Get-APIKey
break
}
"b" { Clear-Host; return }
"B" { Clear-Host; return }
default {
Write-Host ""
Write-ColorText "Invalid choice. Please choose 1-7, or b." -ForegroundColor "Red"
Start-Sleep -Seconds 1
}
}
if (-not [string]::IsNullOrEmpty($script:provider_name)) {
break
}
}
Write-Host ""
Write-ColorText "Configuring for Cloud API Provider: $provider_name..." -ForegroundColor "White"
# Create .env file
"API_KEY=$api_key" | Out-File -FilePath $ENV_FILE -Encoding utf8 -Force
"LLM_NAME=$llm_name" | Add-Content -Path $ENV_FILE -Encoding utf8
"MODEL_NAME=$model_name" | Add-Content -Path $ENV_FILE -Encoding utf8
"VITE_API_STREAMING=true" | Add-Content -Path $ENV_FILE -Encoding utf8
Write-ColorText ".env file configured for $provider_name." -ForegroundColor "Green"
# Start Docker if needed
$dockerRunning = Check-AndStartDocker
if (-not $dockerRunning) {
Write-ColorText "Docker is required but could not be started. Please start Docker Desktop manually and try again." -ForegroundColor "Red"
return
}
try {
Write-Host ""
Write-ColorText "Starting Docker Compose..." -ForegroundColor "White"
# Run Docker compose commands
& docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" up -d --build
if ($LASTEXITCODE -ne 0) {
throw "Docker compose build or up failed with exit code $LASTEXITCODE"
}
Write-Host ""
Write-ColorText "DocsGPT is now configured to use $provider_name on http://localhost:5173" -ForegroundColor "Green"
Write-ColorText "You can stop the application by running: docker compose -f `"$COMPOSE_FILE`" down" -ForegroundColor "Yellow"
}
catch {
Write-Host ""
Write-ColorText "Error running Docker Compose: $_" -ForegroundColor "Red"
Write-ColorText "Please ensure Docker Compose is installed and in your PATH." -ForegroundColor "Red"
Write-ColorText "Refer to Docker documentation for installation instructions: https://docs.docker.com/compose/install/" -ForegroundColor "Red"
exit 1
}
}
# Main script execution
Animate-Dino
while ($true) {
Clear-Host
Prompt-MainMenu
$exitLoop = $false # Add this flag
switch ($main_choice) {
"1" {
Use-DocsPublicAPIEndpoint
$exitLoop = $true # Set flag to true on completion
break
}
"2" {
Serve-LocalOllama
# Only exit the loop if user didn't press "b" to go back
if ($ollama_choice -ne "b" -and $ollama_choice -ne "B") {
$exitLoop = $true
}
break
}
"3" {
Connect-LocalInferenceEngine
# Only exit the loop if user didn't press "b" to go back
if ($engine_choice -ne "b" -and $engine_choice -ne "B") {
$exitLoop = $true
}
break
}
"4" {
Connect-CloudAPIProvider
# Only exit the loop if user didn't press "b" to go back
if ($provider_choice -ne "b" -and $provider_choice -ne "B") {
$exitLoop = $true
}
break
}
default {
Write-Host ""
Write-ColorText "Invalid choice. Please choose 1-4." -ForegroundColor "Red"
Start-Sleep -Seconds 1
}
}
# Only break out of the loop if a function completed successfully
if ($exitLoop) {
break
}
}
Write-Host ""
Write-ColorText "DocsGPT Setup Complete." -ForegroundColor "Green"
exit 0