-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart_foxforge.ps1
More file actions
executable file
·160 lines (135 loc) · 4.77 KB
/
Copy pathstart_foxforge.ps1
File metadata and controls
executable file
·160 lines (135 loc) · 4.77 KB
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
param(
[string]$OllamaExe = "",
[string]$OllamaModels = "",
[string]$OllamaHost = "0.0.0.0:11434",
[string]$OllamaLogLevel = "info",
[switch]$EnableVulkan,
[switch]$NoRestartOllama
)
$ErrorActionPreference = "Stop"
$RepoRoot = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path }
function Resolve-OllamaExe {
param([string]$Preferred)
$candidates = New-Object System.Collections.Generic.List[string]
if (-not [string]::IsNullOrWhiteSpace($Preferred)) {
$candidates.Add($Preferred.Trim())
}
try {
$cmd = Get-Command ollama -ErrorAction Stop
if ($cmd -and $cmd.Source) {
$candidates.Add([string]$cmd.Source)
}
}
catch {}
if ($env:LOCALAPPDATA) {
$candidates.Add((Join-Path $env:LOCALAPPDATA "Programs\Ollama\ollama.exe"))
}
if ($env:ProgramFiles) {
$candidates.Add((Join-Path $env:ProgramFiles "Ollama\ollama.exe"))
}
$programFilesX86 = [Environment]::GetEnvironmentVariable("ProgramFiles(x86)")
if ($programFilesX86) {
$candidates.Add((Join-Path $programFilesX86 "Ollama\ollama.exe"))
}
foreach ($candidate in ($candidates | Select-Object -Unique)) {
if ($candidate -and (Test-Path $candidate)) {
return (Resolve-Path $candidate).Path
}
}
return ""
}
function Resolve-OllamaModels {
param([string]$Preferred)
$candidates = New-Object System.Collections.Generic.List[string]
if (-not [string]::IsNullOrWhiteSpace($Preferred)) {
$candidates.Add($Preferred.Trim())
}
foreach ($value in @(
$env:OLLAMA_MODELS,
[Environment]::GetEnvironmentVariable("OLLAMA_MODELS", "User"),
[Environment]::GetEnvironmentVariable("OLLAMA_MODELS", "Machine")
)) {
if (-not [string]::IsNullOrWhiteSpace($value)) {
$candidates.Add($value.Trim())
}
}
if ($env:USERPROFILE) {
$candidates.Add((Join-Path $env:USERPROFILE ".ollama\models"))
}
if ($env:LOCALAPPDATA) {
$candidates.Add((Join-Path $env:LOCALAPPDATA "Ollama\models"))
}
foreach ($candidate in ($candidates | Select-Object -Unique)) {
if ($candidate -and (Test-Path $candidate)) {
return (Resolve-Path $candidate).Path
}
}
if ($env:USERPROFILE) {
return (Join-Path $env:USERPROFILE ".ollama\models")
}
return ""
}
function Test-ModelStore {
param([string]$Path)
$blobs = Join-Path $Path "blobs"
$manifests = Join-Path $Path "manifests"
return (Test-Path $blobs) -and (Test-Path $manifests)
}
$ResolvedOllamaExe = Resolve-OllamaExe -Preferred $OllamaExe
if (-not $ResolvedOllamaExe) {
throw "Ollama executable not found. Install Ollama or pass -OllamaExe <path>."
}
$ResolvedOllamaModels = Resolve-OllamaModels -Preferred $OllamaModels
if (-not $ResolvedOllamaModels) {
throw "Could not resolve an Ollama model directory. Pass -OllamaModels <path>."
}
if (-not (Test-Path $ResolvedOllamaModels)) {
New-Item -ItemType Directory -Force -Path $ResolvedOllamaModels | Out-Null
Write-Warning "Created model directory: $ResolvedOllamaModels"
}
if (-not (Test-ModelStore -Path $ResolvedOllamaModels)) {
Write-Warning "Model directory does not contain both 'blobs' and 'manifests'. Confirm models were copied correctly."
}
# Set for this session and persist for future launches.
$env:OLLAMA_MODELS = $ResolvedOllamaModels
$env:OLLAMA_HOST = $OllamaHost
$env:OLLAMA_LOG_LEVEL = $OllamaLogLevel
if ($EnableVulkan) {
$env:OLLAMA_VULKAN = "1"
}
[Environment]::SetEnvironmentVariable("OLLAMA_MODELS", $ResolvedOllamaModels, "User")
if (-not $NoRestartOllama) {
Get-Process | Where-Object { $_.ProcessName -like "ollama*" } | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1
}
Start-Process -FilePath $ResolvedOllamaExe -ArgumentList "serve" -WindowStyle Hidden
$ready = $false
for ($i = 0; $i -lt 30; $i++) {
try {
$null = Invoke-RestMethod -Uri "http://127.0.0.1:11434/api/tags" -Method Get -TimeoutSec 2
$ready = $true
break
}
catch {
Start-Sleep -Seconds 1
}
}
if (-not $ready) {
throw "Ollama did not become ready on http://127.0.0.1:11434"
}
Write-Host "Ollama started from: $ResolvedOllamaExe"
Write-Host "OLLAMA_MODELS: $env:OLLAMA_MODELS"
Write-Host "OLLAMA_HOST: $env:OLLAMA_HOST"
Write-Host "OLLAMA_LOG_LEVEL: $env:OLLAMA_LOG_LEVEL"
if ($EnableVulkan) {
Write-Host "OLLAMA_VULKAN: $env:OLLAMA_VULKAN"
}
Write-Host "Local models:"
& $ResolvedOllamaExe list
Write-Host ""
Write-Host "Starting Foxforge TUI..."
$orchestratorMain = Join-Path $RepoRoot "SourceCode\orchestrator\main.py"
if (-not (Test-Path $orchestratorMain)) {
throw "Foxforge orchestrator entrypoint not found: $orchestratorMain"
}
python $orchestratorMain