tools.generate_image module
Generate images on the active GPT/Gemini origin and send them to the channel.
- async tools.generate_image.run(prompt, aspect_ratio='16:9', model=None, ctx=None)
Generate an image from a prompt and post it to the current channel.
Entry point for the
generate_imagetool. A GPT-origin turn first uses native Codex image generation on the beneficiary’s own linked account; a Gemini-origin turn, a sponsored GPT route, or a failed GPT image call uses the existing Gemini path. Shared Gemini-key quota is enforced only when that fallback is actually used. The result is normalised to PNG, uploaded throughctx.adapter.send_file, and recorded inctx.sent_files.Dispatched by
tool_loader.py, which imports this module and resolvesrunviagetattr(module, "run")to register it underTOOL_NAME(“generate_image”).- Parameters:
prompt (
str) – Text description of the image to generate.aspect_ratio (
str) – Requested aspect ratio (default"16:9"), passed through to_call_gemini_native.model (
str|None) – Optional Gemini image model id; defaults are applied downstream.ctx (
ToolContext|None) – The currentToolContext; itsadapteris required to send the image and itsuser_id/redisdrive quota enforcement. Whenctxorctx.adapteris missing the call returns an error.
- Return type:
- Returns:
A JSON string with
success: Trueplusfilename, aresultmessage, and (when available)file_urlon success; otherwise a JSON object with anerrordescribing a quota block, an empty result, or a raised exception.