-
-
Notifications
You must be signed in to change notification settings - Fork 68
Disable Apple Intelligence in engine pickers when it is unavailable #837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
Cotabby/Support/Settings/SuggestionEngineSelectionPolicy.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import Foundation | ||
|
|
||
| /// Decides which suggestion engines a user may pick from an engine picker, and how each option is | ||
| /// labelled, given what this Mac can currently run. | ||
| /// | ||
| /// Why this exists as its own type: onboarding (`WelcomeTemplateStepView`) and the power-profile | ||
| /// pickers already refuse Apple Intelligence when `FoundationModelAvailabilityService` reports it | ||
| /// unavailable, but the Settings and menu bar engine pickers listed every `SuggestionEngineKind` | ||
| /// unconditionally. Putting the rule in one pure `Support/` policy lets every picker share the same | ||
| /// answer and lets tests pin it without SwiftUI or a real `SystemLanguageModel`. | ||
| /// | ||
| /// Scope: this gates *new* selections only. A previously persisted Apple Intelligence selection is | ||
| /// still honored as stored; the Settings callout and the engine's own `unavailable` error explain | ||
| /// why nothing is generated, and the choice comes back to life if Apple Intelligence becomes | ||
| /// available later (for example after its model finishes downloading). | ||
| enum SuggestionEngineSelectionPolicy { | ||
| /// Whether `engine` may be chosen right now. Only Apple Intelligence depends on runtime | ||
| /// availability; Open Source and the local endpoint are always selectable because their own | ||
| /// panes guide the user through downloading a model or configuring a server. | ||
| static func isSelectable( | ||
| _ engine: SuggestionEngineKind, | ||
| foundationModelAvailable: Bool | ||
| ) -> Bool { | ||
| switch engine { | ||
| case .appleIntelligence: | ||
| return foundationModelAvailable | ||
| case .llamaOpenSource, .openAICompatible: | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| /// The picker row text. Unselectable engines carry an "(Unavailable)" suffix so a greyed-out | ||
| /// menu item still explains itself; the detailed reason stays in the pane callout. | ||
| static func pickerLabel( | ||
| for engine: SuggestionEngineKind, | ||
| foundationModelAvailable: Bool | ||
| ) -> String { | ||
| guard isSelectable(engine, foundationModelAvailable: foundationModelAvailable) else { | ||
| return "\(engine.displayLabel) (Unavailable)" | ||
| } | ||
| return engine.displayLabel | ||
| } | ||
| } |
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
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
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
44 changes: 44 additions & 0 deletions
44
CotabbyTests/Support/Settings/SuggestionEngineSelectionPolicyTests.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import XCTest | ||
| @testable import Cotabby | ||
|
|
||
| /// Pins the engine-picker gating shared by Settings and the menu bar so Apple Intelligence can never | ||
| /// again be offered as a selectable engine on a Mac that cannot run it, while the other engines stay | ||
| /// selectable regardless of Apple Intelligence availability. | ||
| final class SuggestionEngineSelectionPolicyTests: XCTestCase { | ||
| func test_isSelectable_appleIntelligenceFollowsAvailability() { | ||
| XCTAssertTrue( | ||
| SuggestionEngineSelectionPolicy.isSelectable(.appleIntelligence, foundationModelAvailable: true) | ||
| ) | ||
| XCTAssertFalse( | ||
| SuggestionEngineSelectionPolicy.isSelectable(.appleIntelligence, foundationModelAvailable: false) | ||
| ) | ||
| } | ||
|
|
||
| func test_isSelectable_otherEnginesIgnoreAppleAvailability() { | ||
| for engine in [SuggestionEngineKind.llamaOpenSource, .openAICompatible] { | ||
| for available in [true, false] { | ||
| XCTAssertTrue( | ||
| SuggestionEngineSelectionPolicy.isSelectable(engine, foundationModelAvailable: available), | ||
| "\(engine) available=\(available)" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func test_pickerLabel_marksOnlyUnselectableEngines() { | ||
| XCTAssertEqual( | ||
| SuggestionEngineSelectionPolicy.pickerLabel(for: .appleIntelligence, foundationModelAvailable: false), | ||
| "Apple Intelligence (Unavailable)" | ||
| ) | ||
| for engine in SuggestionEngineKind.allCases { | ||
| XCTAssertEqual( | ||
| SuggestionEngineSelectionPolicy.pickerLabel(for: engine, foundationModelAvailable: true), | ||
| engine.displayLabel | ||
| ) | ||
| } | ||
| XCTAssertEqual( | ||
| SuggestionEngineSelectionPolicy.pickerLabel(for: .llamaOpenSource, foundationModelAvailable: false), | ||
| SuggestionEngineKind.llamaOpenSource.displayLabel | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!