Skip to content

Conversation

@ArEnSc
Copy link
Contributor

@ArEnSc ArEnSc commented Aug 16, 2025

refactor: optimize file handling to avoid redundant buffer conversions

  • Change _get_file_details() to return Buffer instead of bytes
  • Add special handling for memory view 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.

Closes #46

ArEnSc added 2 commits August 15, 2025 21:19
- 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
@github-actions
Copy link

github-actions bot commented Aug 16, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ArEnSc
Copy link
Contributor Author

ArEnSc commented Aug 16, 2025

@ncoghlan I cannot find the location of which I confirm the CLA. I think the site maybe broken ?

@github-actions github-actions bot added the CLA signed Indicates that all contributors have signed label Aug 16, 2025
@baonudesifeizhai
Copy link
Contributor

@ncoghlan I cannot find the location of which I confirm the CLA. I think the site maybe broken ?

image

@ArEnSc
Copy link
Contributor Author

ArEnSc commented Aug 17, 2025

I have read the CLA Document and I hereby sign the CLA

@ArEnSc
Copy link
Contributor Author

ArEnSc commented Aug 17, 2025

@ncoghlan I cannot find the location of which I confirm the CLA. I think the site maybe broken ?

image

thanks bro

Copy link
Collaborator

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ArEnSc and others added 2 commits August 18, 2025 09:34
Co-authored-by: Alyssa Coghlan <[email protected]>
Co-authored-by: Alyssa Coghlan <[email protected]>
@ArEnSc
Copy link
Contributor Author

ArEnSc commented Aug 18, 2025

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.

Sounds good to me!

@ncoghlan ncoghlan changed the title Feature/buffer input clean Feature: accept any buffer instance when processing file data Aug 18, 2025
@ArEnSc
Copy link
Contributor Author

ArEnSc commented Aug 18, 2025

@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.

@ncoghlan
Copy link
Collaborator

@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!

@ncoghlan ncoghlan merged commit d12e757 into lmstudio-ai:main Aug 18, 2025
18 of 19 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2025
@ncoghlan
Copy link
Collaborator

Follow up PR to add test cases for the newly accepted file data input types: #152

@ncoghlan
Copy link
Collaborator

This will be released as part of lmstudio-python 1.5.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

CLA signed Indicates that all contributors have signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: accept any buffer input in the file preparation APIs

3 participants