Skip to content

Replace usage of Bundle.module to build outside SPM context #125

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/Hub/Hub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ public class LanguageModelConfigurationFromHub {
}

static func fallbackTokenizerConfig(for modelType: String) -> Config? {
guard let url = Bundle.module.url(forResource: "\(modelType)_tokenizer_config", withExtension: "json") else { return nil }
let bundle = Bundle(for: self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could fix the tests doing something like:

Suggested change
let bundle = Bundle(for: self)
let bundle = NSClassFromString("XCTest") != nil ? Bundle.module : Bundle(for: self)

But upon additional testing I found that building a CLI that uses Tokenizers would not find the fallback configuration either.

Do you have any thoughts on that? Some additional ideas:

  • Iterate through the bundles and select the right one.
  • Create a bundle (or framework?) solely dedicated to hosting the resources.
  • Download the fallback configs from a well-known location in the Hub.

guard let url = bundle.url(forResource: "\(modelType)_tokenizer_config", withExtension: "json") else { return nil }
do {
let data = try Data(contentsOf: url)
let parsed = try JSONSerialization.jsonObject(with: data, options: [])
Expand Down
Loading