Skip to main content

MLLM Prompt Template

A Python template library for Multimodal LLMs(MLLMs) that extends Python's string.Template to support image substitution in prompts.

# ❌
from string import Template
template = Template("Extract all text from the image. \n image: $img")
prompt = template.safe_substitute(
    img=Image.open("photo.jpg")
)
# ✅
from mllm_prompt_template import Template
template = Template("Extract all text from the image. \n image: $img")
prompt = template.safe_substitute(
    img=Image.open("photo.jpg")
)

Installation

pip install mllm-prompt-template

Usage

from mllm_prompt_template import Template
from PIL import Image

# Create template with image placeholders
prompt_template = Template("""
这个人是$name, 这是他的自拍照:
$img
$name很可爱对不对
""")

# Substitute text and image variables
prompt = prompt_template.safe_substitute(
    name="co-gy",
    img=Image.open("photo.jpg")
)

# Convert to OpenAI-style message format
messages = prompt.to_messages()

# Call MLLM (example with OpenAI-compatible API)
import openai

client = openai.OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")

response = client.chat.completions.create(
    model="Qwen3-VL-8B-Instruct",
    messages=messages,
    max_tokens=500
)

print(response.choices[0].message.content)

API

  • Template(template: str) - Create template
  • substitute(**kwargs)/safe_substitute(**kwargs) - Substitute variables (supports strings and PIL Images)
  • to_messages() - Convert to OpenAI-style message format

Requirements

  • Python >= 3.8
  • Pillow >= 9.0.0

License

MIT License

Metadata

Release files for mllm-prompt-template 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for mllm-prompt-template 2.0.0
File Interpreter ABI Platform Actions
mllm_prompt_template-2.0.0-py3-none-any.whl Python 3 none any Details for mllm_prompt_template-2.0.0-py3-none-any.whl

Release files / mllm_prompt_template-2.0.0-py3-none-any.whl

Download URL mllm_prompt_template-2.0.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83b8e24e73687f5effac91dba0eac55eafaf85aad3504a6e80b67e6c9c3e17a3
BLAKE2b-256 checksum
How to use checksums
aec882935bc9146a4f01d4555a38e630217c6049f4275e081e8f22524336493f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for mllm-prompt-template 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page