Skip to content

Commit 74f6a63

Browse files
feat: add jsonl support (#10)
1 parent 4ba4a39 commit 74f6a63

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/finch-api/util.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,17 +496,19 @@ def encode_content(headers, body)
496496
#
497497
def decode_content(headers, stream:, suppress_error: false)
498498
case headers["content-type"]
499-
in %r{^text/event-stream}
500-
lines = enum_lines(stream)
501-
parse_sse(lines)
502-
in %r{^application/json}
499+
in %r{^application/(?:vnd\.api\+)?json}
503500
json = stream.to_a.join
504501
begin
505502
JSON.parse(json, symbolize_names: true)
506503
rescue JSON::ParserError => e
507504
raise e unless suppress_error
508505
json
509506
end
507+
in %r{^text/event-stream}
508+
lines = enum_lines(stream)
509+
parse_sse(lines)
510+
in %r{^application/(?:x-)?jsonl}
511+
enum_lines(stream)
510512
in %r{^text/}
511513
stream.to_a.join
512514
else
@@ -615,7 +617,7 @@ def parse_sse(lines)
615617
in "event"
616618
current.merge!(event: value)
617619
in "data"
618-
(current[:data] ||= String.new) << value << "\n"
620+
(current[:data] ||= String.new) << (value << "\n")
619621
in "id" unless value.include?("\0")
620622
current.merge!(id: value)
621623
in "retry" if /^\d+$/ =~ value

0 commit comments

Comments
 (0)