Skip to content

Commit 18c1173

Browse files
bmehta001Copilot
andauthored
Add EP download progress bar to all samples (#621)
All samples now show per-EP download progress with name and percentage, matching the pattern already in native-chat-completions samples. **Changes (38 files across 4 languages):** - **C# (9 samples)**: Replaced bare \DownloadAndRegisterEpsAsync()\ and \RunWithSpinner\ calls with progress callback - **JS/TS (12 samples)**: Replaced bare \downloadAndRegisterEps()\ with progress callback - **Python (9 samples)**: Replaced bare \download_and_register_eps()\ with progress callback - **Rust (8 samples)**: Replaced \download_and_register_eps(None)\ with \download_and_register_eps_with_progress\ Each callback tracks the current EP name and displays a carriage-return progress line showing EP name (left-aligned 30 chars) and download percentage. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3eed749 commit 18c1173

File tree

38 files changed

+527
-22
lines changed

38 files changed

+527
-22
lines changed

samples/cs/audio-transcription-example/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@
1717

1818

1919
// Ensure that any Execution Provider (EP) downloads run and are completed.
20-
// EP packages include dependencies and may be large.
21-
// Download is only required again if a new version of the EP is released.
22-
// For cross platform builds there is no dynamic EP download and this will return immediately.
23-
await Utils.RunWithSpinner("Registering execution providers", mgr.DownloadAndRegisterEpsAsync());
20+
// Download and register all execution providers.
21+
var currentEp = "";
22+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
23+
{
24+
if (epName != currentEp)
25+
{
26+
if (currentEp != "") Console.WriteLine();
27+
currentEp = epName;
28+
}
29+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
30+
});
31+
if (currentEp != "") Console.WriteLine();
2432
// </init>
2533

2634

samples/cs/foundry-local-web-server/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@
2323

2424

2525
// Ensure that any Execution Provider (EP) downloads run and are completed.
26-
// EP packages include dependencies and may be large.
27-
// Download is only required again if a new version of the EP is released.
28-
// For cross platform builds there is no dynamic EP download and this will return immediately.
29-
await Utils.RunWithSpinner("Registering execution providers", mgr.DownloadAndRegisterEpsAsync());
26+
// Download and register all execution providers.
27+
var currentEp = "";
28+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
29+
{
30+
if (epName != currentEp)
31+
{
32+
if (currentEp != "") Console.WriteLine();
33+
currentEp = epName;
34+
}
35+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
36+
});
37+
if (currentEp != "") Console.WriteLine();
3038
// </init>
3139

3240

samples/cs/model-management-example/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717

1818

1919
// Download and register all execution providers.
20-
await Utils.RunWithSpinner("Registering execution providers", mgr.DownloadAndRegisterEpsAsync());
20+
var currentEp = "";
21+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
22+
{
23+
if (epName != currentEp)
24+
{
25+
if (currentEp != "") Console.WriteLine();
26+
currentEp = epName;
27+
}
28+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
29+
});
30+
if (currentEp != "") Console.WriteLine();
2131

2232

2333
// Model catalog operations

samples/cs/tool-calling-foundry-local-sdk/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@
2323

2424

2525
// Ensure that any Execution Provider (EP) downloads run and are completed.
26-
// EP packages include dependencies and may be large.
27-
// Download is only required again if a new version of the EP is released.
28-
// For cross platform builds there is no dynamic EP download and this will return immediately.
29-
await Utils.RunWithSpinner("Registering execution providers", mgr.DownloadAndRegisterEpsAsync());
26+
// Download and register all execution providers.
27+
var currentEp = "";
28+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
29+
{
30+
if (epName != currentEp)
31+
{
32+
if (currentEp != "") Console.WriteLine();
33+
currentEp = epName;
34+
}
35+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
36+
});
37+
if (currentEp != "") Console.WriteLine();
3038
// </init>
3139

3240

samples/cs/tool-calling-foundry-local-web-server/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@
2222

2323

2424
// Download and register all execution providers.
25-
await Utils.RunWithSpinner("Registering execution providers", mgr.DownloadAndRegisterEpsAsync());
25+
var currentEp = "";
26+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
27+
{
28+
if (epName != currentEp)
29+
{
30+
if (currentEp != "") Console.WriteLine();
31+
currentEp = epName;
32+
}
33+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
34+
});
35+
if (currentEp != "") Console.WriteLine();
2636

2737

2838
// Get the model catalog

samples/cs/tutorial-chat-assistant/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
await FoundryLocalManager.CreateAsync(config, logger);
2525
var mgr = FoundryLocalManager.Instance;
2626

27+
// Download and register all execution providers.
28+
var currentEp = "";
29+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
30+
{
31+
if (epName != currentEp)
32+
{
33+
if (currentEp != "") Console.WriteLine();
34+
currentEp = epName;
35+
}
36+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
37+
});
38+
if (currentEp != "") Console.WriteLine();
39+
2740
// Select and load a model from the catalog
2841
var catalog = await mgr.GetCatalogAsync();
2942
var model = await catalog.GetModelAsync("qwen2.5-0.5b")

samples/cs/tutorial-document-summarizer/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
await FoundryLocalManager.CreateAsync(config, logger);
2525
var mgr = FoundryLocalManager.Instance;
2626

27+
// Download and register all execution providers.
28+
var currentEp = "";
29+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
30+
{
31+
if (epName != currentEp)
32+
{
33+
if (currentEp != "") Console.WriteLine();
34+
currentEp = epName;
35+
}
36+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
37+
});
38+
if (currentEp != "") Console.WriteLine();
39+
2740
// Select and load a model from the catalog
2841
var catalog = await mgr.GetCatalogAsync();
2942
var model = await catalog.GetModelAsync("qwen2.5-0.5b")

samples/cs/tutorial-tool-calling/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ string ExecuteTool(string functionName, JsonElement arguments)
122122
await FoundryLocalManager.CreateAsync(config, logger);
123123
var mgr = FoundryLocalManager.Instance;
124124

125+
// Download and register all execution providers.
126+
var currentEp = "";
127+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
128+
{
129+
if (epName != currentEp)
130+
{
131+
if (currentEp != "") Console.WriteLine();
132+
currentEp = epName;
133+
}
134+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
135+
});
136+
if (currentEp != "") Console.WriteLine();
137+
125138
var catalog = await mgr.GetCatalogAsync();
126139
var model = await catalog.GetModelAsync("qwen2.5-0.5b")
127140
?? throw new Exception("Model not found");

samples/cs/tutorial-voice-to-text/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
// Initialize the singleton instance
2727
await FoundryLocalManager.CreateAsync(config, logger);
2828
var mgr = FoundryLocalManager.Instance;
29+
30+
// Download and register all execution providers.
31+
var currentEp = "";
32+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
33+
{
34+
if (epName != currentEp)
35+
{
36+
if (currentEp != "") Console.WriteLine();
37+
currentEp = epName;
38+
}
39+
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
40+
});
41+
if (currentEp != "") Console.WriteLine();
42+
2943
var catalog = await mgr.GetCatalogAsync();
3044
// </init>
3145

samples/js/audio-transcription-example/app.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ const manager = FoundryLocalManager.create({
1414
// </init>
1515
console.log('✓ SDK initialized successfully');
1616

17+
// Download and register all execution providers.
18+
let currentEp = '';
19+
await manager.downloadAndRegisterEps((epName, percent) => {
20+
if (epName !== currentEp) {
21+
if (currentEp !== '') process.stdout.write('\n');
22+
currentEp = epName;
23+
}
24+
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
25+
});
26+
if (currentEp !== '') process.stdout.write('\n');
27+
1728
// <model_setup>
1829
// Get the model object
1930
const modelAlias = 'whisper-tiny'; // Using an available model from the list above

0 commit comments

Comments
 (0)