-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
[Feature] Realtime API from OpenAI working #545
base: main
Are you sure you want to change the base?
Conversation
end | ||
|
||
def connect(model: "gpt-4o-realtime-preview-2024-10-01") | ||
uri = "#{File.join(@client.websocket_uri_base, @client.api_version, 'realtime')}?model=#{model}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably this uri shouldn't be here but I was not sure where to put it
Is it out of scope to add a sample sinatra app into the repo with some stimulusjs that demos the client-side setup of the websocket/connection to feed/receive messages to the backend? |
EM.run do | ||
@websocket = Faye::WebSocket::Client.new(uri, nil, headers: openai_realtime_headers) | ||
@websocket.on :message, @on_message | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should replace Eventmachine since it last release was 6 yeas ago. I think we could use async. I have tried and it works fine with something like this:
Async do
endpoint = Async::HTTP::Endpoint.parse(uri, alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
Async::WebSocket::Client.connect(endpoint, headers: @headers) do |connection|
@websocket = connection
while (message = connection.read)
@on_message
end
end
end
@drnic Sorry the delay in the answer, I think it'd be a good thing to have, for me it was the hardest part. If we finally merge this I could do that app easily. |
WIP
This is a very basic PR that we can use to iterate. Right now I'm using it with ActionCable in a rails app like this:
In the example
data['event']
can be something like this:Maybe we could add more functions in order to facilitate event management. Something like I said in this comment.
Dependencies
faye-websocket
eventmachine
All Submissions:
Closes #524