Skip to content

Commit 2be9bf8

Browse files
committed
Improve fix
1 parent 8e1d6a2 commit 2be9bf8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/openai/http.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ module HTTP
77
include HTTPHeaders
88

99
def get(path:, parameters: nil)
10-
response = conn.get(uri(path: path), parameters) { |req| req.headers = headers }
11-
parse_jsonl(response.body)
12-
rescue JSON::ParserError
13-
response.body
10+
parse_jsonl(conn.get(uri(path: path), parameters) do |req|
11+
req.headers = headers
12+
end&.body)
1413
end
1514

1615
def post(path:)
@@ -49,6 +48,8 @@ def parse_jsonl(response)
4948
response = response.gsub("}\n{", "},{").prepend("[").concat("]")
5049

5150
JSON.parse(response)
51+
rescue JSON::ParserError
52+
response
5253
end
5354

5455
# Given a proc, returns an outer proc that can be used to iterate over a JSON stream of chunks.

0 commit comments

Comments
 (0)