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_assettool. 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 viactx.adapter.send_filewith a record appended toctx.sent_files. Whensave_asis 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โsrun(tool_def.handler(**arguments, ctx=ctx)) for the registeredanimate_assettool; 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, andsent_fileslist.
- Returns:
JSON. On success an object with
success, the source name, the animated URL, the sent filename, andsaved_as; on failure an{"error": ...}object describing what went wrong.- Return type: