llm7-validator is a Python package designed to validate message structures sent to LLM7-compatible chat completion APIs. It ensures that model names, messages, and attachments conform to the expected structure and size constraints.
To install llm7-validator, use pip:
pip install llm7-validatorHere is a minimal example of how to use it:
from llm7_validator import validate_chat_completion_request
check = validate_chat_completion_request({
"model": "open-mistral-7b",
"json_mode": True,
"messages": [
{"role": "system", "content": "hj"},
{
"role": "user",
"content": [
{"type": "text", "text": "What is this image?"},
{"type": "image_url", "image_url": "https://example.com/image.png"},
],
},
],
})
print(check)-
Verifies message format (
role,content, etc.) -
Validates model names against a dynamically fetched list from llm7-models.json
-
Checks:
- Image URLs have allowed extensions (
.png,.jpg, etc.) - Base64 image content length
- Total request size (max 5 MB)
- Required fields and optional tuning parameters
- Image URLs have allowed extensions (
-
Uses cached HTTP responses for model list with a 5-minute expiration
Python ≥ 3.10pydantic==2.11.5requests-cache==1.2.1
Contributions, issues, and feature requests are welcome! Please visit the GitHub repo to get started.
llm7-validator is licensed under the MIT License.