Class: GenAI::Image::OpenAI
- Defined in:
- lib/gen_ai/image/open_ai.rb
Constant Summary collapse
- DEFAULT_SIZE =
'256x256'
- DEFAULT_MODEL =
'dall-e-3'
- RESPONSE_FORMAT =
'b64_json'
Instance Method Summary collapse
- #edit(image, prompt, options = {}) ⇒ Object
- #generate(prompt, options = {}) ⇒ Object
-
#initialize(token:, options: {}) ⇒ OpenAI
constructor
A new instance of OpenAI.
- #variations(image, options = {}) ⇒ Object
Methods inherited from Base
Methods included from Dependency
Constructor Details
#initialize(token:, options: {}) ⇒ OpenAI
Returns a new instance of OpenAI.
12 13 14 15 16 |
# File 'lib/gen_ai/image/open_ai.rb', line 12 def initialize(token:, options: {}) depends_on 'ruby-openai' @client = ::OpenAI::Client.new(access_token: token) end |
Instance Method Details
#edit(image, prompt, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gen_ai/image/open_ai.rb', line 42 def edit(image, prompt, = {}) parameters = (image, prompt, ) response = handle_errors { @client.images.edit(parameters: parameters) } build_result( raw: response, model: parameters[:model], parsed: parse_response_data(response['data']) ) end |
#generate(prompt, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gen_ai/image/open_ai.rb', line 18 def generate(prompt, = {}) parameters = (prompt, ) response = handle_errors { @client.images.generate(parameters: parameters) } build_result( raw: response, model: parameters[:model], parsed: parse_response_data(response['data']) ) end |
#variations(image, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gen_ai/image/open_ai.rb', line 30 def variations(image, = {}) parameters = (image, ) response = handle_errors { @client.images.variations(parameters: parameters) } build_result( raw: response, model: parameters[:model], parsed: parse_response_data(response['data']) ) end |