-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
314 lines (284 loc) · 12.2 KB
/
install.ps1
File metadata and controls
314 lines (284 loc) · 12.2 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
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
# =============================================================================
# NVHive — Windows PowerShell Installer
#
# Install (run as regular user — no admin needed):
# iwr -useb https://raw.githubusercontent.com/hitechcloud-vietnam/nvHive/main/install.ps1 | iex
#
# What lives in ~/nvh/:
# ~/nvh/repo/ — the NVHive source code
# ~/nvh/venv/ — Python virtual environment
# ~/.hive/ — Config, database, API keys
# =============================================================================
$ErrorActionPreference = "Stop"
$NVH_HOME = if ($env:NVH_HOME) { $env:NVH_HOME } else { "$HOME\nvh" }
$NVH_VENV = "$NVH_HOME\venv"
$NVH_REPO = "$NVH_HOME\repo"
$HIVE_DIR = "$HOME\.hive"
function Write-Green { param($msg) Write-Host $msg -ForegroundColor Green }
function Write-Yellow { param($msg) Write-Host $msg -ForegroundColor Yellow }
function Write-Blue { param($msg) Write-Host $msg -ForegroundColor Cyan }
function Write-Red { param($msg) Write-Host $msg -ForegroundColor Red }
function Write-Gray { param($msg) Write-Host $msg -ForegroundColor DarkGray }
Write-Host ""
Write-Green "╔══════════════════════════════════════╗"
Write-Green "║ NVHive — Windows Quick Install ║"
Write-Green "╚══════════════════════════════════════╝"
Write-Host ""
# ---------------------------------------------------------------------------
# Find Python 3.11+
# ---------------------------------------------------------------------------
function Find-Python {
foreach ($py in @("python3.12", "python3.11", "python3.13", "python3", "python")) {
$p = Get-Command $py -ErrorAction SilentlyContinue
if ($p) {
$ver = & $p.Source --version 2>&1
if ($ver -match "3\.(1[1-9]|[2-9]\d)") { return $p.Source }
}
}
# Check py launcher (Windows Python Launcher)
$py = Get-Command py -ErrorAction SilentlyContinue
if ($py) {
$ver = & py --version 2>&1
if ($ver -match "3\.(1[1-9]|[2-9]\d)") { return "py" }
}
return $null
}
$PYTHON = Find-Python
if (-not $PYTHON) {
Write-Yellow "Python 3.11+ not found."
Write-Blue "Trying winget install..."
try {
winget install Python.Python.3.12 --accept-package-agreements --accept-source-agreements
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "User") + ";" + $env:PATH
$PYTHON = Find-Python
} catch {
Write-Red "Could not install Python automatically."
Write-Yellow "Please install Python 3.12 from https://python.org/downloads"
Write-Yellow "Make sure to check 'Add Python to PATH' during install."
exit 1
}
}
Write-Gray "Python: $(& $PYTHON --version 2>&1) [$PYTHON]"
# ---------------------------------------------------------------------------
# Detect NVIDIA GPU via nvidia-smi
# ---------------------------------------------------------------------------
$GPU_NAME = ""
$VRAM_GB = 0
$nvidiaSmi = Get-Command nvidia-smi -ErrorAction SilentlyContinue
if ($nvidiaSmi) {
try {
$gpuInfo = nvidia-smi --query-gpu=name,memory.total --format=csv,noheader 2>$null
if ($gpuInfo) {
$parts = $gpuInfo.Trim() -split ",\s*"
$GPU_NAME = $parts[0].Trim()
$VRAM_MB = [int]($parts[1] -replace "[^0-9]","")
$VRAM_GB = [math]::Floor($VRAM_MB / 1024)
Write-Green "GPU: $GPU_NAME (${VRAM_GB}GB VRAM)"
}
} catch { }
}
if (-not $GPU_NAME) { Write-Yellow "No NVIDIA GPU detected — CPU mode" }
# ---------------------------------------------------------------------------
# Fast path: already installed
# ---------------------------------------------------------------------------
if ((Test-Path $NVH_REPO) -and (Test-Path $NVH_VENV)) {
$venvPy = "$NVH_VENV\Scripts\python.exe"
if (Test-Path $venvPy) {
Write-Blue "Existing install found — updating..."
& $venvPy -m pip install -q --upgrade pip 2>$null
& $venvPy -m pip install -q -e $NVH_REPO 2>$null
} else {
Write-Yellow "Recreating venv..."
Remove-Item -Recurse -Force $NVH_VENV -ErrorAction SilentlyContinue
& $PYTHON -m venv $NVH_VENV
& "$NVH_VENV\Scripts\pip" install -q --upgrade pip 2>$null
& "$NVH_VENV\Scripts\pip" install -q -e $NVH_REPO 2>$null
}
Write-Green "NVHive ready."
Write-Host ""
Write-Host " Type " -NoNewline; Write-Green "nvh" -NoNewline; Write-Host " to start chatting"
Write-Host ""
exit 0
}
# ---------------------------------------------------------------------------
# Fresh install
# ---------------------------------------------------------------------------
Write-Blue "Fresh install — setting up ~/nvh/..."
New-Item -ItemType Directory -Force -Path $NVH_HOME | Out-Null
# Clone repo
Write-Blue "Downloading NVHive..."
$git = Get-Command git -ErrorAction SilentlyContinue
if ($git) {
git clone --depth 1 -q https://github.com/hitechcloud-vietnam/nvHive.git $NVH_REPO 2>$null
if ($LASTEXITCODE -ne 0) {
New-Item -ItemType Directory -Force -Path $NVH_REPO | Out-Null
Invoke-WebRequest -Uri "https://github.com/hitechcloud-vietnam/nvHive/archive/refs/heads/main.zip" `
-OutFile "$NVH_HOME\nvhive.zip"
Expand-Archive -Path "$NVH_HOME\nvhive.zip" -DestinationPath "$NVH_HOME\nvhive-main" -Force
Move-Item "$NVH_HOME\nvhive-main\nvHive-main\*" $NVH_REPO -Force
Remove-Item "$NVH_HOME\nvhive.zip","$NVH_HOME\nvhive-main" -Recurse -Force
}
} else {
New-Item -ItemType Directory -Force -Path $NVH_REPO | Out-Null
Write-Blue "Downloading via zip (git not found)..."
Invoke-WebRequest -Uri "https://github.com/hitechcloud-vietnam/nvHive/archive/refs/heads/main.zip" `
-OutFile "$NVH_HOME\nvhive.zip"
Expand-Archive -Path "$NVH_HOME\nvhive.zip" -DestinationPath "$NVH_HOME\_extract" -Force
Move-Item "$NVH_HOME\_extract\nvHive-main\*" $NVH_REPO -Force
Remove-Item "$NVH_HOME\nvhive.zip","$NVH_HOME\_extract" -Recurse -Force
}
# Create venv
Write-Blue "Creating Python environment..."
& $PYTHON -m venv $NVH_VENV
& "$NVH_VENV\Scripts\pip" install -q --upgrade pip 2>$null
# Install
Write-Blue "Installing NVHive (~60s)..."
& "$NVH_VENV\Scripts\pip" install -q -e $NVH_REPO 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Red "Install failed. Check Python version (need 3.11+)."
exit 1
}
# ---------------------------------------------------------------------------
# Auto-config
# ---------------------------------------------------------------------------
New-Item -ItemType Directory -Force -Path $HIVE_DIR | Out-Null
$configFile = "$HIVE_DIR\config.yaml"
if (-not (Test-Path $configFile)) {
Write-Blue "Creating auto-config..."
@'
version: "1"
defaults:
mode: ask
output: text
stream: true
max_tokens: 4096
temperature: 1.0
show_metadata: true
advisors:
ollama:
base_url: http://localhost:11434
default_model: ollama/nemotron-small
type: ollama
enabled: true
llm7:
default_model: deepseek-r1-0528
type: llm7
enabled: true
groq:
api_key: ${GROQ_API_KEY}
default_model: groq/llama-3.3-70b-versatile
enabled: false
openai:
api_key: ${OPENAI_API_KEY}
default_model: gpt-4o
enabled: false
anthropic:
api_key: ${ANTHROPIC_API_KEY}
default_model: claude-sonnet-4-6
enabled: false
budget:
daily_limit_usd: 10
monthly_limit_usd: 50
hard_stop: true
cache:
enabled: true
ttl_seconds: 86400
max_size: 1000
'@ | Set-Content -Path $configFile -Encoding UTF8
Write-Green "Config created: $configFile"
}
# ---------------------------------------------------------------------------
# Add venv Scripts dir to user PATH
# ---------------------------------------------------------------------------
$scriptsDir = "$NVH_VENV\Scripts"
$userPath = [System.Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -notlike "*$scriptsDir*") {
[System.Environment]::SetEnvironmentVariable(
"PATH", "$scriptsDir;$userPath", "User"
)
$env:PATH = "$scriptsDir;$env:PATH"
Write-Green "Added $scriptsDir to user PATH"
}
# ---------------------------------------------------------------------------
# Install Ollama for Windows (only if NVIDIA GPU present)
# ---------------------------------------------------------------------------
if ($GPU_NAME) {
$ollamaCmd = Get-Command ollama -ErrorAction SilentlyContinue
if (-not $ollamaCmd) {
Write-Blue "Installing Ollama..."
try {
winget install Ollama.Ollama --accept-package-agreements --accept-source-agreements 2>$null
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "User") + ";$env:PATH"
$ollamaCmd = Get-Command ollama -ErrorAction SilentlyContinue
} catch { }
if (-not $ollamaCmd) {
Write-Yellow "winget install failed, trying direct download..."
$ollamaInstaller = "$NVH_HOME\OllamaSetup.exe"
Invoke-WebRequest -Uri "https://ollama.com/download/OllamaSetup.exe" `
-OutFile $ollamaInstaller
Start-Process -FilePath $ollamaInstaller -ArgumentList "/SILENT" -Wait
Remove-Item $ollamaInstaller -ErrorAction SilentlyContinue
$ollamaCmd = Get-Command ollama -ErrorAction SilentlyContinue
}
}
if ($ollamaCmd) {
# Start Ollama service
$ollamaRunning = try { (Invoke-WebRequest "http://localhost:11434/api/tags" -UseBasicParsing -TimeoutSec 2).StatusCode -eq 200 } catch { $false }
if (-not $ollamaRunning) {
Write-Blue "Starting Ollama..."
Start-Process ollama -ArgumentList "serve" -WindowStyle Hidden
Start-Sleep -Seconds 3
}
# Pick model based on VRAM
$model = if ($VRAM_GB -ge 80) { "nemotron:120b" }
elseif ($VRAM_GB -ge 24) { "nemotron" }
elseif ($VRAM_GB -ge 6 ) { "nemotron-small" }
else { "nemotron-mini" }
$ollamaRunning = try { (Invoke-WebRequest "http://localhost:11434/api/tags" -UseBasicParsing -TimeoutSec 2).StatusCode -eq 200 } catch { $false }
if ($ollamaRunning) {
$modelList = ollama list 2>$null
if ($modelList -notlike "*$model*") {
Write-Blue "Pulling $model in background (you can start using nvh now)..."
Start-Process ollama -ArgumentList "pull $model" -WindowStyle Hidden
} else {
Write-Green "Model $model ready."
}
}
}
} else {
Write-Yellow "No NVIDIA GPU — skipping Ollama install. Use cloud providers: nvh setup"
}
# ---------------------------------------------------------------------------
# Optional: Create Start Menu shortcut
# ---------------------------------------------------------------------------
try {
$startMenu = [System.Environment]::GetFolderPath("Programs")
$shortcut = "$startMenu\NVHive.lnk"
$shell = New-Object -ComObject WScript.Shell
$lnk = $shell.CreateShortcut($shortcut)
$lnk.TargetPath = "cmd.exe"
$lnk.Arguments = "/k `"$scriptsDir\nvh.exe`""
$lnk.WorkingDirectory = $HOME
$lnk.Description = "NVHive Multi-LLM Orchestration"
$lnk.Save()
Write-Green "Start Menu shortcut created: NVHive"
} catch {
# Non-fatal — shortcut creation can fail in some environments
}
Write-Host ""
Write-Green "╔══════════════════════════════════════╗"
Write-Green "║ NVHive is ready! ║"
Write-Green "╚══════════════════════════════════════╝"
Write-Host ""
Write-Host " " -NoNewline; Write-Green "nvh" -NoNewline
Write-Host " Start chatting"
Write-Host " " -NoNewline; Write-Green "nvh setup" -NoNewline
Write-Host " Add more free AI providers"
Write-Host " " -NoNewline; Write-Green "nvh status" -NoNewline
Write-Host " System overview"
Write-Host ""
Write-Gray " Install dir: ~/nvh/"
Write-Gray " Config: ~/.hive/config.yaml"
Write-Host ""
Write-Gray "(Restart your terminal for PATH changes to take effect)"
Write-Host ""