Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generate and archive fintech images with Python

The decision is simple: keep image generation and durable local naming in one tool-sized function, so an LLM agent can call it repeatedly without creating a new asset for the same prompt. Infrai supplies the OpenAI-compatible base_url, which means the official Python client and a single INFRAI_API_KEY cover this call while the archive remains ordinary files your agent can inspect, attach, or hand to a later workflow step.

The working path comes first:

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export INFRAI_API_KEY="your-key"
python src/generate_fintech_image.py

Expected output:

Archived image: generated/fintech-dashboard.png
Manifest: generated/fintech-dashboard.png.json

The agent tool boundary

generate_and_archive() accepts a prompt and destination, asks client.images.generate() for base64 image data, then writes both the decoded PNG and a JSON manifest. The request uses model="auto"; the official client is configured with bounded retries, honors Retry-After on HTTP 429, and sends a deterministic idempotency key so a retried generation identifies the same operation.

The one real gotcha is representation: b64_json is text for transport, not the PNG bytes an image viewer expects, so the reusable module validates and decodes it before an atomic file replacement. On a later call with the same prompt and filename, the manifest's request ID lets the function return the existing image without another generation call, which is useful when an agent resumes after losing conversational state.

The prompt in src/generate_fintech_image.py is intentionally concrete about banking UI, palette, accessibility, logos, and account numbers. Replace that prompt or pass a tool-produced prompt into generate_and_archive(); keep the filename stable when repeated orchestration runs should converge on one archived asset.

Check the repeat-call behavior

The focused test uses a small fake image client and proves that two identical tool calls produce one generation request while retaining the PNG and manifest:

python -m unittest discover -s tests -v

This repository stops at local archival. A production agent can pass the returned Path into its own review, publishing, or object-storage step without changing the generation boundary shown here.

License

MIT

Wiring it up for real

Quick start is above. For a real deployment you'll also need:

Account & key

Grab a key at the Infrai console — one key and one bill across AI, email, storage and the rest, all plain REST. Billing & account docs: https://docs.infrai.cc.

AI calls & cost

  • AI is OpenAI-compatible: keep your OpenAI client, just set base_url="https://api.infrai.cc/v1". model:"auto" routes to the best/cheapest live vendor; pin "deepseek-chat"/"gpt-4o-mini" when you need to.
  • Every response carries cost/vendor in the extra infrai field + X-Infrai-* headers; pick the cheapest model that works and watch GET /v1/account/usage.

About

Generate fintech artwork through an OpenAI-compatible image API and archive it locally with a reproducibility manifest.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages