Skip to content
Snippets Groups Projects

Add interface for using generic CoreML LLMs

Merged Abhinav Jain requested to merge compile_cmd_line_generic_model_broken into main
1 file
+ 4
4
Compare changes
  • Side-by-side
  • Inline
@@ -132,25 +132,25 @@ public enum LLMPredictionFunctions: DeclarationMacro {
ret +=
"""
public static func prediction(input: \(model_input_name)) throws -> \(model_output_name) {
let model = try \(model_type_name)(contentsOf: URL(fileURLWithPath: \"Sources/SwiftNLP/Models/\(model_url)\");
let model = try \(model_type_name)(contentsOf: URL(fileURLWithPath: \"Sources/SwiftNLP/Models/\(model_url)\"));
return try model.prediction(input: input, options: MLPredictionOptions())
}
public static func prediction(input: \(model_input_name), options: MLPredictionOptions) throws -> \(model_output_name) {
let model = try \(model_type_name)(contentsOf: URL(fileURLWithPath: \"Sources/SwiftNLP/Models/\(model_url)\");
let model = try \(model_type_name)(contentsOf: URL(fileURLWithPath: \"Sources/SwiftNLP/Models/\(model_url)\"));
let outFeatures: MLFeatureProvider = try model.prediction(input: input, options:options)
return \(model_output_name)(features: outFeatures)
}
@available(macOS 13.6, iOS 17.0, tvOS 17.0, watchOS 10.0, *)
public static func prediction(input: \(model_input_name), options: MLPredictionOptions = MLPredictionOptions()) async throws -> \(model_output_name) {
let model = try \(model_type_name)(contentsOf: URL(fileURLWithPath: \"Sources/SwiftNLP/Models/\(model_url)\");
let model = try \(model_type_name)(contentsOf: URL(fileURLWithPath: \"Sources/SwiftNLP/Models/\(model_url)\"));
let outFeatures: MLFeatureProvider? = try await model.prediction(input: input, options:options)
return \(model_output_name)(features: outFeatures!)
}
public static func predictions(inputs: [\(model_input_name)], options: MLPredictionOptions = MLPredictionOptions()) throws -> [\(model_output_name)] {
let model = try \(model_type_name)(contentsOf: URL(fileURLWithPath: \"Sources/SwiftNLP/Models/\(model_url)\");
let model = try \(model_type_name)(contentsOf: URL(fileURLWithPath: \"Sources/SwiftNLP/Models/\(model_url)\"));
let res = try model.predictions(inputs: inputs, options: options);
return res;
}
Loading