functions/LemonAI-GetChat.ps1

function LemonAI-GetChat($chatJob, $chatJobID){
    if(-not $chatJob -and $chatJobID){
        $chatJob = Get-Job -Id $chatJobID
    }

    if($chatJob){
        while($chatJob.HasMoreData -or $chatJob.State -eq "Running"){
            Start-Sleep -Milliseconds 100
            Write-Output (Receive-Job $chatJob)
        }
    }else {
        Write-Output "Error: No AI Chat found."
    }
}