Skip to content

Instantly share code, notes, and snippets.

@kunal732
Created January 15, 2025 03:31
Show Gist options
  • Save kunal732/a18e83f3e477b687e5c925a54abb4f0c to your computer and use it in GitHub Desktop.
Save kunal732/a18e83f3e477b687e5c925a54abb4f0c to your computer and use it in GitHub Desktop.
Adding Microsoft's Phi-4 LLM in your swift MacOS application
import SwiftUI
import MLXModelManager
struct ContentView: View {
@StateObject var Phi4Manager = ModelManager(modelPath: "mlx-community/phi-4-4bit")
var body: some View {
VStack {
Button("answer prompt"){
Task {
//load model
try await Phi4Manager.loadModel()
//inference
await Phi4Manager.generate(
prompt: "why is the sky blue ?"
)
}
}
//Model Output
Text(Phi4Manager.output)
}
.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment