Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions samples/cs/audio-transcription-example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@


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


Expand Down
16 changes: 12 additions & 4 deletions samples/cs/foundry-local-web-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@


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


Expand Down
12 changes: 11 additions & 1 deletion samples/cs/model-management-example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@


// Download and register all execution providers.
await Utils.RunWithSpinner("Registering execution providers", mgr.DownloadAndRegisterEpsAsync());
var currentEp = "";
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
{
if (epName != currentEp)
{
if (currentEp != "") Console.WriteLine();
currentEp = epName;
}
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
});
if (currentEp != "") Console.WriteLine();


// Model catalog operations
Expand Down
16 changes: 12 additions & 4 deletions samples/cs/tool-calling-foundry-local-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@


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


Expand Down
12 changes: 11 additions & 1 deletion samples/cs/tool-calling-foundry-local-web-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@


// Download and register all execution providers.
await Utils.RunWithSpinner("Registering execution providers", mgr.DownloadAndRegisterEpsAsync());
var currentEp = "";
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
{
if (epName != currentEp)
{
if (currentEp != "") Console.WriteLine();
currentEp = epName;
}
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
});
if (currentEp != "") Console.WriteLine();


// Get the model catalog
Expand Down
13 changes: 13 additions & 0 deletions samples/cs/tutorial-chat-assistant/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
await FoundryLocalManager.CreateAsync(config, logger);
var mgr = FoundryLocalManager.Instance;

// Download and register all execution providers.
var currentEp = "";
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
{
if (epName != currentEp)
{
if (currentEp != "") Console.WriteLine();
currentEp = epName;
}
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
});
if (currentEp != "") Console.WriteLine();

// Select and load a model from the catalog
var catalog = await mgr.GetCatalogAsync();
var model = await catalog.GetModelAsync("qwen2.5-0.5b")
Expand Down
13 changes: 13 additions & 0 deletions samples/cs/tutorial-document-summarizer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
await FoundryLocalManager.CreateAsync(config, logger);
var mgr = FoundryLocalManager.Instance;

// Download and register all execution providers.
var currentEp = "";
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
{
if (epName != currentEp)
{
if (currentEp != "") Console.WriteLine();
currentEp = epName;
}
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
});
if (currentEp != "") Console.WriteLine();

// Select and load a model from the catalog
var catalog = await mgr.GetCatalogAsync();
var model = await catalog.GetModelAsync("qwen2.5-0.5b")
Expand Down
13 changes: 13 additions & 0 deletions samples/cs/tutorial-tool-calling/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@
await FoundryLocalManager.CreateAsync(config, logger);
var mgr = FoundryLocalManager.Instance;

// Download and register all execution providers.
var currentEp = "";
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
{
if (epName != currentEp)
{
if (currentEp != "") Console.WriteLine();
currentEp = epName;
}
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
});
if (currentEp != "") Console.WriteLine();

var catalog = await mgr.GetCatalogAsync();
var model = await catalog.GetModelAsync("qwen2.5-0.5b")
?? throw new Exception("Model not found");
Expand Down Expand Up @@ -182,14 +195,14 @@
foreach (var toolCall in choice.ToolCalls)
{
var toolArgs = JsonDocument.Parse(
toolCall.FunctionCall.Arguments

Check warning on line 198 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (macos)

Possible null reference argument for parameter 'json' in 'JsonDocument JsonDocument.Parse(string json, JsonDocumentOptions options = default(JsonDocumentOptions))'.

Check warning on line 198 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (macos)

Dereference of a possibly null reference.

Check warning on line 198 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (macos)

Possible null reference argument for parameter 'json' in 'JsonDocument JsonDocument.Parse(string json, JsonDocumentOptions options = default(JsonDocumentOptions))'.

Check warning on line 198 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (macos)

Dereference of a possibly null reference.

Check warning on line 198 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (windows)

Possible null reference argument for parameter 'json' in 'JsonDocument JsonDocument.Parse(string json, JsonDocumentOptions options = default(JsonDocumentOptions))'.

Check warning on line 198 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (windows)

Dereference of a possibly null reference.

Check warning on line 198 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (windows)

Possible null reference argument for parameter 'json' in 'JsonDocument JsonDocument.Parse(string json, JsonDocumentOptions options = default(JsonDocumentOptions))'.

Check warning on line 198 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (windows)

Dereference of a possibly null reference.
).RootElement;
Console.WriteLine(
$" Tool call: {toolCall.FunctionCall.Name}({toolArgs})"
);

var result = ExecuteTool(
toolCall.FunctionCall.Name, toolArgs

Check warning on line 205 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (macos)

Possible null reference argument for parameter 'functionName' in 'string ExecuteTool(string functionName, JsonElement arguments)'.

Check warning on line 205 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (macos)

Possible null reference argument for parameter 'functionName' in 'string ExecuteTool(string functionName, JsonElement arguments)'.

Check warning on line 205 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (windows)

Possible null reference argument for parameter 'functionName' in 'string ExecuteTool(string functionName, JsonElement arguments)'.

Check warning on line 205 in samples/cs/tutorial-tool-calling/Program.cs

View workflow job for this annotation

GitHub Actions / cs-samples (windows)

Possible null reference argument for parameter 'functionName' in 'string ExecuteTool(string functionName, JsonElement arguments)'.
);
messages.Add(new ChatMessage
{
Expand Down
14 changes: 14 additions & 0 deletions samples/cs/tutorial-voice-to-text/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
// Initialize the singleton instance
await FoundryLocalManager.CreateAsync(config, logger);
var mgr = FoundryLocalManager.Instance;

// Download and register all execution providers.
var currentEp = "";
await mgr.DownloadAndRegisterEpsAsync((epName, percent) =>
{
if (epName != currentEp)
{
if (currentEp != "") Console.WriteLine();
currentEp = epName;
}
Console.Write($"\r {epName.PadRight(30)} {percent,6:F1}%");
});
if (currentEp != "") Console.WriteLine();

var catalog = await mgr.GetCatalogAsync();
// </init>

Expand Down
11 changes: 11 additions & 0 deletions samples/js/audio-transcription-example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ const manager = FoundryLocalManager.create({
// </init>
console.log('✓ SDK initialized successfully');

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

// <model_setup>
// Get the model object
const modelAlias = 'whisper-tiny'; // Using an available model from the list above
Expand Down
11 changes: 11 additions & 0 deletions samples/js/chat-and-audio-foundry-local/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ async function main() {
logLevel: "info",
});

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

const catalog = manager.catalog;

// --- Load both models ---
Expand Down
11 changes: 11 additions & 0 deletions samples/js/copilot-sdk-foundry-local/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ async function main() {
webServiceUrls: endpointUrl,
});

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

model = await manager.catalog.getModel(alias);
await model.download();
await model.load();
Expand Down
11 changes: 11 additions & 0 deletions samples/js/copilot-sdk-foundry-local/src/tool-calling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ async function main() {
webServiceUrls: endpointUrl,
});

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

model = await manager.catalog.getModel(alias);
await model.download();
await model.load();
Expand Down
33 changes: 25 additions & 8 deletions samples/js/electron-chat-application/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,34 @@ let webServiceStarted = false;
const SERVICE_PORT = 47392;
const SERVICE_URL = `http://127.0.0.1:${SERVICE_PORT}`;

let initPromise = null;

async function initializeSDK() {
if (manager) return manager;
if (initPromise) return initPromise;

const { FoundryLocalManager } = await import('foundry-local-sdk');
manager = FoundryLocalManager.create({
appName: 'foundry_local_samples',
logLevel: 'info',
webServiceUrls: SERVICE_URL
});
initPromise = (async () => {
const { FoundryLocalManager } = await import('foundry-local-sdk');
manager = FoundryLocalManager.create({
appName: 'foundry_local_samples',
logLevel: 'info',
webServiceUrls: SERVICE_URL
});

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

return manager;
})();

return manager;
return initPromise;
}

function ensureWebServiceStarted() {
Expand Down
11 changes: 11 additions & 0 deletions samples/js/langchain-integration-example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ const manager = FoundryLocalManager.create({
// </init>
console.log('✓ SDK initialized successfully');

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

// Get the model object
const modelAlias = 'qwen2.5-0.5b'; // Using an available model from the list above
const model = await manager.catalog.getModel(modelAlias);
Expand Down
11 changes: 11 additions & 0 deletions samples/js/tool-calling-foundry-local/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ async function runToolCallingExample() {
});
// </init>

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

// <model_setup>
const catalog = manager.catalog;
model = await catalog.getModel(alias);
Expand Down
11 changes: 11 additions & 0 deletions samples/js/tutorial-chat-assistant/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ const manager = FoundryLocalManager.create({
logLevel: 'info'
});

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

// Select and load a model from the catalog
const model = await manager.catalog.getModel('qwen2.5-0.5b');

Expand Down
11 changes: 11 additions & 0 deletions samples/js/tutorial-document-summarizer/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ const manager = FoundryLocalManager.create({
logLevel: 'info'
});

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

// Select and load a model from the catalog
const model = await manager.catalog.getModel('qwen2.5-0.5b');

Expand Down
11 changes: 11 additions & 0 deletions samples/js/tutorial-tool-calling/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ const manager = FoundryLocalManager.create({
logLevel: 'info'
});

// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');

const model = await manager.catalog.getModel('qwen2.5-0.5b');

await model.download((progress) => {
Expand Down
Loading
Loading