From 5521c80eaa0ac2cd36d4825c04be1ba1cb5b2eeb Mon Sep 17 00:00:00 2001 From: Gregory Date: Tue, 29 Oct 2024 18:29:00 -0300 Subject: [PATCH 1/3] Return body if content octet-stream --- lib/openai/http.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 2f60eb0b..3f473e8d 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -7,9 +7,12 @@ module HTTP include HTTPHeaders def get(path:, parameters: nil) - parse_jsonl(conn.get(uri(path: path), parameters) do |req| + response = conn.get(uri(path: path), parameters) do |req| req.headers = headers - end&.body) + end + + content_type = response.headers['content-type'] + content_type == 'application/octet-stream' ? response.body : parse_jsonl(response.body) end def post(path:) From 9802caa5533c27124bf1ee0b133c4edbbeecd91d Mon Sep 17 00:00:00 2001 From: Gregory Date: Tue, 29 Oct 2024 18:40:46 -0300 Subject: [PATCH 2/3] Fix rubocop offenses --- lib/openai/http.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 3f473e8d..6f529421 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -11,8 +11,8 @@ def get(path:, parameters: nil) req.headers = headers end - content_type = response.headers['content-type'] - content_type == 'application/octet-stream' ? response.body : parse_jsonl(response.body) + content_type = response.headers["content-type"] + content_type == "application/octet-stream" ? response.body : parse_jsonl(response.body) end def post(path:) From a4c23295724ef00b9dc29b73b426f3bfe1e0f674 Mon Sep 17 00:00:00 2001 From: Gregory Date: Tue, 29 Oct 2024 19:05:18 -0300 Subject: [PATCH 3/3] Handle json parsing --- lib/openai/http.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 6f529421..0f773052 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -11,8 +11,11 @@ def get(path:, parameters: nil) req.headers = headers end - content_type = response.headers["content-type"] - content_type == "application/octet-stream" ? response.body : parse_jsonl(response.body) + begin + parse_jsonl(response.body) + rescue JSON::ParserError + response.body + end end def post(path:)