-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-perknow.ps1
More file actions
180 lines (149 loc) · 4.68 KB
/
start-perknow.ps1
File metadata and controls
180 lines (149 loc) · 4.68 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Quick start script for Perknow knowledge management system
.DESCRIPTION
Starts the Perknow web server and AI gardener worker, finding an available port automatically
#>
param(
[int]$StartPort = 8000,
[int]$MaxPort = 9000,
[switch]$NoBrowser
)
$ErrorActionPreference = "Stop"
# Colors for output
$Green = "`e[32m"
$Yellow = "`e[33m"
$Red = "`e[31m"
$Blue = "`e[34m"
$Reset = "`e[0m"
function Write-Status($message, $color = $Green) {
Write-Host "$color[PERKNOW]$Reset $message"
}
function Write-Error($message) {
Write-Host "$Red[ERROR]$Reset $message"
}
function Write-Info($message) {
Write-Host "$Blue[INFO]$Reset $message"
}
function Write-Warn($message) {
Write-Host "$Yellow[WARN]$Reset $message"
}
# Check if we're in the right directory
if (-not (Test-Path "perknow/main.py")) {
Write-Error "Not in perknow project root directory. Please cd to the project folder."
exit 1
}
Write-Status "Starting Perknow Knowledge Management System..."
Write-Info "Project directory: $(Get-Location)"
# Check Python/uvicorn availability
try {
$uvicornVersion = uvicorn --version 2>&1
Write-Info "Uvicorn found: $uvicornVersion"
} catch {
Write-Error "uvicorn not found. Run: pip install -r requirements.txt"
exit 1
}
# Check Ollama
try {
$ollamaPs = Get-Process ollama -ErrorAction SilentlyContinue
if (-not $ollamaPs) {
Write-Warn "Ollama process not detected. Attempting to start..."
Start-Process ollama -ArgumentList "serve" -WindowStyle Hidden
Start-Sleep -Seconds 3
}
# Test Ollama API
$testResponse = Invoke-RestMethod -Uri "http://localhost:11434/api/tags" -Method GET -TimeoutSec 5
Write-Info "Ollama is running at http://localhost:11434"
# Check for required models
$requiredModels = @("nomic-embed-text", "llama3.2")
$availableModels = $testResponse.models | ForEach-Object { $_.name }
foreach ($model in $requiredModels) {
$found = $availableModels | Where-Object { $_ -like "$model*" }
if ($found) {
Write-Info "Model ready: $found"
} else {
Write-Warn "Model not found: $model. Run: ollama pull $model"
}
}
} catch {
Write-Error "Ollama not responding. Ensure Ollama is installed and running."
Write-Info "Download from: https://ollama.com/download"
exit 1
}
# Find available port
Write-Info "Searching for available port starting from $StartPort..."
$port = $StartPort
$foundPort = $false
while ($port -lt $MaxPort) {
$connection = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue
if (-not $connection) {
$foundPort = $true
break
}
$port++
}
if (-not $foundPort) {
Write-Error "No available ports found between $StartPort and $MaxPort"
exit 1
}
Write-Status "Found available port: $port"
# Initialize directories
$dataDir = "data"
$exportDir = "export"
if (-not (Test-Path $dataDir)) {
New-Item -ItemType Directory -Path $dataDir | Out-Null
Write-Info "Created directory: $dataDir"
}
if (-not (Test-Path $exportDir)) {
New-Item -ItemType Directory -Path $exportDir | Out-Null
Write-Info "Created directory: $exportDir"
}
# Initialize git in export if not already
if (-not (Test-Path "$exportDir/.git")) {
Write-Info "Initializing git repository in export/"
Push-Location $exportDir
git init 2>&1 | Out-Null
Pop-Location
}
# Start the gardener worker in a new window
Write-Status "Starting AI Gardener worker..."
$gardenerJob = Start-Job -ScriptBlock {
param($location)
Set-Location $location
python scripts/gardener_worker.py
} -ArgumentList (Get-Location)
Start-Sleep -Seconds 1
# Check if gardener started
if ($gardenerJob.State -eq "Failed") {
Write-Error "Gardener worker failed to start"
Receive-Job $gardenerJob
exit 1
}
Write-Status "Gardener worker started (Job ID: $($gardenerJob.Id))"
# Start the web server
Write-Status "Starting web server on http://localhost:$port ..."
Write-Info "Press Ctrl+C to stop both server and gardener"
if (-not $NoBrowser) {
# Open browser after a short delay
Start-Job -ScriptBlock {
param($port)
Start-Sleep -Seconds 3
Start-Process "http://localhost:$port"
} -ArgumentList $port | Out-Null
}
try {
# Run uvicorn (this blocks until Ctrl+C)
uvicorn perknow.main:app --host 0.0.0.0 --port $port --reload
} finally {
# Cleanup on exit
Write-Host "`n"
Write-Warn "Shutting down..."
# Stop the gardener job
if ($gardenerJob) {
Stop-Job $gardenerJob
Remove-Job $gardenerJob
Write-Info "Gardener worker stopped"
}
Write-Status "Perknow stopped. Goodbye!"
}