Class: LLM::OpenAI::Images
- Inherits:
-
Object
- Object
- LLM::OpenAI::Images
- Defined in:
- lib/llm/providers/openai/images.rb
Overview
The LLM::OpenAI::Images class provides an images object for interacting with OpenAI’s images API. OpenAI supports multiple response formats: temporary URLs, or binary strings encoded in base64. The default is to return temporary URLs.
Instance Method Summary collapse
-
#initialize(provider) ⇒ LLM::OpenAI::Responses
constructor
Returns a new Images object.
-
#create(prompt:, model: "dall-e-3", **params) ⇒ LLM::Response::Image
Create an image.
-
#create_variation(image:, model: "dall-e-2", **params) ⇒ LLM::Response::Image
Create image variations.
-
#edit(image:, prompt:, model: "dall-e-2", **params) ⇒ LLM::Response::Image
Edit an image.
Constructor Details
#initialize(provider) ⇒ LLM::OpenAI::Responses
Returns a new Images object
33 34 35 |
# File 'lib/llm/providers/openai/images.rb', line 33 def initialize(provider) @provider = provider end |
Instance Method Details
#create(prompt:, model: "dall-e-3", **params) ⇒ LLM::Response::Image
Create an image
49 50 51 52 53 54 |
# File 'lib/llm/providers/openai/images.rb', line 49 def create(prompt:, model: "dall-e-3", **params) req = Net::HTTP::Post.new("/v1/images/generations", headers) req.body = JSON.dump({prompt:, n: 1, model:}.merge!(params)) res = request(http, req) LLM::Response::Image.new(res).extend(response_parser) end |
#create_variation(image:, model: "dall-e-2", **params) ⇒ LLM::Response::Image
Create image variations
68 69 70 71 72 73 74 75 |
# File 'lib/llm/providers/openai/images.rb', line 68 def create_variation(image:, model: "dall-e-2", **params) multi = LLM::Multipart.new(params.merge!(image:, model:)) req = Net::HTTP::Post.new("/v1/images/variations", headers) req["content-type"] = multi.content_type req.body_stream = multi.body res = request(http, req) LLM::Response::Image.new(res).extend(response_parser) end |
#edit(image:, prompt:, model: "dall-e-2", **params) ⇒ LLM::Response::Image
Edit an image
90 91 92 93 94 95 96 97 |
# File 'lib/llm/providers/openai/images.rb', line 90 def edit(image:, prompt:, model: "dall-e-2", **params) multi = LLM::Multipart.new(params.merge!(image:, prompt:, model:)) req = Net::HTTP::Post.new("/v1/images/edits", headers) req["content-type"] = multi.content_type req.body_stream = multi.body res = request(http, req) LLM::Response::Image.new(res).extend(response_parser) end |