Metadata-Version: 2.4
Name: mllm-prompt-template
Version: 1.0.1
Summary: A Python template library for Multimodal LLMs that extends string.Template to support image substitution in prompts
Home-page: https://github.com/co-gy/mllm-prompt-template
Author: co-gy
Author-email: co-gy <948628463@qq.com>
License: MIT
Project-URL: Homepage, https://github.com/co-gy/mllm-prompt-template
Project-URL: Repository, https://github.com/co-gy/mllm-prompt-template
Keywords: llm,multimodal,template,prompt,image
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: General
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Pillow>=9.0.0
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# MLLM Prompt Template

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

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

## Installation

```bash
pip install mllm-prompt-template
```

## Usage

```python
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 template
- `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
