Skip to content

Proposal: Add MLX Chat Example App to the Repository #276

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

Closed
ibrahimcetin opened this issue Apr 21, 2025 · 3 comments
Closed

Proposal: Add MLX Chat Example App to the Repository #276

ibrahimcetin opened this issue Apr 21, 2025 · 3 comments

Comments

@ibrahimcetin
Copy link
Contributor

Hi, I developed an example chat app as I promised in this comment.

MLXChatExample App

MLX Chat Example is simple, practical, and modular. It supports both LLMs and VLMs, along with most features you’d expect from a modern chat app—cancellation, real-time generation, model switching, and chat clearing. The codebase is modular, with a clear separation between UI and business logic and it's well documented. However, it is not intended for production use—rather, I consider it a sandbox app for experimentation.

The Advantage of Structured Chat Messages

I developed this app to explore the benefits of structured chat messages. As shown here, this approach significantly simplifies the codebase and the usage of the package by abstracting away model-specific differences. It allows developers to easily use both LLMs and VLMs without having to manage model-specific chat structures manually.

One Problem

Initially, I tried creating this app inside the existing package (in the Applications folder), but I ran into issues binding the frameworks (MLXLLM, MLXVLM, MLXLMCommon) to the application target and couldn't find a solution. Here are the steps I followed:

  1. Open mlx-swift-examples.xcodeproj in Xcode
  2. Add a new target to the project
  3. Select “App” from the templates
  4. Create a SwiftUI project named MLXChatExample
  5. Go to Frameworks, Libraries, and Embedded Content, click the plus button
  6. Xcode should list the products from mlx-swift-examples, but they aren't shown—so I can't add them

I tried removing and re-adding the local package (which resets references in existing projects), and after that, Xcode successfully listed the products. However, this approach modifies the .xcodeproj file unnecessarily. Aside from that workaround, I haven’t found a clean solution.

What am I doing wrong?
Is there a proper way to add this project to the package as an example?
Or should we even include example apps directly in the package?

Conclusion

I believe mlx-swift-examples could really benefit from an example like this. If I can solve the integration issue, I'd love to contribute this app to the repository. But I also think it’s worth discussing whether we want to include these kinds of examples directly within the package.

@davidkoski
Copy link
Collaborator

What am I doing wrong?

I think the problem is how I set up the Package.swift as a local package. The goal is to make the xcodeproj build using the swiftpm version of the libraries -- we were seeing some inconsistencies in the builds when it was built both as an xcodeproj target and a swiftpm target.

The problem is that the target don't appear for local linking for some reason. I am pretty sure this is a bit of an abuse of how the local path is working.

Anyway, you aren't doing anything wrong. I think the project has problems.

OK, that said, it is possible to do it, but dirty. You can add 3 other projects, e.g. MLXFast, MLXRandom and MLXFFT. Then you can edit the xcodeproj in a text editor and replace those with the correct references. Not great, but until I figure out a better way to represent this it is the best we have. If you want to set up a PR I am happy to make these edits.

@davidkoski
Copy link
Collaborator

I have a little chat command line tool that I have been tinkering with today -- let me get a PR ready for that and we can discuss.

@davidkoski
Copy link
Collaborator

See #277

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants