A Python template library for Multimodal LLMs that extends string.Template to support image substitution in prompts
Project description
MLLM Prompt Template
A Python template library for Multimodal LLMs(MLLMs) that extends Python's string.Template to support image substitution in prompts.
Installation
pip install mllm-prompt-template
Usage
from mllm_prompt_template import Template
from PIL import Image
# Create template with image placeholders
prompt_template = """
这个人是$name, 这是他的自拍照:
$img
$name很可爱对不对
"""
# Substitute text and image variables
prompt = Template(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(prompt_template: str)- Create templatesafe_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
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
File details
Details for the file mllm_prompt_template-1.0.0.tar.gz.
File metadata
- Download URL: mllm_prompt_template-1.0.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
059dfec820b93b4de542e164e8cf4fe062f20ca9b1037e5ba316bb70816944c2
|
|
| MD5 |
cf3ec008c143c6ace7da965a8fe9f266
|
|
| BLAKE2b-256 |
2dc5198eddfbfd4434e0fc55610127f4da6da77b1fbfb822a09f3f7d95ede6d4
|