tools.generate_background module
GENERATE_BACKGROUND – Generate + save backgrounds for VN scenes.
Wraps the existing Gemini image generation to also save output to /home/star/large_files/assets/backgrounds/ so it can be served by nginx and referenced in scene scripts.
@fire @skull THE CANVAS PAINTS ITSELF.
- async tools.generate_background.run(prompt, name=None, aspect_ratio='16:9', ctx=None)[source]
Generate a VN scene background, persist it, and post it to the channel.
Entry point for the
generate_backgroundtool. It borrows the image pipeline fromtools.generate_image– reusing_resolve_api_keyand_call_gemini_native– after wrapping the caller’spromptin a background-specific instruction (no characters, wide establishing shot) so the result is usable as acompose_scenebackdrop. The returned bytes are normalised to PNG off the event loop via the nested_convert_to_pngandasyncio.to_thread, then the function has three side effects: it writes the PNG toBACKGROUNDS_DIRon disk (creating the directory if needed) so nginx can serve it under/backgrounds/, uploads the same bytes to the current channel throughctx.adapter.send_file, and appends a record toctx.sent_files. The deterministic filename embeds a SHA-256 hash of the image (plus a sanitisednamewhen given). Any failure is caught and returned as a JSON error object.Dispatched by
tool_loader.py, which imports this module and resolvesrunviagetattr(module, "run")to register it underTOOL_NAME(“generate_background”).- Parameters:
prompt (
str) – Text description of the background; mood, lighting, style, and perspective all help.name (
str|None) – Optional short label for the file (prefixed withbg_). When omitted the filename is derived purely from the image hash.aspect_ratio (
str) – Output aspect ratio passed through to Gemini (default"16:9").ctx (
ToolContext|None) – The currentToolContext; itsadapteris required to send the file and itschannel_id/sent_filesare used for the upload. Whenctxorctx.adapteris missing the call returns an error immediately.
- Return type:
- Returns:
A pretty-printed JSON string with
success: Trueplusfilename,path,scene_ref(thebg:reference for scene scripts),save_path, and a usagemessageon success; otherwise a JSON object withsuccess: Falseand anerrordescribing the failure.