Skip to content

Use IModel in the public API.#556

Open
skottmckay wants to merge 6 commits intomainfrom
skottmckay/IModel_updates
Open

Use IModel in the public API.#556
skottmckay wants to merge 6 commits intomainfrom
skottmckay/IModel_updates

Conversation

@skottmckay
Copy link
Copy Markdown
Collaborator

Use IModel in the public API. Changes allow ICatalog and IModel to be stubbed for testing as you no longer need a concrete Model or ModelVariant class.

  • Make Model and ModelVariant implementation details
  • Add variant info and selection to IModel so it works with either Model or ModelVariant
  • Move GetLatestVersion to Catalog and take IModel as input
    • ModelVariant has insufficient info to implement this and intuitively the catalog should know this information.
  • Update tests
    • fix usage of test config file for shared test data path

… stubbed for testing as you no longer need a concrete Model or ModelVariant class.

- Make Model and ModelVariant implementation details
- Add variant info and selection to IModel so it works with either Model or ModelVariant
- Move GetLatestVersion to Catalog and take IModel as input
  - ModelVariant has insufficient info to implement this and intuitively the catalog should know this information.
- Update tests
  - fix usage of test config file for shared test data path
Copilot AI review requested due to automatic review settings March 27, 2026 01:34
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

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

Project Deployment Actions Updated (UTC)
foundry-local Error Error Mar 27, 2026 2:15am

Request Review

Comment on lines +199 to +203
if (variant != this)
{
// error message is consistent with Model.SelectVariant
throw new FoundryLocalException($"Input variant was not found in Variants.");
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if it would be clearer to throw here to make the user aware it's a single variant and they need to call Catalog.GetModelAsync(variant.Alias) for this to be a meaningful option. I feel like that would avoid confusion given it should fail loudly during development if they call this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Updated in 889fd59. ModelVariant.SelectVariant now always throws a FoundryLocalException with a message directing the caller to use Catalog.GetModelAsync(alias) to get a Model with all variants available.

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 refactors the C# SDK public surface area to use IModel/ICatalog instead of concrete Model/ModelVariant, adds variant selection info to IModel, and moves “latest version” lookup logic onto the catalog. It also updates tests and test configuration to align with the new abstractions.

Changes:

  • Update ICatalog APIs to return/accept IModel and introduce GetLatestVersionAsync(IModel, ...).
  • Expand IModel with Info, Variants, SelectedVariant, and SelectVariant(IModel).
  • Adjust test setup/config and add/modify tests around catalog/model versioning behavior.

Reviewed changes

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

Show a summary per file
File Description
sdk/cs/src/ICatalog.cs Switches catalog API to IModel and adds GetLatestVersionAsync.
sdk/cs/src/IModel.cs Adds Info and variant-selection surface to the public model interface.
sdk/cs/src/Catalog.cs Implements updated ICatalog methods and adds latest-version lookup.
sdk/cs/src/Detail/Model.cs Adapts concrete Model to new IModel variant APIs.
sdk/cs/src/Detail/ModelVariant.cs Adapts ModelVariant to new IModel variant APIs.
sdk/cs/test/FoundryLocal.Tests/CatalogTests.cs Adds unit test coverage for GetLatestVersionAsync.
sdk/cs/test/FoundryLocal.Tests/ModelTests.cs Updates tests to new APIs (currently duplicates CatalogTests).
sdk/cs/test/FoundryLocal.Tests/ChatCompletionsTests.cs Moves test state to IModel instead of Model.
sdk/cs/test/FoundryLocal.Tests/AudioClientTests.cs Moves test state to IModel instead of Model.
sdk/cs/test/FoundryLocal.Tests/EndToEnd.cs Uses catalog model retrieval + variant selection instead of new Model(...).
sdk/cs/test/FoundryLocal.Tests/TestAssemblySetupCleanup.cs Makes cleanup resilient when the singleton manager wasn’t initialized.
sdk/cs/test/FoundryLocal.Tests/Utils.cs Reads test model cache directory from config; improves error visibility when missing.
sdk/cs/test/FoundryLocal.Tests/appsettings.Test.json Updates default test cache directory name.
sdk/cs/test/FoundryLocal.Tests/LOCAL_MODEL_TESTING.md Updates docs for running local model tests (currently has rendering issues).
Comments suppressed due to low confidence (2)

sdk/cs/src/Detail/Model.cs:15

  • PR description says Model should become an implementation detail, but this type is still public in the main namespace. If the intent is to hide it from the public surface, consider making it internal (or moving it under a non-public namespace) and ensuring ICatalog/IModel are the only public entry points; otherwise, please update the PR description to reflect that Model remains a supported public type.
    sdk/cs/src/Detail/ModelVariant.cs:26
  • PR description mentions ModelVariant becoming an implementation detail, but it remains a public type and is still surfaced via the public namespace (even if returned as IModel). If the goal is to hide it, consider making it internal/non-public; otherwise update the PR description to avoid implying it’s no longer part of the supported surface area.

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

…ctVariant error message

Agent-Logs-Url: https://github.com/microsoft/Foundry-Local/sessions/b48314ac-0aa9-457e-a8ea-03edb0b835f3

Co-authored-by: skottmckay <979079+skottmckay@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 1javsblobprodcus364.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/Microsoft.AI.Foundry.Local.csproj (dns block)
  • 51yvsblobprodcus36.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/Microsoft.AI.Foundry.Local.csproj (dns block)
  • imzvsblobprodcus368.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/Microsoft.AI.Foundry.Local.csproj (dns block)
  • s8mvsblobprodcus38.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/Microsoft.AI.Foundry.Local.csproj (dns block)
  • se1vsblobprodcus349.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/Microsoft.AI.Foundry.Local.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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