feat: Add native Hugging Face push support with LFS#673
feat: Add native Hugging Face push support with LFS#673iamanishx wants to merge 4 commits intodocker:mainfrom
Conversation
Signed-off-by: iamanishx <manishbiswal754@gmail.com>
Signed-off-by: Manish Biswal <manishbiswal754@gmail.com>
Signed-off-by: Manish Biswal <manishbiswal754@gmail.com>
Summary of ChangesHello @iamanishx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new
PushModelsignature uses a variadicbearerToken ...stringbut only ever reads the first element; consider switching to a single explicit parameter or a small options struct to make the call sites and intent clearer. - Hugging Face reference detection is now implemented both in the CLI (
strings.HasPrefix(modelLower, "hf.co/")...) and inisHuggingFaceReference; centralizing this into a shared helper would reduce duplication and avoid future drift in patterns. - In
UploadFiles, progress for small (non-LFS) files is reported viauploadProgressReaderduring read and then again afterCreateCommitby writing a full-size update, which may double-count per-file progress; consider consolidating progress reporting so each byte is only accounted for once.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `PushModel` signature uses a variadic `bearerToken ...string` but only ever reads the first element; consider switching to a single explicit parameter or a small options struct to make the call sites and intent clearer.
- Hugging Face reference detection is now implemented both in the CLI (`strings.HasPrefix(modelLower, "hf.co/")...`) and in `isHuggingFaceReference`; centralizing this into a shared helper would reduce duplication and avoid future drift in patterns.
- In `UploadFiles`, progress for small (non-LFS) files is reported via `uploadProgressReader` during read and then again after `CreateCommit` by writing a full-size update, which may double-count per-file progress; consider consolidating progress reporting so each byte is only accounted for once.
## Individual Comments
### Comment 1
<location> `pkg/inference/models/http_handler.go:454-456` </location>
<code_context>
// handlePushModel handles POST <inference-prefix>/models/{name}/push requests.
func (h *HTTPHandler) handlePushModel(w http.ResponseWriter, r *http.Request, model string) {
- if err := h.manager.Push(model, r, w); err != nil {
+ var req ModelPushRequest
+ if r.Body != nil && r.Body != http.NoBody {
+ body, err := io.ReadAll(r.Body)
+ if err != nil {
+ http.Error(w, "invalid request body", http.StatusBadRequest)
</code_context>
<issue_to_address>
**🚨 issue (security):** Reading the entire request body without a size limit can be abused
`io.ReadAll` consumes the entire body even though only a small JSON payload is required. This allows an attacker to send a very large request and exhaust memory. Please cap the body size (e.g., wrap `r.Body` with `io.LimitReader` here, or `http.MaxBytesReader` at the router) before reading.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| var req ModelPushRequest | ||
| if r.Body != nil && r.Body != http.NoBody { | ||
| body, err := io.ReadAll(r.Body) |
There was a problem hiding this comment.
🚨 issue (security): Reading the entire request body without a size limit can be abused
io.ReadAll consumes the entire body even though only a small JSON payload is required. This allows an attacker to send a very large request and exhaust memory. Please cap the body size (e.g., wrap r.Body with io.LimitReader here, or http.MaxBytesReader at the router) before reading.
There was a problem hiding this comment.
Code Review
This pull request introduces native push support for Hugging Face repositories, which is a great feature. The implementation correctly detects Hugging Face URLs and routes them to a new native upload flow that uses the Hugging Face LFS and commit APIs. The changes are well-structured across the CLI, desktop client, and distribution packages. My review includes a critical fix for a compilation error, suggestions to improve consistency in error handling for progress reporting, and a recommendation to simplify some of the new HTTP handling logic.
|
@doringeman @ericcurtin please have a look |
ericcurtin
left a comment
There was a problem hiding this comment.
Wow @iamanishx this is great please go through the Gemini comments and address or mark as resolved if they are not worth it
|
Lets hope you pass the build |
|
Need to regenerate the docs and repush, it's just: make docs in the cmd/cli directory and repush the changes. |
|
@ericcurtin i have repushed the docs and gemini suggestions were invalid so i have resolved them . |
Summery:
issue number : #597
video ref- https://drive.google.com/file/d/1HE7GrpqXN_BNzgffR6nBm9kOBFKdtEjl/view?usp=sharing