diff --git a/Tests/ModelsTests/WeightsTests.swift b/Tests/ModelsTests/WeightsTests.swift index c907125..e69fe27 100644 --- a/Tests/ModelsTests/WeightsTests.swift +++ b/Tests/ModelsTests/WeightsTests.swift @@ -13,7 +13,8 @@ struct WeightsTests { @Test("Load weights from file URL") func loadWeightsFromFileURL() async throws { let repo = "google/bert_uncased_L-2_H-128_A-2" - let modelDir = try await hubApi.snapshot(from: repo, matching: ["config.json", "model.safetensors"]) + let onlineHubApi = HubApi(downloadBase: downloadDestination, useOfflineMode: false) + let modelDir = try await onlineHubApi.snapshot(from: repo, matching: ["config.json", "model.safetensors"]) let files = try FileManager.default.contentsOfDirectory(at: modelDir, includingPropertiesForKeys: [.isReadableKey]) #expect(files.contains(where: { $0.lastPathComponent == "config.json" })) diff --git a/Tests/TokenizersTests/FactoryTests.swift b/Tests/TokenizersTests/FactoryTests.swift index b5bf1eb..08f0b42 100644 --- a/Tests/TokenizersTests/FactoryTests.swift +++ b/Tests/TokenizersTests/FactoryTests.swift @@ -10,10 +10,10 @@ import Hub import Testing import Tokenizers -private func makeHubApi() -> (api: HubApi, downloadDestination: URL) { +private func makeHubApi(useOfflineMode: Bool? = nil) -> (api: HubApi, downloadDestination: URL) { let base = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first! let destination = base.appending(component: "huggingface-tests-\(UUID().uuidString)") - return (HubApi(downloadBase: destination), destination) + return (HubApi(downloadBase: destination, useOfflineMode: useOfflineMode), destination) } @Suite("Factory") @@ -40,7 +40,7 @@ struct FactoryTests { @Test func fromModelFolder() async throws { - let (hubApi, downloadDestination) = makeHubApi() + let (hubApi, downloadDestination) = makeHubApi(useOfflineMode: false) defer { try? FileManager.default.removeItem(at: downloadDestination) } let filesToDownload = ["config.json", "tokenizer_config.json", "tokenizer.json"] @@ -54,7 +54,7 @@ struct FactoryTests { @Test func whisperFromModelFolder() async throws { - let (hubApi, downloadDestination) = makeHubApi() + let (hubApi, downloadDestination) = makeHubApi(useOfflineMode: false) defer { try? FileManager.default.removeItem(at: downloadDestination) } let filesToDownload = ["config.json", "tokenizer_config.json", "tokenizer.json"] diff --git a/Tests/TokenizersTests/TokenizerTests.swift b/Tests/TokenizersTests/TokenizerTests.swift index b731194..1305b71 100644 --- a/Tests/TokenizersTests/TokenizerTests.swift +++ b/Tests/TokenizersTests/TokenizerTests.swift @@ -244,7 +244,7 @@ struct TokenizerTests { return base.appending(component: "hf-local-pretrained-tests-downloads") }() - let hubApi = HubApi(downloadBase: downloadDestination) + let hubApi = HubApi(downloadBase: downloadDestination, useOfflineMode: false) let downloadedTo = try await hubApi.snapshot(from: "pcuenq/gemma-tokenizer") let tokenizerOpt = try await AutoTokenizer.from(modelFolder: downloadedTo) as? PreTrainedTokenizer