Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds availability APIs to the LanguageModel protocol, enabling models to communicate whether they're ready to handle requests. This eliminates the need to use @testable import to access underlying model availability states, as seen in the SystemLanguageModel tests.
Key changes:
- Introduces an
Availability<UnavailableReason>enum with.availableand.unavailable(reason)cases - Adds
UnavailableReasonassociated type andavailabilityproperty requirements to theLanguageModelprotocol - Provides default
.availableimplementation for models whereUnavailableReason == Never
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/AnyLanguageModel/Availability.swift | New file defining the Availability enum with generic unavailable reason support |
| Sources/AnyLanguageModel/LanguageModel.swift | Adds availability requirements and convenience property isAvailable to protocol |
| Sources/AnyLanguageModel/Models/SystemLanguageModel.swift | Implements availability API by bridging to FoundationModels availability, adds static .default accessor |
| Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift | Declares UnavailableReason = Never for always-available model |
| Sources/AnyLanguageModel/Models/OllamaLanguageModel.swift | Declares UnavailableReason = Never for always-available model |
| Sources/AnyLanguageModel/Models/MLXLanguageModel.swift | Declares UnavailableReason = Never for always-available model |
| Sources/AnyLanguageModel/Models/LlamaLanguageModel.swift | Declares UnavailableReason = Never for always-available model |
| Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift | Declares UnavailableReason = Never for always-available model |
| Sources/AnyLanguageModel/Models/AnthropicLanguageModel.swift | Declares UnavailableReason = Never for always-available model |
| Tests/AnyLanguageModelTests/SystemLanguageModelTests.swift | Updates test to use new public availability API instead of internal access |
| Tests/AnyLanguageModelTests/Shared/MockLanguageModel.swift | Implements availability support with customizable provider for testing |
| Tests/AnyLanguageModelTests/MockLanguageModelTests.swift | Adds test coverage for unavailable model scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AnyLanguageModel doesn't currently provide equivalent APIs for language models to communicate that they're unavailable. For example, in the case of the system Foundation Model, Apple Intelligence must be enabled, and that's indicated by
Availability.UnavailableReason.appleIntelligenceNotEnabled.One smell arising from this deficiency is that we needed to
@testable import AnyLanguageModelto introspect the underlying Foundation Models API to gate tests.This PR adds that availability functionality. The
LanguageModelprotocol adds a newUnavailableReasonassociated type requirement, which provides some flexibility for implementations to define their own specific reasons. For example, a model that proxies to service providers may report "network unreachable" and a model running locally may report "insufficient RAM".