Skip to main content

ChatImg image generation package

Project description

ChatImg

ChatImg 是 ChatArch 的图片生成包,承接原 chattool image 中已经解耦的 provider 实现。

当前支持:

  • codex / openai-codex:ChatGPT/Codex OAuth image bridge,支持 gpt-image-2-* preset。
  • pollinations:Pollinations.ai image URL generation and model listing。
  • siliconflow:SiliconFlow OpenAI-compatible image generation。
  • huggingface:Hugging Face Inference image generation。
  • liblib:LiblibAI signed API generation。
  • tongyi:通义万相 / DashScope image generation。

安装

开发安装:

pip install -e ".[dev]"

通义万相 SDK 可选依赖:

pip install -e ".[images]"

CLI

chatimg --help
chatimg --version
chatimg codex list-models
chatimg pollinations list-models

生成示例:

chatimg codex generate "a watercolor fox in the snow" --aspect-ratio square -o fox.png
chatimg pollinations generate "a cyberpunk cat" --model flux --width 512 --height 512 -o cat.png
chatimg siliconflow generate "a cute dog" --size 1024x1024 -o dog.png
chatimg huggingface generate "A futuristic city at night" -o city.png
chatimg liblib generate "A cute dog" --model-id liblib-sdxl-model -o dog.png
chatimg tongyi generate "一只赛博朋克猫" --size "1024*1024" -o cat.png

Codex / GPT Image2 实测示例

codex provider 走 ChatGPT/Codex OAuth-backed Responses API,请求里的 image tool model 是 gpt-image-2。它不是外部 Codex CLI。

常用配置字段:

  • OPENAI_CODEX_ACCESS_TOKEN:历史 Codex image access token 变量;也兼容 OPENAI_ACCESS_TOKEN
  • OPENAI_CODEX_AUTH_JSON:Hermes auth.json 路径;默认 ~/.hermes/auth.json,用于复用本机 openai-codex 登录态。
  • OPENAI_CODEX_HOST_MODEL:承载 image_generation tool 的 host model,默认 gpt-5.4
  • OPENAI_CODEX_BASE_URL:Codex backend base URL,默认 https://chatgpt.com/backend-api/codex
  • OPENAI_CODEX_TIMEOUT:请求超时秒数,默认 300
  • OPENAI_IMAGE_MODEL:默认 image preset,默认 gpt-image-2-medium
  • OPENAI_IMAGE_ASPECT_RATIO:默认图片比例,默认 square

基础验收图:

chatimg codex generate \
  "A clean minimal ChatImg acceptance test illustration: a friendly robot holding a small picture frame, modern flat design, white background, no text" \
  --image-model gpt-image-2-low \
  --aspect-ratio square \
  -o generated/chatimg-gpt-image2-basic.png \
  --timeout 300

快速排序流程图:

chatimg codex generate \
  "Create a clean landscape technical design flowchart explaining quicksort. Use this exact example array: [6, 3, 8, 5, 1, 10, 2]. Pick pivot = 5. Partition correctly: left part [3, 1, 2] labeled < pivot, right part [6, 8, 10] labeled > pivot. Include steps: START, base case length <= 1?, pick pivot, partition array, recursively sort left part, recursively sort right part, concatenate sorted-left + pivot + sorted-right, END. Modern vector style, white background, blue/orange accents, arrows, decision diamond, readable simple English labels. Avoid mathematical mistakes." \
  --image-model gpt-image-2-medium \
  --aspect-ratio landscape \
  -o generated/chatimg-gpt-image2-quicksort-flowchart.png \
  --timeout 300

Python API

from chatimg.image import create_generator

generator = create_generator("codex")
result = generator.generate("A cute cat astronaut")

配置

ChatImg 注册了 chatenv.configs entry point:

chatimg = "chatimg.config"

支持的主要环境变量:

  • OPENAI_ACCESS_TOKEN, OPENAI_CODEX_ACCESS_TOKEN, OPENAI_CODEX_AUTH_JSON, OPENAI_REFRESH_TOKEN, OPENAI_OAUTH_BASE_URL, OPENAI_ACCESS_TOKEN_EXPIRES_AT, OPENAI_IMAGE_MODEL, OPENAI_IMAGE_ASPECT_RATIO, OPENAI_CODEX_HOST_MODEL, OPENAI_CODEX_BASE_URL, OPENAI_CODEX_TIMEOUT
  • POLLINATIONS_API_KEY, POLLINATIONS_MODEL_ID
  • SILICONFLOW_API_KEY, SILICONFLOW_MODEL_ID
  • HUGGINGFACE_HUB_TOKEN
  • LIBLIB_ACCESS_KEY, LIBLIB_SECRET_KEY, LIBLIB_MODEL_ID
  • DASHSCOPE_API_KEY

开发验证

PYTHONPATH=src python -m pytest -q
PYTHONPATH=src python -m chatimg.cli --help
PYTHONPATH=src python -m chatimg.cli codex list-models
python -m build
python -m twine check dist/*

发布状态

PyPI chatimg==0.0.1 是占位版本;0.1.0 源码已准备为首个功能版本,但 tag / PyPI 正式发布需单独确认。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chatimg-0.1.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chatimg-0.1.0-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file chatimg-0.1.0.tar.gz.

File metadata

  • Download URL: chatimg-0.1.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chatimg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 319ab2f5831272e9c7a4fca39368ba8089404ca6dc3bc0664e7dd35a1be2ad45
MD5 3cbb6bc8b02b86f72dfa8005131bddf6
BLAKE2b-256 db15b8d189b1790b022fe64dbb6e9de4832bdca3830d0e20e49361c7743bc9f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatimg-0.1.0.tar.gz:

Publisher: publish.yml on ChatArch/ChatImg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chatimg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: chatimg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chatimg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55e248925bb5829b1792cbabb1cf4f19e457af26e520067bf316ee66cabba687
MD5 9fc75676e8eeded1b07250fc77a9aa1f
BLAKE2b-256 a2fcf10ddd91ab88263250f993337459922e0cc4188b0f5bb8708276db5a783f

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatimg-0.1.0-py3-none-any.whl:

Publisher: publish.yml on ChatArch/ChatImg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page