functions/LemonAI-InstalledModels.ps1
function LemonAI-InstalledModels{ $ollamaJob=Start-Job -ScriptBlock{ $tmp=Start-Job -ScriptBlock{ ollama list } $tmp2=Start-Job -ScriptBlock{ ollama list } $recList="" for($timeout=100;$timeout -gt 0; $timeout--){ Start-Sleep -Milliseconds 100 $recvd=Receive-Job $tmp -ErrorAction SilentlyContinue $recvd2=Receive-Job $tmp2 -ErrorAction SilentlyContinue if($recvd) {$recList=$recvd} elseif($recvd2) {$recList=$recvd2} if($recList){ Write-Output $recList break } } if((Get-Process -Name "ollama*")){(Stop-Process (Get-Process -Name "ollama*") -ErrorAction SilentlyContinue) | Out-Null} Stop-Job $tmp Remove-Job $tmp } while($ollamajob.State -eq "Running"){ Start-Sleep -Milliseconds 100 Receive-Job $ollamaJob } if((Get-Process -Name "ollama*")){(Stop-Process (Get-Process -Name "ollama*") -ErrorAction SilentlyContinue) | Out-Null} Receive-Job $ollamajob #Remove-Job $ollamaJob } |