Sha256: 6eeb127f4b3a2a25c444d998d7bfa9d1129b61b93eafa396547351f806d5e240
Contents?: true
Size: 967 Bytes
Versions: 3
Compression:
Stored size: 967 Bytes
Contents
module OpenAI class Files def initialize(access_token: nil, organization_id: nil) Ruby::OpenAI.configuration.access_token = access_token if access_token Ruby::OpenAI.configuration.organization_id = organization_id if organization_id end def list OpenAI::Client.get(path: "/files") end def upload(parameters: {}) validate(file: parameters[:file]) OpenAI::Client.post( path: "/files", parameters: parameters.merge(file: File.open(parameters[:file])) ) end def retrieve(id:) OpenAI::Client.get(path: "/files/#{id}") end def delete(id:) OpenAI::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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ruby-openai-3.0.2 | lib/ruby/openai/files.rb |
ruby-openai-3.0.1 | lib/ruby/openai/files.rb |
ruby-openai-3.0.0 | lib/ruby/openai/files.rb |