Skip to content

Commit 16849cf

Browse files
lancecarlsonalexrudall
authored andcommitted
obie: debug and error handling for streams
1 parent e66a540 commit 16849cf

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/openai/http.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ def to_json_stream(user_proc:)
4949

5050
proc do |chunk, _bytes, env|
5151
if env && env.status != 200
52-
raise_error = Faraday::Response::RaiseError.new
53-
raise_error.on_complete(env.merge(body: JSON.parse(chunk)))
54-
end
55-
56-
parser.feed(chunk) do |_type, data|
57-
user_proc.call(JSON.parse(data)) unless data == "[DONE]"
52+
parser.feed(chunk) do |_type, data|
53+
emit_json(json: data, user_proc: user_proc) unless data == "[DONE]"
54+
end
5855
end
5956
end
6057
end

0 commit comments

Comments
 (0)