Class: RunApi::Gpt4oImage::Resources::TextToImage

Inherits:
Object
  • Object
show all
Includes:
Core::ResourceHelpers
Defined in:
lib/runapi/gpt_4o_image/resources/text_to_image.rb

Overview

GPT-4o Image generation and editing resource. Generate images from text, edit with source images, or inpaint with a mask.

Constant Summary collapse

ENDPOINT =
"/api/v1/gpt_4o_image/text_to_image"
RESPONSE_CLASS =
Types::TextToImageResponse
COMPLETED_RESPONSE_CLASS =
Types::CompletedTextToImageResponse

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ TextToImage

Returns a new instance of TextToImage.



16
17
18
# File 'lib/runapi/gpt_4o_image/resources/text_to_image.rb', line 16

def initialize(http)
  @http = http
end

Instance Method Details

#create(options: nil, **params) ⇒ Object



25
26
27
28
29
# File 'lib/runapi/gpt_4o_image/resources/text_to_image.rb', line 25

def create(options: nil, **params)
  params = compact_params(params)
  validate_contract!(CONTRACT["text-to-image"], params)
  request(:post, ENDPOINT, body: params, options: options)
end

#get(id, options: nil) ⇒ Object



31
32
33
# File 'lib/runapi/gpt_4o_image/resources/text_to_image.rb', line 31

def get(id, options: nil)
  request(:get, "#{ENDPOINT}/#{id}", options: options)
end

#run(options: nil, **params) ⇒ Object



20
21
22
23
# File 'lib/runapi/gpt_4o_image/resources/text_to_image.rb', line 20

def run(options: nil, **params)
  task = create(options: options, **params)
  poll_until_complete { get(task.id, options: options) }
end