in lib/anthropic/internal/util.rb [590:615]
def decode_content(headers, stream:, suppress_error: false)
case headers["content-type"]
in %r{^application/(?:vnd\.api\+)?json}
json = stream.to_a.join
begin
JSON.parse(json, symbolize_names: true)
rescue JSON::ParserError => e
raise e unless suppress_error
json
end
in %r{^application/(?:x-)?jsonl}
lines = decode_lines(stream)
chain_fused(lines) do |y|
lines.each { y << JSON.parse(_1, symbolize_names: true) }
end
in %r{^text/event-stream}
lines = decode_lines(stream)
decode_sse(lines)
in %r{^text/}
stream.to_a.join
else
StringIO.new(stream.to_a.join)
end
end