Class: LLM::Gemini::Images
- Inherits:
-
Object
- Object
- LLM::Gemini::Images
- Includes:
- RequestAdapter
- Defined in:
- lib/llm/providers/gemini/images.rb
Overview
The LLM::Gemini::Images class provides an images object for interacting with [Gemini’s images API](ai.google.dev/gemini-api/docs/image-generation). Please note that unlike OpenAI, which can return either URLs or base64-encoded strings, Gemini’s images API will always return an image as a base64 encoded string that can be decoded into binary.
Instance Method Summary collapse
-
#create(prompt:, model: "gemini-2.5-flash-image", **params) ⇒ LLM::Response
Create an image.
- #create_variation ⇒ Object
-
#edit(image:, prompt:, model: "gemini-2.5-flash-image", **params) ⇒ LLM::Response
Edit an image.
-
#initialize(provider) ⇒ LLM::Gemini::Responses
constructor
Returns a new Images object.
Methods included from RequestAdapter
Constructor Details
#initialize(provider) ⇒ LLM::Gemini::Responses
Returns a new Images object
24 25 26 |
# File 'lib/llm/providers/gemini/images.rb', line 24 def initialize(provider) @provider = provider end |
Instance Method Details
#create(prompt:, model: "gemini-2.5-flash-image", **params) ⇒ LLM::Response
Create an image
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/llm/providers/gemini/images.rb', line 40 def create(prompt:, model: "gemini-2.5-flash-image", **params) req = Net::HTTP::Post.new("/v1beta/models/#{model}:generateContent?key=#{key}", headers) body = LLM.json.dump({ contents: [{parts: [{text: create_prompt}, {text: prompt}]}], generationConfig: {responseModalities: ["TEXT", "IMAGE"]} }.merge!(params)) req.body = body res = execute(request: req) validate ResponseAdapter.adapt(res, type: :image) end |
#create_variation ⇒ Object
80 81 82 |
# File 'lib/llm/providers/gemini/images.rb', line 80 def create_variation raise NotImplementedError end |
#edit(image:, prompt:, model: "gemini-2.5-flash-image", **params) ⇒ LLM::Response
Edit an image
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/llm/providers/gemini/images.rb', line 65 def edit(image:, prompt:, model: "gemini-2.5-flash-image", **params) req = Net::HTTP::Post.new("/v1beta/models/#{model}:generateContent?key=#{key}", headers) image = LLM::Object.from(value: LLM.File(image), kind: :local_file) body = LLM.json.dump({ contents: [{parts: [{text: edit_prompt}, {text: prompt}, adapter.adapt_content(image)]}], generationConfig: {responseModalities: ["TEXT", "IMAGE"]} }.merge!(params)).b set_body_stream(req, StringIO.new(body)) res = execute(request: req) validate ResponseAdapter.adapt(res, type: :image) end |