Skip to content

Propagate IModel API changes across Python, JS, Rust SDKs and update C# docs#565

Open
Copilot wants to merge 5 commits intomainfrom
copilot/update-language-bindings-documentation
Open

Propagate IModel API changes across Python, JS, Rust SDKs and update C# docs#565
Copilot wants to merge 5 commits intomainfrom
copilot/update-language-bindings-documentation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

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 - 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

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Apr 1, 2026 6:08am

Request Review

@baijumeswani baijumeswani force-pushed the copilot/update-language-bindings-documentation branch from 9b6ff02 to 1895c97 Compare March 31, 2026 21:45
@baijumeswani baijumeswani marked this pull request as ready for review March 31, 2026 21:46
Copilot AI review requested due to automatic review settings March 31, 2026 21:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR propagates the “public API returns IModel” design across the SDKs, making model variants an implementation detail and aligning model/variant selection capabilities with the interface-based API approach introduced in #556.

Changes:

  • Introduces/extends IModel across Rust/Python/JS and updates model/variant selection APIs to operate on IModel.
  • Updates Rust/Python/JS Catalog methods to return interface types (IModel / Arc<dyn IModel>) rather than concrete Model/ModelVariant.
  • Updates READMEs, examples, and tests to use the new interface-based APIs (including boxed callbacks in Rust).

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
sdk/rust/tests/integration/model_test.rs Updates integration assertions to avoid direct selected-variant access patterns.
sdk/rust/src/model_variant.rs Removes the previously-public ModelVariant module (variant becomes internal).
sdk/rust/src/lib.rs Exposes IModel publicly and rewires exports to internal detail implementations.
sdk/rust/src/imodel.rs Adds the public Rust IModel trait surface.
sdk/rust/src/detail/model.rs Makes Model implement IModel and forwards operations to the selected variant.
sdk/rust/src/detail/model_variant.rs Reintroduces ModelVariant as a crate-internal implementation of IModel.
sdk/rust/src/detail/mod.rs Registers model and model_variant as internal detail modules.
sdk/rust/src/catalog.rs Changes Catalog query methods to return Arc<dyn IModel> instead of concrete model types.
sdk/rust/README.md Updates Rust documentation/examples to the IModel-based API and boxed progress callbacks.
sdk/rust/examples/tool_calling.rs Updates example to use IModel accessors and boxed progress callbacks.
sdk/rust/examples/interactive_chat.rs Updates example to box download progress callback.
sdk/rust/examples/chat_completion.rs Updates example to box download progress callback.
sdk/python/src/imodel.py Extends Python IModel with info, variants, and select_variant.
sdk/python/src/detail/model.py Updates Model to implement new IModel surface and accept IModel variant selection.
sdk/python/src/detail/model_variant.py Updates ModelVariant to implement variants/select_variant behavior as a single-variant IModel.
sdk/python/src/catalog.py Changes Catalog return types to IModel for model/variant/cached/loaded queries.
sdk/python/README.md Updates Python docs to describe IModel as the primary public abstraction.
sdk/js/test/openai/responsesClient.test.ts Adjusts test import to reference internal detail/model.
sdk/js/test/model.test.ts Updates test to select a variant via model.variants (IModel-based selection).
sdk/js/src/index.ts Marks Model/ModelVariant exports as internal and exposes IModel type.
sdk/js/src/imodel.ts Extends JS IModel with info, variants, and selectVariant.
sdk/js/src/detail/modelVariant.ts Aligns ModelVariant with IModel (renames info accessor and adds single-variant behaviors).
sdk/js/src/detail/model.ts Updates Model to implement IModel.info and accept IModel in selectVariant.
sdk/js/src/catalog.ts Changes Catalog method return types to IModel and adds getLatestVersion.
sdk/js/README.md Updates JS README language to IModel-first API reference.
sdk/cs/README.md Updates C# README snippets and key-types list to reflect IModel usage.
samples/rust/tutorial-voice-to-text/src/main.rs Updates sample to box download progress callbacks.
samples/rust/tutorial-tool-calling/src/main.rs Updates sample to box download progress callbacks.
samples/rust/tutorial-document-summarizer/src/main.rs Updates sample to box download progress callbacks.
samples/rust/tutorial-chat-assistant/src/main.rs Updates sample to box download progress callbacks.
samples/rust/tool-calling-foundry-local/src/main.rs Updates sample to box download progress callbacks.
samples/rust/native-chat-completions/src/main.rs Updates sample to box download progress callbacks.
samples/rust/foundry-local-webserver/src/main.rs Updates sample to box download progress callbacks (including move closure).
samples/rust/audio-transcription-example/src/main.rs Updates sample to box download progress callbacks.
Comments suppressed due to low confidence (3)

sdk/rust/src/detail/model.rs:172

  • Arc::clone(v) as Arc<dyn IModel> is likely to be rejected as a non-primitive cast. Return Arc::clone(v) and let it coerce to Arc<dyn IModel> (or explicitly bind/annotate the trait-object type) instead.
    sdk/python/src/detail/model.py:58
  • The new error message when a variant can’t be selected is too generic (it loses the alias, requested variant id, and available ids), which makes debugging harder. Consider including the model alias, the requested variant.id, and the set of available variant ids (similar to the previous behavior).
    sdk/js/src/detail/model.ts:52
  • The new error message for an invalid selectVariant input is too generic (it omits the model alias, requested variant id, and what variant ids are valid). Including that context will make it much easier for callers to diagnose why selection failed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

sdk/js/src/detail/model.ts:52

  • selectVariant no longer validates variant for null/undefined/non-object inputs. Because this method is reachable via the public IModel returned by Catalog.getModel(), passing an invalid value will now throw an unhelpful runtime TypeError when accessing variant.id. Add an explicit guard (and a clear error) before dereferencing variant.id to preserve runtime-safety for JS callers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants