tools.grok_imagine module๏ƒ

GameGirl Color โ€“ Asset animation tool via Grok Imagine.

Takes an existing game asset (image URL) and animates it into a short video using xAIโ€™s Grok Imagine img2vid API. The result is sent as an animated WebP or MP4. # ๐ŸŒ€๐Ÿ’€ CORRUPTED ANIMATION PIPELINE

async tools.grok_imagine.run(asset_name, prompt='', save_as='', output_format='webp', ctx=None)[source]๏ƒ

Animate a still game asset into a short clip via Grok Imagine img2vid.

Entry point for the animate_asset tool. It resolves the seed image (_resolve_image_url), downloads and base64-encodes it (_download_as_base64), authorizes with an xAI key (_resolve_api_key), then calls xAIโ€™s Grok Imagine image-to-video endpoint and polls for completion. The finished clip is downloaded through the SSRF-guarded HTTP helpers, optionally transcoded to the requested format (_convert_format, ffmpeg), and delivered to the channel via ctx.adapter.send_file with a record appended to ctx.sent_files. When save_as is given and a game session is active, the result is also registered as a new game asset (game_assets.upload_asset, persisted via Redis).

Dispatched by the tool runner in tools/__init__.py, which calls this moduleโ€™s run (tool_def.handler(**arguments, ctx=ctx)) for the registered animate_asset tool; there are no direct internal callers.

Parameters:
  • asset_name (str) โ€“ Name of a saved game asset to animate, or a direct image URL.

  • prompt (str) โ€“ Optional motion prompt guiding the animation; a sensible default is used when empty.

  • save_as (str) โ€“ Optional name under which to register the result as a new game asset.

  • output_format (str) โ€“ Desired output container ("webp", "mp4", or "gif"); invalid values fall back to "webp".

  • ctx (ToolContext | None) โ€“ Tool execution context; supplies the channel id, Redis client, config, user id, outbound adapter, and sent_files list.

Returns:

JSON. On success an object with success, the source name, the animated URL, the sent filename, and saved_as; on failure an {"error": ...} object describing what went wrong.

Return type:

str