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(**params) ⇒ Object



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

def create(**params)
  params = compact_params(params)
  validate_params!(params)
  request(:post, ENDPOINT, body: params)
end

#get(id) ⇒ Object



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

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

#run(**params) ⇒ Object



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

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