Skip to content

Commit 97bee1e

Browse files
Copilotbaijumeswani
andcommitted
C# SDK: Update README, docs and samples for IModel API changes
Agent-Logs-Url: https://github.com/microsoft/Foundry-Local/sessions/8082508c-1338-48b2-bdd3-6c2c8e35e195 Co-authored-by: baijumeswani <12852605+baijumeswani@users.noreply.github.com>
1 parent d0b2d04 commit 97bee1e

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

samples/cs/GettingStarted/src/AudioTranscriptionExample/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
var catalog = await mgr.GetCatalogAsync();
2424

2525

26-
// Get a model using an alias and select the CPU model variant
26+
// Get a model using an alias and select the CPU variant
2727
var model = await catalog.GetModelAsync("whisper-tiny") ?? throw new System.Exception("Model not found");
28-
var modelVariant = model.Variants.First(v => v.Info.Runtime?.DeviceType == DeviceType.CPU);
29-
model.SelectVariant(modelVariant);
28+
var cpuVariant = model.Variants.First(v => v.Info.Runtime?.DeviceType == DeviceType.CPU);
29+
model.SelectVariant(cpuVariant);
3030

3131

3232
// Download the model (the method skips download if already cached)

samples/cs/GettingStarted/src/ModelManagementExample/Program.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,26 @@
6767

6868

6969
// OPTIONAL: `model` can be used directly and `model.SelectedVariant` will be used as the default.
70-
// You can explicitly select or use a specific ModelVariant if you want more control
70+
// You can explicitly select a specific variant if you want more control
7171
// over the device and/or execution provider used.
72-
// Model and ModelVariant can be used interchangeably in methods such as
72+
// Model and its variants can be used interchangeably in methods such as
7373
// DownloadAsync, LoadAsync, UnloadAsync and GetChatClientAsync.
7474
//
7575
// Choices:
76-
// - Use a ModelVariant directly from the catalog if you know the variant Id
77-
// - `var modelVariant = await catalog.GetModelVariantAsync("qwen2.5-0.5b-instruct-generic-gpu:3")`
76+
// - Use a variant directly from the catalog if you know the variant Id
77+
// - `var variant = await catalog.GetModelVariantAsync("qwen2.5-0.5b-instruct-generic-gpu:3")`
7878
//
79-
// - Get the ModelVariant from Model.Variants
80-
// - `var modelVariant = model.Variants.First(v => v.Id == "qwen2.5-0.5b-instruct-generic-cpu:4")`
81-
// - `var modelVariant = model.Variants.First(v => v.Info.Runtime?.DeviceType == DeviceType.GPU)`
82-
// - optional: update selected variant in `model` using `model.SelectVariant(modelVariant);` if you wish to use
79+
// - Get the variant from Model.Variants
80+
// - `var variant = model.Variants.First(v => v.Id == "qwen2.5-0.5b-instruct-generic-cpu:4")`
81+
// - `var variant = model.Variants.First(v => v.Info.Runtime?.DeviceType == DeviceType.GPU)`
82+
// - optional: update selected variant in `model` using `model.SelectVariant(variant);` if you wish to use
8383
// `model` in your code.
8484

8585
// For this example we explicitly select the CPU variant, and call SelectVariant so all the following example code
8686
// uses the `model` instance.
8787
Console.WriteLine("Selecting CPU variant of model");
88-
var modelVariant = model.Variants.First(v => v.Info.Runtime?.DeviceType == DeviceType.CPU);
89-
model.SelectVariant(modelVariant);
88+
var cpuVariant = model.Variants.First(v => v.Info.Runtime?.DeviceType == DeviceType.CPU);
89+
model.SelectVariant(cpuVariant);
9090

9191

9292
// Download the model (the method skips download if already cached)

sdk/cs/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The Foundry Local C# SDK provides a .NET interface for running AI models locally
99
- **Chat completions** — synchronous and `IAsyncEnumerable` streaming via OpenAI-compatible types
1010
- **Audio transcription** — transcribe audio files with streaming support
1111
- **Download progress** — wire up an `Action<float>` callback for real-time download percentage
12-
- **Model variants** — select specific hardware/quantization variants per model alias
12+
- **Model variants** — select specific hardware/quantization variants per model alias via the IModel interface
1313
- **Optional web service** — start an OpenAI-compatible REST endpoint (`/v1/chat_completions`, `/v1/models`)
1414
- **WinML acceleration** — opt-in Windows hardware acceleration with automatic EP download
1515
- **Full async/await** — every operation supports `CancellationToken` and async patterns
@@ -138,11 +138,14 @@ var cached = await catalog.GetCachedModelsAsync();
138138

139139
// List models currently loaded in memory
140140
var loaded = await catalog.GetLoadedModelsAsync();
141+
142+
// Check for a newer version of a model
143+
var latest = await catalog.GetLatestVersionAsync(model);
141144
```
142145

143146
### Model Lifecycle
144147

145-
Each `Model` wraps one or more `ModelVariant` entries (different quantizations, hardware targets). The SDK auto-selects the best variant, or you can pick one:
148+
Each `Model` wraps one or more variant entries (different quantizations, hardware targets). The SDK auto-selects the best variant, or you can pick one:
146149

147150
```csharp
148151
// Check and select variants
@@ -293,8 +296,8 @@ Key types:
293296
| [`FoundryLocalManager`](./docs/api/microsoft.ai.foundry.local.foundrylocalmanager.md) | Singleton entry point — create, catalog, web service |
294297
| [`Configuration`](./docs/api/microsoft.ai.foundry.local.configuration.md) | Initialization settings |
295298
| [`ICatalog`](./docs/api/microsoft.ai.foundry.local.icatalog.md) | Model catalog interface |
296-
| [`Model`](./docs/api/microsoft.ai.foundry.local.model.md) | Model with variant selection |
297-
| [`ModelVariant`](./docs/api/microsoft.ai.foundry.local.modelvariant.md) | Specific model variant (hardware/quantization) |
299+
| [`IModel`](./docs/api/microsoft.ai.foundry.local.imodel.md) | Model interface — shared by Model and ModelVariant |
300+
| [`Model`](./docs/api/microsoft.ai.foundry.local.model.md) | Model with variant selection (implementation detail) |
298301
| [`OpenAIChatClient`](./docs/api/microsoft.ai.foundry.local.openaichatclient.md) | Chat completions (sync + streaming) |
299302
| [`OpenAIAudioClient`](./docs/api/microsoft.ai.foundry.local.openaiaudioclient.md) | Audio transcription (sync + streaming) |
300303
| [`ModelInfo`](./docs/api/microsoft.ai.foundry.local.modelinfo.md) | Full model metadata record |

0 commit comments

Comments
 (0)