Feature: accept any buffer instance when processing file data#148
Feature: accept any buffer instance when processing file data#148ncoghlan merged 5 commits intolmstudio-ai:mainfrom
Conversation
- Change _get_file_details() to return Buffer instead of bytes - Add special handling for memoryview inputs to avoid unnecessary conversion - Support all buffer protocol objects (bytes, bytearray, memoryview, array.array, etc.) - Update type annotations throughout to use Buffer type from typing_extensions - Improve error messages to mention "buffer" instead of just "bytes" This change reduces memory overhead when working with buffer protocol objects by preserving memoryview objects instead of converting them to bytes unnecessarily.
- Fix trailing comma in Buffer import - Remove redundant type annotation to fix mypy error - Add groups = dev to typecheck tox environment - Remove trailing whitespace
|
All contributors have signed the CLA ✍️ ✅ |
|
@ncoghlan I cannot find the location of which I confirm the CLA. I think the site maybe broken ? |
|
|
I have read the CLA Document and I hereby sign the CLA |
thanks bro |
ncoghlan
left a comment
There was a problem hiding this comment.
This is a nice improvement, thanks!
I'd like to arrange the updated checks in _get_file_details a bit differently, but the details are beyond what GitHub will tolerate as a multi-line suggestion, so I'll change those locally and push them up to the branch.
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
Sounds good to me! |
|
@ncoghlan I don't think I can merge it requires me to have write permissions I believe, it just shows close with comment on my side. |
Aye, there was a gap between approval and merging as I was also running the full test suite against my local LM Studio instance (the automated CI's coverage is unfortunately still limited for now). Local tests were all green, though, so thanks for the enhancement! |
|
Follow up PR to add test cases for the newly accepted file data input types: #152 |
|
This will be released as part of lmstudio-python 1.5.0. |


refactor: optimize file handling to avoid redundant buffer conversions
This change reduces memory overhead when working with buffer protocol objects
by preserving memoryview objects instead of converting them to bytes unnecessarily.
Closes #46