test3.ps1
$job = Register-EngineEvent -SourceIdentifier 'PSOpenAI.Realtime.ReceiveMessage' -Action { $o = $Event.SourceArgs[0] $o | ConvertTo-Json -Depth 10 | Out-Default } $job2 = Register-EngineEvent -SourceIdentifier 'PSOpenAI.Realtime.SendMessage' -Action { $Event.SourceArgs[0] | Out-Default } Register-EngineEvent -SourceIdentifier 'PSOpenAI.Realtime.ReceiveMessage' -Action { $eventItem = $Event.SourceArgs[0] switch ($eventItem.type) { 'session.created' { # Display session info Write-Host "`r" ('Connected .(SessionID = "{0}")' -f $eventItem.session.id) | Write-Host -ForegroundColor Green } 'response.text.delta' { # Display text responses from the AI to the console $eventItem.delta | Write-Host -NoNewline -ForegroundColor Blue } 'error' { # Oops, something went wrong. Write-Host "`r" ('ERROR : "{0}")' -f $eventItem.error.message) | Write-Host -ForegroundColor Red } } } |