Skip to content

Commit 23477c8

Browse files
samuel100Copilot
andauthored
rust sdk: change download progress callback from &str to f64 (#608)
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>
1 parent 25f8d9b commit 23477c8

File tree

18 files changed

+94
-55
lines changed

18 files changed

+94
-55
lines changed

samples/rust/.cargo/config.toml

Lines changed: 0 additions & 7 deletions
This file was deleted.

samples/rust/audio-transcription-example/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3535
if !model.is_cached().await? {
3636
println!("Downloading model...");
3737
model
38-
.download(Some(|progress: &str| {
39-
print!("\r {progress}%");
38+
.download(Some(|progress: f64| {
39+
print!("\r {progress:.1}%");
4040
io::stdout().flush().ok();
4141
}))
4242
.await?;

samples/rust/foundry-local-webserver/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3434
if !model.is_cached().await? {
3535
print!("Downloading model {model_alias}...");
3636
model
37-
.download(Some(move |progress: &str| {
38-
print!("\rDownloading model... {progress}%");
37+
.download(Some(move |progress: f64| {
38+
print!("\rDownloading model... {progress:.1}%");
3939
io::stdout().flush().ok();
4040
}))
4141
.await?;

samples/rust/native-chat-completions/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3232
if !model.is_cached().await? {
3333
println!("Downloading model...");
3434
model
35-
.download(Some(|progress: &str| {
36-
print!("\r {progress}%");
35+
.download(Some(|progress: f64| {
36+
print!("\r {progress:.1}%");
3737
io::stdout().flush().ok();
3838
}))
3939
.await?;

samples/rust/tool-calling-foundry-local/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6666
if !model.is_cached().await? {
6767
println!("Downloading model...");
6868
model
69-
.download(Some(|progress: &str| {
70-
print!("\r {progress}%");
69+
.download(Some(|progress: f64| {
70+
print!("\r {progress:.1}%");
7171
io::stdout().flush().ok();
7272
}))
7373
.await?;

samples/rust/tutorial-chat-assistant/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ async fn main() -> anyhow::Result<()> {
2121
if !model.is_cached().await? {
2222
println!("Downloading model...");
2323
model
24-
.download(Some(|progress: &str| {
25-
print!("\r {progress}");
24+
.download(Some(|progress: f64| {
25+
print!("\r {progress:.1}%");
2626
io::stdout().flush().ok();
2727
}))
2828
.await?;

samples/rust/tutorial-document-summarizer/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ async fn main() -> anyhow::Result<()> {
9696
if !model.is_cached().await? {
9797
println!("Downloading model...");
9898
model
99-
.download(Some(|progress: &str| {
100-
print!("\r {progress}");
99+
.download(Some(|progress: f64| {
100+
print!("\r {progress:.1}%");
101101
io::stdout().flush().ok();
102102
}))
103103
.await?;

samples/rust/tutorial-tool-calling/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ async fn main() -> anyhow::Result<()> {
199199
if !model.is_cached().await? {
200200
println!("Downloading model...");
201201
model
202-
.download(Some(|progress: &str| {
203-
print!("\r {progress}");
202+
.download(Some(|progress: f64| {
203+
print!("\r {progress:.1}%");
204204
io::stdout().flush().ok();
205205
}))
206206
.await?;

samples/rust/tutorial-voice-to-text/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ async fn main() -> anyhow::Result<()> {
2828
if !speech_model.is_cached().await? {
2929
println!("Downloading speech model...");
3030
speech_model
31-
.download(Some(|progress: &str| {
32-
print!("\r {progress}");
31+
.download(Some(|progress: f64| {
32+
print!("\r {progress:.1}%");
3333
io::stdout().flush().ok();
3434
}))
3535
.await?;
@@ -60,8 +60,8 @@ async fn main() -> anyhow::Result<()> {
6060
if !chat_model.is_cached().await? {
6161
println!("Downloading chat model...");
6262
chat_model
63-
.download(Some(|progress: &str| {
64-
print!("\r {progress}");
63+
.download(Some(|progress: f64| {
64+
print!("\r {progress:.1}%");
6565
io::stdout().flush().ok();
6666
}))
6767
.await?;

sdk/rust/.cargo/config.toml

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)