decode_content

in lib/openai/internal/util.rb [611:635]


        def decode_content(headers, stream:, suppress_error: false)
          case (content_type = 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)
          else
            text = stream.to_a.join
            force_charset!(content_type, text: text)
            StringIO.new(text)
          end
        end