Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket Connection Closed After Short Inactivity in Realtime API #274

Closed
hf75 opened this issue Oct 30, 2024 · 2 comments
Closed

WebSocket Connection Closed After Short Inactivity in Realtime API #274

hf75 opened this issue Oct 30, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@hf75
Copy link

hf75 commented Oct 30, 2024

OpenAIRealtimeChat.zip

Service

OpenAI

Describe the bug

I am using the OpenAI Realtime API to develop a small WPF chat application that exchanges voice messages in a ping/pong manner (with ConversationTurnDetectionOptions.CreateDisabledTurnDetectionOptions()). The voice messages are successfully transmitted/received, but I am encountering an issue where the WebSocket connection is closed automatically after a few seconds of inactivity (lets say 5 to 10 seconds). When I conduct a chat with quickly consecutive short voice messages, I can chat for as long as I want.

What I can see in the API is that in AsyncWebsocketMessageResultEnumerator::MoveNextAsync
receiveResult.CloseStatus.HasValue is true and the closeStatus is InternalServerError with
receiveResult.CloseStatusDescription is "keepalive ping timeout".

So the webSocket is closed and the AsyncWebsocketMessageResultEnumerator is disposed.

Is this expected behaviour? If so, what is the expected way to reestablich the connection?

Steps to reproduce

await session.SendAudioAsync(recording);

// Do something for a couple of seconds, e. g. play the BinaryData result in an audio player etc.

// might fail because the internal webSocket is disposed.
await session.SendAudioAsync(recording);

Code snippets

In the attached code you only need to insert your key in the method MainWindow::InitOpenAI(). Then it should compile and run. Please note that I do not use the nugget package for the OpenAI-API but compile it myself (also included in the solution). I need to do that to fix #268.

OS

Win11

.NET version

8

Library version

v2.1.0-beta.1

@hf75 hf75 added the bug Something isn't working label Oct 30, 2024
@hf75 hf75 changed the title WebSocket Connection Disposed After Inactivity in Realtime API WebSocket Connection Closed After Inactivity in Realtime API Oct 30, 2024
@hf75 hf75 changed the title WebSocket Connection Closed After Inactivity in Realtime API WebSocket Connection Closed After Short Inactivity in Realtime API Oct 30, 2024
@jkears
Copy link

jkears commented Oct 30, 2024

Are you able to show your code?

@hf75
Copy link
Author

hf75 commented Oct 30, 2024

Turns out it was a user error. Works like a charm now after fixing some bugs.

I attached the code. Just insert your key in the method MainWindow::InitOpenAI() and it should compile and run. I do not use the OpenAI-API nugget package but the source which is also included in the solution. I need to do this to fix #268. I hope it does not turn out to be complete incompetence on my side :)

@hf75 hf75 closed this as completed Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants