-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
210 lines (193 loc) · 7.77 KB
/
setup.ps1
File metadata and controls
210 lines (193 loc) · 7.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
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
# CodeInsight Setup Script
# Creates a virtual environment and installs dependencies
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "CodeInsight Setup" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Check if Python is available
Write-Host "Checking Python installation..." -ForegroundColor Yellow
try {
$pythonVersion = python --version 2>&1
if ($LASTEXITCODE -ne 0) {
throw "Python not found"
}
Write-Host "Found: $pythonVersion" -ForegroundColor Green
# Check Python version (3.10+)
$versionMatch = $pythonVersion -match "Python (\d+)\.(\d+)"
if ($versionMatch) {
$majorVersion = [int]$matches[1]
$minorVersion = [int]$matches[2]
if ($majorVersion -lt 3 -or ($majorVersion -eq 3 -and $minorVersion -lt 10)) {
Write-Host "ERROR: Python 3.10 or higher is required. Found Python $majorVersion.$minorVersion" -ForegroundColor Red
exit 1
}
}
}
catch {
Write-Host "ERROR: Python is not installed or not in PATH" -ForegroundColor Red
Write-Host "Please install Python 3.10 or higher from https://www.python.org/downloads/" -ForegroundColor Yellow
exit 1
}
# Check if .venv already exists
if (Test-Path ".venv") {
Write-Host "Virtual environment '.venv' already exists." -ForegroundColor Yellow
Write-Host "Skipping virtual environment creation." -ForegroundColor Yellow
Write-Host ""
}
else {
Write-Host "Creating virtual environment '.venv'..." -ForegroundColor Yellow
python -m venv .venv
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to create virtual environment" -ForegroundColor Red
exit 1
}
Write-Host "Virtual environment created successfully!" -ForegroundColor Green
Write-Host ""
}
# Activate virtual environment
Write-Host "Activating virtual environment..." -ForegroundColor Yellow
$activateScript = ".venv\Scripts\Activate.ps1"
if (-not (Test-Path $activateScript)) {
Write-Host "ERROR: Virtual environment activation script not found" -ForegroundColor Red
exit 1
}
# Handle PowerShell execution policy
$executionPolicy = Get-ExecutionPolicy
if ($executionPolicy -eq "Restricted") {
Write-Host "WARNING: PowerShell execution policy is Restricted" -ForegroundColor Yellow
Write-Host "Attempting to activate virtual environment..." -ForegroundColor Yellow
Write-Host "If activation fails, run: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser" -ForegroundColor Yellow
Write-Host ""
}
try {
& $activateScript
if ($LASTEXITCODE -ne 0) {
Write-Host "WARNING: Virtual environment activation may have failed" -ForegroundColor Yellow
Write-Host "You may need to activate manually: .venv\Scripts\Activate.ps1" -ForegroundColor Yellow
}
}
catch {
Write-Host "WARNING: Could not activate virtual environment automatically" -ForegroundColor Yellow
Write-Host "Please activate manually: .venv\Scripts\Activate.ps1" -ForegroundColor Yellow
Write-Host ""
}
# Upgrade pip
Write-Host "Upgrading pip..." -ForegroundColor Yellow
python -m pip install --upgrade pip --quiet
if ($LASTEXITCODE -ne 0) {
Write-Host "WARNING: Failed to upgrade pip" -ForegroundColor Yellow
}
else {
Write-Host "pip upgraded successfully!" -ForegroundColor Green
}
Write-Host ""
# Install requirements
Write-Host "Installing dependencies from requirements.txt..." -ForegroundColor Yellow
if (-not (Test-Path "requirements.txt")) {
Write-Host "ERROR: requirements.txt not found" -ForegroundColor Red
exit 1
}
python -m pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to install dependencies" -ForegroundColor Red
exit 1
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Setup completed successfully!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
if ($env:VIRTUAL_ENV) {
Write-Host "1. Virtual Environment:" -ForegroundColor White
Write-Host " Active ($env:VIRTUAL_ENV)" -ForegroundColor Green
}
else {
Write-Host "1. Activate the virtual environment:" -ForegroundColor White
Write-Host " .venv\Scripts\Activate.ps1" -ForegroundColor Cyan
Write-Host " (Note: If this script was not run with '. .\setup.ps1', the environment is not active in your current shell)" -ForegroundColor DarkGray
}
Write-Host ""
# Copy Config Files
Write-Host "Checking configuration files..." -ForegroundColor Yellow
if (-not (Test-Path ".env")) {
if (Test-Path ".env.example") {
Write-Host "Copying .env.example to .env..." -ForegroundColor Yellow
Copy-Item ".env.example" ".env"
Write-Host ".env created successfully!" -ForegroundColor Green
}
else {
Write-Host "WARNING: .env.example not found. Please create .env manually." -ForegroundColor Red
}
}
else {
Write-Host ".env already exists. Skipping." -ForegroundColor Yellow
}
if (-not (Test-Path "config.yaml")) {
if (Test-Path "config.yaml.example") {
Write-Host "Copying config.yaml.example to config.yaml..." -ForegroundColor Yellow
Copy-Item "config.yaml.example" "config.yaml"
Write-Host "config.yaml created successfully!" -ForegroundColor Green
}
}
Write-Host ""
# Setup Langfuse (Docker)
Write-Host "Setting up Langfuse..." -ForegroundColor Yellow
if (Get-Command "docker" -ErrorAction SilentlyContinue) {
if (Test-Path "langfuse/docker-compose.yml") {
Write-Host "Starting Langfuse services..." -ForegroundColor Yellow
docker compose -f langfuse/docker-compose.yml up -d
if ($LASTEXITCODE -ne 0) {
Write-Host "WARNING: Failed to start Langfuse services. Please check Docker Desktop." -ForegroundColor Red
}
else {
Write-Host "Langfuse services started!" -ForegroundColor Green
}
}
else {
Write-Host "WARNING: langfuse/docker-compose.yml not found." -ForegroundColor Red
}
}
else {
Write-Host "WARNING: Docker is not installed or not in PATH. Skipping Langfuse setup." -ForegroundColor Red
}
Write-Host ""
# Initialize Database
Write-Host "Initializing database..." -ForegroundColor Yellow
$venvPython = ".venv\Scripts\python.exe"
if (Test-Path $venvPython) {
if (Test-Path "scripts/init_database.py") {
& $venvPython scripts/init_database.py
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Database initialization failed." -ForegroundColor Red
exit 1
}
Write-Host "Database initialized successfully!" -ForegroundColor Green
}
else {
Write-Host "WARNING: scripts/init_database.py not found." -ForegroundColor Red
}
}
else {
Write-Host "ERROR: Virtual environment python not found at $venvPython" -ForegroundColor Red
exit 1
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Setup completed successfully!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
if ($env:VIRTUAL_ENV) {
Write-Host "1. Virtual Environment:" -ForegroundColor White
Write-Host " Active ($env:VIRTUAL_ENV)" -ForegroundColor Green
}
else {
Write-Host "1. Activate the virtual environment:" -ForegroundColor White
Write-Host " .venv\Scripts\Activate.ps1" -ForegroundColor Cyan
Write-Host " (Note: If this script was not run with '. .\setup.ps1', the environment is not active in your current shell)" -ForegroundColor DarkGray
}
Write-Host ""
Write-Host "2. Start the application:" -ForegroundColor White
Write-Host " streamlit run ui/app.py" -ForegroundColor Cyan
Write-Host ""