Skip to content

Commit c97cde3

Browse files
author
Raja Phanindra Chava
committed
Updated embedding samples to be consistent with other samples
1 parent 4c11b95 commit c97cde3

4 files changed

Lines changed: 130 additions & 1 deletion

File tree

samples/cs/embeddings/Program.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,44 @@
1313
// Initialize the singleton instance.
1414
await FoundryLocalManager.CreateAsync(config, Utils.GetAppLogger());
1515
var mgr = FoundryLocalManager.Instance;
16+
17+
// Discover available execution providers and their registration status.
18+
var eps = mgr.DiscoverEps();
19+
int maxNameLen = 30;
20+
Console.WriteLine("Available execution providers:");
21+
Console.WriteLine($" {"Name".PadRight(maxNameLen)} Registered");
22+
Console.WriteLine($" {new string('─', maxNameLen)} {"──────────"}");
23+
foreach (var ep in eps)
24+
{
25+
Console.WriteLine($" {ep.Name.PadRight(maxNameLen)} {ep.IsRegistered}");
26+
}
27+
28+
// Download and register all execution providers with per-EP progress.
29+
// EP packages include dependencies and may be large.
30+
// Download is only required again if a new version of the EP is released.
31+
// For cross platform builds there is no dynamic EP download and this will return immediately.
32+
Console.WriteLine("\nDownloading execution providers:");
33+
if (eps.Length > 0)
34+
{
35+
string currentEp = "";
36+
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
37+
{
38+
if (epName != currentEp)
39+
{
40+
if (currentEp != "")
41+
{
42+
Console.WriteLine();
43+
}
44+
currentEp = epName;
45+
}
46+
Console.Write($"\r {epName.PadRight(maxNameLen)} {percent,6:F1}%");
47+
});
48+
Console.WriteLine();
49+
}
50+
else
51+
{
52+
Console.WriteLine("No execution providers to download.");
53+
}
1654
// </init>
1755

1856
// <model_setup>
@@ -69,6 +107,5 @@ await model.DownloadAsync(progress =>
69107
// <cleanup>
70108
// Tidy up - unload the model
71109
await model.UnloadAsync();
72-
Console.WriteLine("\nModel unloaded.");
73110
// </cleanup>
74111
// </complete_code>

samples/js/embeddings/app.js

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

17+
// Discover available execution providers and their registration status.
18+
const eps = manager.discoverEps();
19+
const maxNameLen = 30;
20+
console.log('\nAvailable execution providers:');
21+
console.log(` ${'Name'.padEnd(maxNameLen)} Registered`);
22+
console.log(` ${'─'.repeat(maxNameLen)} ──────────`);
23+
for (const ep of eps) {
24+
console.log(` ${ep.name.padEnd(maxNameLen)} ${ep.isRegistered}`);
25+
}
26+
27+
// Download and register all execution providers with per-EP progress.
28+
// EP packages include dependencies and may be large.
29+
// Download is only required again if a new version of the EP is released.
30+
console.log('\nDownloading execution providers:');
31+
if (eps.length > 0) {
32+
let currentEp = '';
33+
await manager.downloadAndRegisterEps((epName, percent) => {
34+
if (epName !== currentEp) {
35+
if (currentEp !== '') {
36+
process.stdout.write('\n');
37+
}
38+
currentEp = epName;
39+
}
40+
process.stdout.write(`\r ${epName.padEnd(maxNameLen)} ${percent.toFixed(1).padStart(5)}%`);
41+
});
42+
process.stdout.write('\n');
43+
} else {
44+
console.log('No execution providers to download.');
45+
}
46+
1747
// <model_setup>
1848
// Get an embedding model
1949
const modelAlias = 'qwen3-embedding-0.6b';

samples/python/embeddings/src/app.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@ def main():
1111
FoundryLocalManager.initialize(config)
1212
manager = FoundryLocalManager.instance
1313

14+
# Discover available execution providers and their registration status.
15+
eps = manager.discover_eps()
16+
max_name_len = 30
17+
print("Available execution providers:")
18+
print(f" {'Name':<{max_name_len}} Registered")
19+
print(f" {'─' * max_name_len} ──────────")
20+
for ep in eps:
21+
print(f" {ep.name:<{max_name_len}} {ep.is_registered}")
22+
23+
# Download and register all execution providers.
24+
print("\nDownloading execution providers:")
25+
current_ep = ""
26+
def ep_progress(ep_name: str, percent: float):
27+
nonlocal current_ep
28+
if ep_name != current_ep:
29+
if current_ep:
30+
print()
31+
current_ep = ep_name
32+
print(f"\r {ep_name:<{max_name_len}} {percent:5.1f}%", end="", flush=True)
33+
34+
if eps:
35+
manager.download_and_register_eps(progress_callback=ep_progress)
36+
if current_ep:
37+
print()
38+
else:
39+
print("No execution providers to download.")
40+
1441
# Select and load an embedding model from the catalog
1542
model = manager.catalog.get_model("qwen3-embedding-0.6b")
1643
model.download(

samples/rust/embeddings/src/main.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Licensed under the MIT License.
44

55
// <imports>
6+
use std::io::{self, Write};
7+
68
use foundry_local_sdk::{FoundryLocalConfig, FoundryLocalManager};
79
// </imports>
810

@@ -18,6 +20,39 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1820
let manager = FoundryLocalManager::create(FoundryLocalConfig::new("foundry_local_samples"))?;
1921
// </init>
2022

23+
// Discover available execution providers and their registration status.
24+
let eps = manager.discover_eps()?;
25+
let max_name_len = 30;
26+
println!("Available execution providers:");
27+
println!(" {:<width$} Registered", "Name", width = max_name_len);
28+
println!(" {:─<width$} ──────────", "", width = max_name_len);
29+
for ep in &eps {
30+
println!(" {:<width$} {}", ep.name, ep.is_registered, width = max_name_len);
31+
}
32+
33+
// Download and register all execution providers.
34+
println!("\nDownloading execution providers:");
35+
if !eps.is_empty() {
36+
manager
37+
.download_and_register_eps_with_progress(None, {
38+
let mut current_ep = String::new();
39+
move |ep_name: &str, percent: f64| {
40+
if ep_name != current_ep {
41+
if !current_ep.is_empty() {
42+
println!();
43+
}
44+
current_ep = ep_name.to_string();
45+
}
46+
print!("\r {:<width$} {:5.1}%", ep_name, percent, width = max_name_len);
47+
io::stdout().flush().ok();
48+
}
49+
})
50+
.await?;
51+
println!();
52+
} else {
53+
println!("No execution providers to download.");
54+
}
55+
2156
// ── 2. Pick a model and ensure it is downloaded ─────────────────────
2257
// <model_setup>
2358
let model = manager.catalog().get_model(ALIAS).await?;

0 commit comments

Comments
 (0)