Skip to content

Commit e99ff06

Browse files
Copilotbaijumeswaninenad1002
authored
Propagate IModel API changes across Python, JS, Rust SDKs and update C# docs (#565)
Mirrors the C# changes from #556 across all language bindings: public APIs use the `IModel` interface instead of concrete `Model`/`ModelVariant` types, `GetLatestVersion` moves from `Model` to `Catalog`, and `ModelVariant` becomes an implementation detail. ### IModel interface extended (Python, JS) - Added `info`, `variants`, `selected_variant`/`selectedVariant`, `select_variant`/`selectVariant` to the abstract interface - `ModelVariant` implements these as self-referential (`variants=[self]`, `selected_variant=self`, `select_variant` throws) ```python # Python - IModel now exposes variant info model = catalog.get_model("qwen2.5-0.5b") for v in model.variants: # List[IModel], not List[ModelVariant] print(v.info.name, v.id) model.select_variant(v) # takes IModel, not ModelVariant latest = catalog.get_latest_version(model) # moved from Model to Catalog ``` ### Catalog return types changed (Python, JS) - `list_models()` → `List[IModel]` (was `List[Model]`) - `get_model()` → `Optional[IModel]` (was `Optional[Model]`) - `get_model_variant()` → `Optional[IModel]` (was `Optional[ModelVariant]`) - `get_cached_models()` / `get_loaded_models()` → `List[IModel]` (was `List[ModelVariant]`) ### `get_latest_version` added to Catalog (Python, JS, Rust) Moved from `Model` to `Catalog` since `ModelVariant` lacks sufficient context to implement it. Takes any `IModel` and resolves the latest version by name matching against the variant list. ### Rust SDK - Added `Model::info()` (delegates to selected variant) - Added `Catalog::get_latest_version(&self, model: &Arc<Model>) -> Result<Arc<ModelVariant>>` ### C# docs and samples updated - README, API docs (`ICatalog`, `IModel`, `Model`, `ModelVariant`) updated to reflect `IModel` return types - `ModelVariant` docs marked as internal - Samples updated to avoid direct `ModelVariant` type references - `GetLatestVersionAsync` added to `ICatalog` docs --------- Co-authored-by: Baiju Meswani <bmeswani@microsoft.com> Co-authored-by: Nenad Banfic <46795300+nenad1002@users.noreply.github.com>
1 parent 2035462 commit e99ff06

30 files changed

Lines changed: 967 additions & 828 deletions

sdk/cs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ var loaded = await catalog.GetLoadedModelsAsync();
181181

182182
### Model Lifecycle
183183

184-
Each `Model` wraps one or more `ModelVariant` entries (different quantizations, hardware targets). The SDK auto-selects the best variant, or you can pick one:
184+
Each model may have multiple variants (different quantizations, hardware targets). The SDK auto-selects the best variant, or you can pick one. All models implement the `IModel` interface.
185185

186186
```csharp
187187
// Check and select variants
188-
Console.WriteLine($"Selected: {model.SelectedVariant.Id}");
188+
Console.WriteLine($"Selected: {model.Id}");
189189
foreach (var v in model.Variants)
190190
Console.WriteLine($" {v.Id} (cached: {await v.IsCachedAsync()})");
191191

@@ -389,8 +389,8 @@ Key types:
389389
| [`FoundryLocalManager`](./docs/api/microsoft.ai.foundry.local.foundrylocalmanager.md) | Singleton entry point — create, catalog, web service |
390390
| [`Configuration`](./docs/api/microsoft.ai.foundry.local.configuration.md) | Initialization settings |
391391
| [`ICatalog`](./docs/api/microsoft.ai.foundry.local.icatalog.md) | Model catalog interface |
392-
| [`Model`](./docs/api/microsoft.ai.foundry.local.model.md) | Model with variant selection |
393-
| [`ModelVariant`](./docs/api/microsoft.ai.foundry.local.modelvariant.md) | Specific model variant (hardware/quantization) |
392+
| [`IModel`](./docs/api/microsoft.ai.foundry.local.imodel.md) | Model interface — identity, metadata, lifecycle, variant selection |
393+
| [`Model`](./docs/api/microsoft.ai.foundry.local.model.md) | Model with variant selection (implements `IModel`) |
394394
| [`OpenAIChatClient`](./docs/api/microsoft.ai.foundry.local.openaichatclient.md) | Chat completions (sync + streaming) |
395395
| [`OpenAIAudioClient`](./docs/api/microsoft.ai.foundry.local.openaiaudioclient.md) | Audio transcription (sync + streaming) |
396396
| [`LiveAudioTranscriptionSession`](./docs/api/microsoft.ai.foundry.local.openai.liveaudiotranscriptionsession.md) | Real-time audio streaming session |

sdk/js/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const loaded = await catalog.getLoadedModels();
148148

149149
### Loading and Running Models
150150

151-
Each `Model` can have multiple variants (different quantizations or formats). The SDK automatically selects the best available variant, preferring cached versions.
151+
Each model can have multiple variants (different quantizations or formats). The SDK automatically selects the best available variant, preferring cached versions. All models implement the `IModel` interface.
152152

153153
```typescript
154154
const model = await catalog.getModel('qwen2.5-0.5b');
@@ -259,8 +259,7 @@ Auto-generated class documentation lives in [`docs/classes/`](docs/classes/):
259259

260260
- [FoundryLocalManager](docs/classes/FoundryLocalManager.md) — SDK entry point, web service management
261261
- [Catalog](docs/classes/Catalog.md) — Model discovery and browsing
262-
- [Model](docs/classes/Model.md) — High-level model with variant selection
263-
- [ModelVariant](docs/classes/ModelVariant.md) — Specific model variant: download, load, inference
262+
- [IModel](docs/README.md#imodel) — Model interface: variant selection, download, load, inference
264263
- [ChatClient](docs/classes/ChatClient.md) — Chat completions (sync and streaming)
265264
- [AudioClient](docs/classes/AudioClient.md) — Audio transcription (sync and streaming)
266265
- [ModelLoadManager](docs/classes/ModelLoadManager.md) — Low-level model loading management

sdk/js/docs/README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
- [FoundryLocalManager](classes/FoundryLocalManager.md)
2424
- [Model](classes/Model.md)
2525
- [ModelLoadManager](classes/ModelLoadManager.md)
26-
- [ModelVariant](classes/ModelVariant.md)
2726
- [ResponsesClient](classes/ResponsesClient.md)
2827
- [ResponsesClientSettings](classes/ResponsesClientSettings.md)
2928

@@ -562,6 +561,18 @@ get id(): string;
562561

563562
`string`
564563

564+
##### info
565+
566+
###### Get Signature
567+
568+
```ts
569+
get info(): ModelInfo;
570+
```
571+
572+
###### Returns
573+
574+
[`ModelInfo`](#modelinfo)
575+
565576
##### inputModalities
566577

567578
###### Get Signature
@@ -622,6 +633,20 @@ get supportsToolCalling(): boolean | null;
622633

623634
`boolean` \| `null`
624635

636+
##### variants
637+
638+
###### Get Signature
639+
640+
```ts
641+
get variants(): IModel[];
642+
```
643+
644+
Variants of the model that are available. Variants of the model are optimized for different devices.
645+
646+
###### Returns
647+
648+
[`IModel`](#imodel)[]
649+
625650
#### Methods
626651

627652
##### createAudioClient()
@@ -710,6 +735,29 @@ removeFromCache(): void;
710735
711736
`void`
712737
738+
##### selectVariant()
739+
740+
```ts
741+
selectVariant(variant): void;
742+
```
743+
744+
Select a model variant from variants to use for IModel operations.
745+
An IModel from `variants` can also be used directly.
746+
747+
###### Parameters
748+
749+
| Parameter | Type | Description |
750+
| ------ | ------ | ------ |
751+
| `variant` | [`IModel`](#imodel) | Model variant to select. Must be one of the variants in `variants`. |
752+
753+
###### Returns
754+
755+
`void`
756+
757+
###### Throws
758+
759+
Error if variant is not valid for this model.
760+
713761
##### unload()
714762
715763
```ts

sdk/js/docs/classes/Catalog.md

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,47 @@ The name of the catalog.
4747
### getCachedModels()
4848

4949
```ts
50-
getCachedModels(): Promise<ModelVariant[]>;
50+
getCachedModels(): Promise<IModel[]>;
5151
```
5252

5353
Retrieves a list of all locally cached model variants.
5454
This method is asynchronous as it may involve file I/O or querying the underlying core.
5555

5656
#### Returns
5757

58-
`Promise`\<[`ModelVariant`](ModelVariant.md)[]\>
58+
`Promise`\<[`IModel`](../README.md#imodel)[]\>
5959

60-
A Promise that resolves to an array of cached ModelVariant objects.
60+
A Promise that resolves to an array of cached IModel objects.
61+
62+
***
63+
64+
### getLatestVersion()
65+
66+
```ts
67+
getLatestVersion(modelOrModelVariant): Promise<IModel>;
68+
```
69+
70+
Get the latest version of a model.
71+
This is used to check if a newer version of a model is available in the catalog for download.
72+
73+
#### Parameters
74+
75+
| Parameter | Type | Description |
76+
| ------ | ------ | ------ |
77+
| `modelOrModelVariant` | [`IModel`](../README.md#imodel) | The model to check for the latest version. |
78+
79+
#### Returns
80+
81+
`Promise`\<[`IModel`](../README.md#imodel)\>
82+
83+
The latest version of the model. Will match the input if it is the latest version.
6184

6285
***
6386

6487
### getLoadedModels()
6588

6689
```ts
67-
getLoadedModels(): Promise<ModelVariant[]>;
90+
getLoadedModels(): Promise<IModel[]>;
6891
```
6992

7093
Retrieves a list of all currently loaded model variants.
@@ -73,16 +96,16 @@ the underlying core or an external service, which can be an I/O bound operation.
7396

7497
#### Returns
7598

76-
`Promise`\<[`ModelVariant`](ModelVariant.md)[]\>
99+
`Promise`\<[`IModel`](../README.md#imodel)[]\>
77100

78-
A Promise that resolves to an array of loaded ModelVariant objects.
101+
A Promise that resolves to an array of loaded IModel objects.
79102

80103
***
81104

82105
### getModel()
83106

84107
```ts
85-
getModel(alias): Promise<Model>;
108+
getModel(alias): Promise<IModel>;
86109
```
87110

88111
Retrieves a model by its alias.
@@ -96,9 +119,9 @@ This method is asynchronous as it may ensure the catalog is up-to-date by fetchi
96119

97120
#### Returns
98121

99-
`Promise`\<[`Model`](Model.md)\>
122+
`Promise`\<[`IModel`](../README.md#imodel)\>
100123

101-
A Promise that resolves to the Model object if found, otherwise throws an error.
124+
A Promise that resolves to the IModel object if found, otherwise throws an error.
102125

103126
#### Throws
104127

@@ -109,27 +132,29 @@ Error - If alias is null, undefined, or empty.
109132
### getModels()
110133

111134
```ts
112-
getModels(): Promise<Model[]>;
135+
getModels(): Promise<IModel[]>;
113136
```
114137

115138
Lists all available models in the catalog.
116139
This method is asynchronous as it may fetch the model list from a remote service or perform file I/O.
117140

118141
#### Returns
119142

120-
`Promise`\<[`Model`](Model.md)[]\>
143+
`Promise`\<[`IModel`](../README.md#imodel)[]\>
121144

122-
A Promise that resolves to an array of Model objects.
145+
A Promise that resolves to an array of IModel objects.
123146

124147
***
125148

126149
### getModelVariant()
127150

128151
```ts
129-
getModelVariant(modelId): Promise<ModelVariant>;
152+
getModelVariant(modelId): Promise<IModel>;
130153
```
131154

132155
Retrieves a specific model variant by its ID.
156+
NOTE: This will return an IModel with a single variant. Use getModel to get an IModel with all available
157+
variants.
133158
This method is asynchronous as it may ensure the catalog is up-to-date by fetching from a remote service.
134159

135160
#### Parameters
@@ -140,9 +165,9 @@ This method is asynchronous as it may ensure the catalog is up-to-date by fetchi
140165

141166
#### Returns
142167

143-
`Promise`\<[`ModelVariant`](ModelVariant.md)\>
168+
`Promise`\<[`IModel`](../README.md#imodel)\>
144169

145-
A Promise that resolves to the ModelVariant object if found, otherwise throws an error.
170+
A Promise that resolves to the IModel object if found, otherwise throws an error.
146171

147172
#### Throws
148173

sdk/js/docs/classes/Model.md

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ new Model(variant): Model;
2121

2222
| Parameter | Type |
2323
| ------ | ------ |
24-
| `variant` | [`ModelVariant`](ModelVariant.md) |
24+
| `variant` | `ModelVariant` |
2525

2626
#### Returns
2727

@@ -109,6 +109,28 @@ The ID of the selected variant.
109109

110110
***
111111

112+
### info
113+
114+
#### Get Signature
115+
116+
```ts
117+
get info(): ModelInfo;
118+
```
119+
120+
Gets the ModelInfo of the currently selected variant.
121+
122+
##### Returns
123+
124+
[`ModelInfo`](../README.md#modelinfo)
125+
126+
The ModelInfo object.
127+
128+
#### Implementation of
129+
130+
[`IModel`](../README.md#imodel).[`info`](../README.md#info)
131+
132+
***
133+
112134
### inputModalities
113135

114136
#### Get Signature
@@ -212,43 +234,22 @@ get supportsToolCalling(): boolean | null;
212234
#### Get Signature
213235

214236
```ts
215-
get variants(): ModelVariant[];
237+
get variants(): IModel[];
216238
```
217239

218240
Gets all available variants for this model.
219241

220242
##### Returns
221243

222-
[`ModelVariant`](ModelVariant.md)[]
223-
224-
An array of ModelVariant objects.
244+
[`IModel`](../README.md#imodel)[]
225245

226-
## Methods
246+
An array of IModel objects.
227247

228-
### addVariant()
229-
230-
```ts
231-
addVariant(variant): void;
232-
```
233-
234-
Adds a new variant to this model.
235-
Automatically selects the new variant if it is cached and the current one is not.
236-
237-
#### Parameters
238-
239-
| Parameter | Type | Description |
240-
| ------ | ------ | ------ |
241-
| `variant` | [`ModelVariant`](ModelVariant.md) | The model variant to add. |
242-
243-
#### Returns
244-
245-
`void`
246-
247-
#### Throws
248+
#### Implementation of
248249

249-
Error - If the argument is not a ModelVariant object, or if the variant's alias does not match the model's alias.
250+
[`IModel`](../README.md#imodel).[`variants`](../README.md#variants)
250251

251-
***
252+
## Methods
252253

253254
### createAudioClient()
254255

@@ -410,15 +411,19 @@ Selects a specific variant.
410411
411412
| Parameter | Type | Description |
412413
| ------ | ------ | ------ |
413-
| `variant` | [`ModelVariant`](ModelVariant.md) | The model variant to select. |
414+
| `variant` | [`IModel`](../README.md#imodel) | The model variant to select. Must be one of the variants in `variants`. |
414415
415416
#### Returns
416417
417418
`void`
418419
419420
#### Throws
420421
421-
Error - If the argument is not a ModelVariant object, or if the variant does not belong to this model.
422+
Error - If the variant does not belong to this model.
423+
424+
#### Implementation of
425+
426+
[`IModel`](../README.md#imodel).[`selectVariant`](../README.md#selectvariant)
422427
423428
***
424429

0 commit comments

Comments
 (0)