fix: improve model setup and native workflows

This commit is contained in:
public-repo-gate
2026-09-13 01:03:00 +03:00
parent 1cefe5b2ee
commit 30dae8b9a3
92 changed files with 13819 additions and 7022 deletions
+29 -3
View File
@@ -163,13 +163,20 @@ func speechModelCacheDirectory(for profile: SpeechModelProfile) -> URL {
}
public func speechModelCacheExists(for profile: SpeechModelProfile) -> Bool {
speechModelCacheIsComplete(for: profile, at: speechModelCacheDirectory(for: profile))
}
/// Быстрый probe для интерфейса: состав файлов, не SHA-256 сотен мегабайт.
/// Полная проверка по закреплённому манифесту остаётся перед загрузкой модели.
func speechModelCacheIsComplete(for profile: SpeechModelProfile, at directory: URL) -> Bool {
switch profile {
case .multilingualV3:
return FileManager.default.fileExists(atPath: speechModelCacheDirectory(for: profile).path)
return ModelIntegrity.parakeetV3CacheIsComplete(at: directory)
case .whisperLargeV3, .whisperTurbo:
// У whisper модель - ОДИН файл, и каталог без него бесполезен: проверяем файл.
guard let file = profile.whisperModelFile else { return false }
return FileManager.default.fileExists(atPath: whisperModelURL(file).path)
let values = try? directory.appendingPathComponent(file)
.resourceValues(forKeys: [.isRegularFileKey, .fileSizeKey])
return values?.isRegularFile == true && (values?.fileSize ?? 0) > 0
}
}
@@ -241,6 +248,25 @@ public enum ModelIntegrity {
// END GENERATED PARAKEET_V3_MODEL_MANIFEST
]
static var parakeetV3DownloadFiles: [ModelFileDigest] { parakeetV3Files }
static func parakeetV3CacheIsComplete(at directory: URL) -> Bool {
do {
let directories = Set(parakeetV3Files.flatMap { parentDirectories(of: $0.relativePath) })
for name in directories {
try requireDirectory(directory.appendingPathComponent(name), relativePath: name)
}
for file in parakeetV3Files {
let url = directory.appendingPathComponent(file.relativePath)
try requireRegularFile(url, relativePath: file.relativePath)
guard (try url.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? 0) > 0 else { return false }
}
return true
} catch {
return false
}
}
public static func verifyParakeetV3Model(at directory: URL) throws {
try verifyFiles(root: directory,
expectedFiles: parakeetV3Files,