I discovered that you can use NLModel for predictions. Here's an example:
guard let model = model,
let nlModel = try? NLModel(mlModel: model) else {
Logger.categoryClassifier.error("Failed to load NLModel.")
return nil
}
let hypotheses = nlModel.predictedLabelHypotheses(for: name.lowercased(), maximumCount: 10)
For more details, refer to the documentation: https://developer.apple.com/documentation/naturallanguage/nlmodel
Post
Replies
Boosts
Views
Activity
I encountered the same issue as @jknlsn. The didMigrate method was only triggered after switching the initializer.
let modelContainer: ModelContainer
let cloudConfig: ModelConfiguration = .init()
let localConfig: ModelConfiguration = .init(cloudKitDatabase: .none)
let schema = Schema(CurrentScheme.models)
do {
_ = try? ModelContainer(
for: schema,
migrationPlan: MigrationPlan.self,
configurations: localConfig
)
if let iCloudContainer = try? ModelContainer(
for: schema,
migrationPlan: MigrationPlan.self,
configurations: cloudConfig
) {
modelContainer = iCloudContainer
} else {
modelContainer = try ModelContainer(
for: schema,
migrationPlan: MigrationPlan.self,
configurations: localConfig
)
}
} catch {
fatalError("Failed to create the model container: \(error)")
}
Has anyone managed to get the confidence level? It still doesn't seem to be working.
The issue still exists on iOS18 and beta 18.1.
Entity
import AppIntents
struct CategoryEntity: AppEntity {
var id: UUID
var name: String
init(name: String) {
self.id = UUID()
self.name = name
}
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: LocalizedStringResource(stringLiteral: name))
}
static let typeDisplayRepresentation: TypeDisplayRepresentation = "Category"
static let defaultQuery = CategoryEntityQuery()
}
struct CategoryEntityQuery: EntityQuery {
func entities(for identifiers: [CategoryEntity.ID]) async throws -> [CategoryEntity] {
SampleData.categories
}
func suggestedEntities() async throws -> [CategoryEntity] {
SampleData.categories
}
}
struct SampleData {
static var categories: [CategoryEntity] = [
.init(name: "Category 1"),
.init(name: "Category 2"),
.init(name: "Category 3"),
.init(name: "Category 4"),
.init(name: "Category 5")
]
}
Intent
import AppIntents
struct Intent: AppIntent {
static let title: LocalizedStringResource = "Intent"
static var parameterSummary: some ParameterSummary {
Summary("Test \(\.$category)") {
/// $hidden.requestValue() functions properly when it is included in the ParameterSummary
// \.$hidden
}
}
@Parameter(title: "Visible Category")
var category: CategoryEntity?
@Parameter(title: "Hidden Category")
private var hidden: CategoryEntity?
@MainActor
func perform() async throws -> some ReturnsValue<CategoryEntity?> {
let visible = try? await $category.requestValue("Select visible category") // Works as expected
var hidden: CategoryEntity?
/// Fails since iOS 18 because $hidden is not part of the ParameterSummary
do {
hidden = try await $hidden.requestValue("Select hidden category")
} catch {
/// Error Domain=NSCocoaErrorDomain Code=4099 "The connection from pid 11647 on anonymousListener or serviceListener was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection from pid 11647 on anonymousListener or serviceListener was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.}
print(error)
}
let value = hidden ?? visible
print("Category: \(value?.name ?? "none")")
return .result(value: value)
}
}
Test project added to demonstrate the issue.
FB14828592
I'm encountering the same issue, but it seems to have stopped working, likely since iOS 17.
https://developer.apple.com/forums/thread/765516
FB14035016