Sha256: 4c5628a983467d3b72dd57e4972d1986b20b06e042343938d770c6944eed17fa
Contents?: true
Size: 895 Bytes
Versions: 7
Compression:
Stored size: 895 Bytes
Contents
module OpenAI class Files def initialize(client:) @client = client end def list @client.get(path: "/files") end def upload(parameters: {}) validate(file: parameters[:file]) if parameters[:file].include?(".jsonl") @client.multipart_post( path: "/files", parameters: parameters.merge(file: File.open(parameters[:file])) ) end def retrieve(id:) @client.get(path: "/files/#{id}") end def content(id:) @client.get(path: "/files/#{id}/content") end def delete(id:) @client.delete(path: "/files/#{id}") end private def validate(file:) File.open(file).each_line.with_index do |line, index| JSON.parse(line) rescue JSON::ParserError => e raise JSON::ParserError, "#{e.message} - found on line #{index + 1} of #{file}" end end end end
Version data entries
7 entries across 7 versions & 2 rubygems