Created
March 18, 2026 08:09
-
-
Save simmessa/5cdbacabaebf6dd77065183c89c53282 to your computer and use it in GitHub Desktop.
llama updater in powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # llama_update.ps1 | |
| # Automatically check for and update llama.cpp releases | |
| $ErrorActionPreference = "Stop" | |
| # Configuration | |
| $releasesUrl = "https://github.com/ggml-org/llama.cpp/releases" | |
| $downloadPath = "C:\ai" | |
| $batFilePath = "C:\ai\llama_start.bat" | |
| Write-Host "Checking for llama.cpp updates..." -ForegroundColor Cyan | |
| # Fetch the releases page and find the latest build number | |
| try { | |
| $response = Invoke-WebRequest -Uri $releasesUrl -UseBasicParsing | |
| # Find all release tags in format b#### (b followed by digits like b1234, b3914, etc.) | |
| $buildMatches = [regex]::Matches($response.Content, 'releases/tag/(b\d+)') | |
| if ($buildMatches.Count -eq 0) { | |
| Write-Host "Error: Could not find any build releases on the releases page" -ForegroundColor Red | |
| Write-Host "Debug: First 500 characters of response:" -ForegroundColor Yellow | |
| Write-Host $response.Content.Substring(0, [Math]::Min(500, $response.Content.Length)) | |
| exit 1 | |
| } | |
| # Extract unique build numbers and find the highest | |
| $latestBuild = ($buildMatches | ForEach-Object { | |
| $tagValue = $_.Groups[1].Value | |
| [PSCustomObject]@{ | |
| Tag = $tagValue | |
| Number = [int]($tagValue -replace 'b', '') | |
| } | |
| } | Sort-Object -Property Number -Descending -Unique | Select-Object -First 1) | |
| $latestBuildTag = $latestBuild.Tag | |
| $latestBuildNumber = $latestBuild.Number | |
| Write-Host "Latest release found: $latestBuildTag (build number: $latestBuildNumber)" -ForegroundColor Green | |
| } | |
| catch { | |
| Write-Host "Error fetching releases page: $_" -ForegroundColor Red | |
| exit 1 | |
| } | |
| # Check current version in llama_start.bat | |
| if (-not (Test-Path $batFilePath)) { | |
| Write-Host "Error: $batFilePath not found" -ForegroundColor Red | |
| exit 1 | |
| } | |
| $batContent = Get-Content $batFilePath -Raw | |
| $currentBuildMatch = [regex]::Match($batContent, 'set\s+"build=(b\d+)"') | |
| if (-not $currentBuildMatch.Success) { | |
| Write-Host "Error: Could not find 'set `"build=bxxxx`"' in $batFilePath" -ForegroundColor Red | |
| Write-Host "Debug: File content preview:" -ForegroundColor Yellow | |
| Write-Host ($batContent.Substring(0, [Math]::Min(200, $batContent.Length))) | |
| exit 1 | |
| } | |
| $currentBuildTag = $currentBuildMatch.Groups[1].Value | |
| $currentBuildNumber = [int]($currentBuildTag -replace 'b', '') | |
| Write-Host "Current build: $currentBuildTag" -ForegroundColor Yellow | |
| # Compare versions | |
| if ($latestBuildNumber -le $currentBuildNumber) { | |
| Write-Host "`nNo llama.cpp update needed. Current build $currentBuildTag is up to date." -ForegroundColor Green | |
| exit 0 | |
| } | |
| Write-Host "`nNew version available! Updating from $currentBuildTag to $latestBuildTag..." -ForegroundColor Yellow | |
| # Find the download URL for Windows x64 Vulkan release | |
| try { | |
| $releasePageUrl = "https://github.com/ggml-org/llama.cpp/releases/expanded_assets/$latestBuildTag" | |
| Write-Host "Fetching asset list from release page..." -ForegroundColor Cyan | |
| $releaseResponse = Invoke-WebRequest -Uri $releasePageUrl -UseBasicParsing | |
| # Look for the Windows x64 Vulkan zip file - try multiple patterns | |
| $patterns = @( | |
| "llama-$latestBuildTag-bin-win-vulkan-x64\.zip", | |
| "llama-$latestBuildTag-bin-win-vulkan\.zip", | |
| "llama.*$latestBuildTag.*win.*vulkan.*x64\.zip", | |
| "llama.*$latestBuildTag.*windows.*vulkan.*x64\.zip" | |
| ) | |
| $assetFileName = $null | |
| foreach ($pattern in $patterns) { | |
| $assetMatch = [regex]::Match($releaseResponse.Content, "($pattern)") | |
| if ($assetMatch.Success) { | |
| $assetFileName = $assetMatch.Groups[1].Value | |
| Write-Host "Found asset: $assetFileName" -ForegroundColor Green | |
| break | |
| } | |
| } | |
| if (-not $assetFileName) { | |
| Write-Host "Error: Could not find Windows x64 Vulkan release asset" -ForegroundColor Red | |
| Write-Host "Debug: Searching for patterns containing 'win' and 'vulkan':" -ForegroundColor Yellow | |
| $debugMatches = [regex]::Matches($releaseResponse.Content, '(llama[^"]*\.zip)') | |
| Write-Host "Found zip files:" -ForegroundColor Yellow | |
| $debugMatches | ForEach-Object { Write-Host " - $($_.Groups[1].Value)" } | |
| exit 1 | |
| } | |
| $downloadUrl = "https://github.com/ggml-org/llama.cpp/releases/download/$latestBuildTag/$assetFileName" | |
| $zipFilePath = Join-Path $downloadPath $assetFileName | |
| Write-Host "Downloading $assetFileName..." -ForegroundColor Cyan | |
| Invoke-WebRequest -Uri $downloadUrl -OutFile $zipFilePath | |
| Write-Host "Download complete!" -ForegroundColor Green | |
| } | |
| catch { | |
| Write-Host "Error downloading release: $_" -ForegroundColor Red | |
| exit 1 | |
| } | |
| # Unzip the file (smart mode - create folder with same name as zip without extension) | |
| try { | |
| $extractFolderName = [System.IO.Path]::GetFileNameWithoutExtension($zipFilePath) | |
| $extractPath = Join-Path $downloadPath $extractFolderName | |
| Write-Host "Extracting to $extractPath..." -ForegroundColor Cyan | |
| # Remove existing folder if it exists | |
| if (Test-Path $extractPath) { | |
| Remove-Item $extractPath -Recurse -Force | |
| } | |
| Expand-Archive -Path $zipFilePath -DestinationPath $extractPath -Force | |
| Write-Host "Extraction complete!" -ForegroundColor Green | |
| # Clean up zip file | |
| Remove-Item $zipFilePath -Force | |
| } | |
| catch { | |
| Write-Host "Error extracting archive: $_" -ForegroundColor Red | |
| exit 1 | |
| } | |
| # Backup the current bat file | |
| try { | |
| $backupPath = "C:\ai\llama_start.previous" | |
| Write-Host "Backing up $batFilePath to $backupPath..." -ForegroundColor Cyan | |
| Copy-Item $batFilePath $backupPath -Force | |
| Write-Host "Backup complete!" -ForegroundColor Green | |
| } | |
| catch { | |
| Write-Host "Error backing up bat file: $_" -ForegroundColor Red | |
| exit 1 | |
| } | |
| # Update the bat file with new build number | |
| try { | |
| $updatedBatContent = $batContent -replace "set\s+`"build=$currentBuildTag`"", "set `"build=$latestBuildTag`"" | |
| Set-Content -Path $batFilePath -Value $updatedBatContent -NoNewline | |
| Write-Host "Updated $batFilePath with build $latestBuildTag" -ForegroundColor Green | |
| } | |
| catch { | |
| Write-Host "Error updating bat file: $_" -ForegroundColor Red | |
| exit 1 | |
| } | |
| Write-Host "`nUpdate complete! llama.cpp has been updated to $latestBuildTag" -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment