Skip to content

rust sdk: change download progress callback from &str to f64#608

Merged
baijumeswani merged 6 commits intomainfrom
samuel100/rust-downloadcb
Apr 8, 2026
Merged

rust sdk: change download progress callback from &str to f64#608
baijumeswani merged 6 commits intomainfrom
samuel100/rust-downloadcb

Conversation

@samuel100
Copy link
Copy Markdown
Contributor

Change the public download progress callback type from FnMut(&str) to FnMut(f64) for cross-SDK consistency. Python, JS, and C# SDKs all expose a numeric float type for download progress.

The string-to-float parsing now happens inside model_variant.rs (using chunk.parse::()), matching the pattern already used by download_and_register_eps_with_progress. Unparseable chunks are silently TryParse). The internal core_interop streaming infrastructure remains unchanged since it is shared with chat/audio streaming.

Copilot AI review requested due to automatic review settings April 8, 2026 11:42
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Apr 8, 2026 5:48pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Rust SDK’s model download progress reporting to use a numeric percentage callback (f64) instead of a string, aligning Rust with the Python/JS/C# SDK APIs.

Changes:

  • Change Model::download / ModelVariant::download progress callback type from FnMut(&str) to FnMut(f64).
  • Parse progress chunks into f64 inside model_variant.rs before invoking the user callback.
  • Update Rust SDK docs and examples to use the new numeric progress callback.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk/rust/src/detail/model.rs Public API change: download progress callback now receives f64 percent.
sdk/rust/src/detail/model_variant.rs Adds a wrapper callback that parses streaming chunks into f64 before forwarding.
sdk/rust/README.md Updates documentation example to print numeric progress with formatting.
sdk/rust/examples/tool_calling.rs Updates example to use f64 progress callback formatting.
sdk/rust/examples/interactive_chat.rs Updates example to use f64 progress callback formatting.
sdk/rust/examples/chat_completion.rs Updates example to use f64 progress callback formatting.
sdk/rust/docs/api.md Updates API docs to reflect FnMut(f64) progress callback and percent semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

nenad1002
nenad1002 previously approved these changes Apr 8, 2026
samuel100 and others added 6 commits April 8, 2026 10:47
Change the public download progress callback type from FnMut(&str) to
FnMut(f64) for cross-SDK consistency. Python, JS, and C# SDKs all
expose a numeric float type for download progress.

The string-to-float parsing now happens inside model_variant.rs (using
chunk.parse::<f64>()), matching the pattern already used by
download_and_register_eps_with_progress. Unparseable chunks are silently
TryParse). The internal core_interop streaming infrastructure remains
unchanged since it is shared with chat/audio streaming.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The .cargo/config.toml was replacing all of crates.io with the
ORT-Nightly Cargo index, causing all non-ORT crates (reqwest,
async-openai, tokio, etc.) to fail resolution. The Foundry Local Core,
ORT, and GenAI native packages are NuGet packages downloaded via HTTP
in build.rs — they are not Cargo crates and do not need a Cargo
registry override.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update all 9 download progress callback sites across 8 sample files
to use f64 instead of &str, matching the SDK API change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Handle cases where native core sends chunks with whitespace, newlines,
or multiple values in a single callback. Tokenize with split_whitespace()
before parsing each token as f64, matching how other SDKs handle this
(JS parseFloat ignores trailing junk, Python float() strips whitespace).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Align Rust SDK with Python/C#/JS SDKs where select_variant accepts a
typed model variant object rather than a raw string ID. The string-based
selection is preserved as select_variant_by_id for convenience.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@baijumeswani baijumeswani enabled auto-merge (squash) April 8, 2026 18:02
@baijumeswani baijumeswani disabled auto-merge April 8, 2026 19:14
@baijumeswani baijumeswani merged commit 23477c8 into main Apr 8, 2026
49 of 51 checks passed
@baijumeswani baijumeswani deleted the samuel100/rust-downloadcb branch April 8, 2026 19:14
baijumeswani pushed a commit that referenced this pull request Apr 8, 2026
Change the public download progress callback type from FnMut(&str) to
FnMut(f64) for cross-SDK consistency. Python, JS, and C# SDKs all expose
a numeric float type for download progress.

The string-to-float parsing now happens inside model_variant.rs (using
chunk.parse::<f64>()), matching the pattern already used by
download_and_register_eps_with_progress. Unparseable chunks are silently
TryParse). The internal core_interop streaming infrastructure remains
unchanged since it is shared with chat/audio streaming.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rui-ren pushed a commit that referenced this pull request Apr 8, 2026
- Sample: update download progress callback from &str to f64 to match
  upstream API change (PR #608)
- Apply cargo fmt to all SDK and sample files for CI compliance

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants