-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
Realtime #524
Comments
Did a small poc a few days ago, connecting Twilio and the realtime API:
|
Thanks so much for sharing @danielfriis ! super helpful. |
simple example with Async websocket def ws_client
require "async"
require "async/http"
require "async/websocket"
url = "wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01"
# Creating headers for the request
headers = {
"Authorization" => "Bearer #{ENV.fetch('OPENAI_API_KEY', nil)}",
"OpenAI-Beta" => "realtime=v1"
}
Async do |task|
endpoint = Async::HTTP::Endpoint.parse(url, alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
Async::WebSocket::Client.connect(endpoint, headers: headers) do |connection|
input_task = task.async do
while line = $stdin.gets
text = {
type: "response.create",
response: {
modalities: ["text"],
instructions: "Please assist the user."
}
}
message = Protocol::WebSocket::TextMessage.generate(text) # ({ text: line })
message.send(connection)
connection.flush
end
end
puts "Connected..."
while message = connection.read
puts "> #{message.to_h}"
end
ensure
input_task&.stop
end
end
end |
Hello! I'm interested in opening a PR. I have been working with the API using ruby on rails. What I have done (Briefly):
My proposal:Maybe the solution in this gem should be something like the first point, right? More or less it should have this functions: Maybe we could have a |
Hello! I wanted to try a bit and I opened a small PR, perhaps we can iterate better over it 😄 |
OpenAI added a realtime API!
How do we add this to ruby-openai?
Options
The text was updated successfully, but these errors were encountered: