fix(multimodal): detect truncated images at the frontend via pixel-le…#1307
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces robust image verification to prevent server crashes caused by truncated or corrupted images. It implements a thread pool to perform pixel-level decoding verification using PIL, offloading this CPU-intensive task from the main event loop. Additionally, a new test script is included to verify that the API correctly rejects invalid images with a 4xx error. The review identified a potential runtime error during environment variable parsing for the thread pool configuration and suggested translating the test script's documentation into English for better accessibility.
| ImageFile.LOAD_TRUNCATED_IMAGES = False | ||
|
|
||
| _IMAGE_VERIFY_POOL = ThreadPoolExecutor( | ||
| max_workers=int(os.getenv("LIGHTLLM_IMAGE_VERIFY_WORKERS", str((os.cpu_count() or 4) * 2))), |
There was a problem hiding this comment.
| """验证残缺图片在 OpenAI /v1/chat/completions 接口被前端拦截为 4xx。 | ||
|
|
||
| 启动 server: | ||
| python -m lightllm.server.api_server --port 8000 --model_dir <your_vlm> --tp 1 | ||
|
|
||
| 运行: | ||
| python test/test_api/test_image_verify_api.py | ||
| """ |
There was a problem hiding this comment.
For consistency with the rest of the codebase and to make it more accessible to non-Chinese speakers, please consider translating the docstring and comments into English.
| """验证残缺图片在 OpenAI /v1/chat/completions 接口被前端拦截为 4xx。 | |
| 启动 server: | |
| python -m lightllm.server.api_server --port 8000 --model_dir <your_vlm> --tp 1 | |
| 运行: | |
| python test/test_api/test_image_verify_api.py | |
| """ | |
| """Verify that truncated images are rejected with a 4xx error by the frontend | |
| at the OpenAI /v1/chat/completions endpoint. | |
| To run this test: | |
| 1. Start the server: | |
| python -m lightllm.server.api_server --port 8000 --model_dir <your_vlm> --tp 1 | |
| 2. Run the test script: | |
| python test/test_api/test_image_verify_api.py | |
| """ |
…vel decode