Skip to content

stream option should take any callable not just a proc #262

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/openai/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ def get(path:)

def json_post(path:, parameters:)
to_json(conn.post(uri(path: path)) do |req|
if parameters[:stream].is_a?(Proc)
if parameters[:stream].respond_to?(:call)
req.options.on_data = to_json_stream(user_proc: parameters[:stream])
parameters[:stream] = true # Necessary to tell OpenAI to stream.
elsif parameters[:stream]
raise ArgumentError, "stream must be callable"
end

req.headers = headers
Expand Down