Files
cyclop/run_python_with_restart.ps1
T

67 lines
1.9 KiB
PowerShell
Raw Normal View History

param(
[Parameter(Mandatory=$true)]
[ValidateSet("Claude", "OpenAI")]
[string]$Model
)
function Run-PythonScript {
param($ScriptPath)
$process = Start-Process -FilePath "python" -ArgumentList $ScriptPath -PassThru -Wait -NoNewWindow
return $process.ExitCode
}
function Run-Tests {
$process = Start-Process -FilePath "powershell" -ArgumentList "-File run_tests.ps1" -PassThru -Wait -NoNewWindow
return $process.ExitCode
}
function Git-Pull {
git pull
return $LASTEXITCODE -eq 0
}
if ($Model -eq "Claude") {
New-Item -ItemType File -Path ".reboot_claude" -Force
} elseif ($Model -eq "OpenAI") {
New-Item -ItemType File -Path ".reboot_openai" -Force
}
$waitTime = 30
2024-08-20 13:11:24 -05:00
while ($true) {
2024-08-20 17:10:30 -05:00
python -m pip install -r requirements.txt
Write-Host "Running tests..."
$testExitCode = Run-Tests
if ($testExitCode -ne 0) {
2024-08-20 18:01:43 -05:00
Write-Host "Tests failed. Attempting git pull and waiting $waitTime seconds before next attempt..."
Git-Pull
Start-Sleep -Seconds $waitTime
continue
}
$scriptPath = ".\chatgpt_telegram_inference_bot.py" # Default to ChatGPT
Remove-Item -Path ".\.reboot_openai" -Force
if (Test-Path -Path ".\.reboot_claude") { # But if both are specified, choose Claude
$scriptPath = ".\anthropic_telegram_inference_bot.py"
Remove-Item -Path ".\.reboot_claude" -Force
}
Write-Host "Tests passed. Starting main Python script..."
$exitCode = Run-PythonScript -ScriptPath $scriptPath
2024-08-20 13:11:24 -05:00
if (Test-Path -Path ".\.doreboot") {
Write-Host "Special filename detected. Attempting git pull..."
if (Git-Pull) {
Write-Host "Git pull successful. Restarting Python script..."
continue
} else {
Write-Host "Git pull failed. Waiting $waitTime seconds before next attempt..."
}
} else {
2024-08-20 13:11:24 -05:00
exit 1
}
Start-Sleep -Seconds $waitTime
2024-08-20 13:11:24 -05:00
}