Sha256: 8568d988b8625135cd81e02beff7899ca71ece5173a9fa504fd9cd7995ea4868

Contents?: true

Size: 898 Bytes

Versions: 13

Compression:

Stored size: 898 Bytes

Contents

module OpenAI
  class Images
    def initialize(access_token: nil, organization_id: nil)
      OpenAI.configuration.access_token = access_token if access_token
      OpenAI.configuration.organization_id = organization_id if organization_id
    end

    def generate(parameters: {})
      OpenAI::Client.json_post(path: "/images/generations", parameters: parameters)
    end

    def edit(parameters: {})
      OpenAI::Client.multipart_post(path: "/images/edits", parameters: open_files(parameters))
    end

    def variations(parameters: {})
      OpenAI::Client.multipart_post(path: "/images/variations", parameters: open_files(parameters))
    end

    private

    def open_files(parameters)
      parameters = parameters.merge(image: File.open(parameters[:image]))
      parameters = parameters.merge(mask: File.open(parameters[:mask])) if parameters[:mask]
      parameters
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ruby-openai-4.3.2 lib/openai/images.rb
ruby-openai-4.3.1 lib/openai/images.rb
ruby-openai-4.3.0 lib/openai/images.rb
ruby-openai-4.2.0 lib/openai/images.rb
ruby-advanced-openai-4.1.1 lib/openai/images.rb
ruby-advanced-openai-4.1.0 lib/openai/images.rb
ruby-openai-4.1.0 lib/openai/images.rb
ruby-openai-4.0.0 lib/openai/images.rb
ruby-openai-3.7.0 lib/openai/images.rb
ruby-openai-3.6.0 lib/openai/images.rb
ruby-openai-3.5.0 lib/openai/images.rb
ruby-openai-3.4.0 lib/openai/images.rb
ruby-openai-3.3.0 lib/openai/images.rb