DRAFT: Add jamfile
, a JavaScript runtime for creating scripts/CLIs on top of llamafile
#661
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new
jamfile
project tollamafile
, which is a new JavaScript runtime for scripting with llamafile completion models, embeddings, SQLite, and more.This is a follow-up to my previous "
embedfile
" PR #644. There I tried to contribute an "embeddings CLI" that could embed/query different filetypes, but the "CLI-only" API wasn't very flexible, and any new feature would require C++ code.So I came up with a new tool,
jamfile
. It's a JavaScript runtime based on top of quickjs-ng, a fork of the original quickjs project. It's a tiny JavaScript engine written entirely in C, which we use to build a runtime with llamafile-specific APIs. It's a standalone cosmopolitan binary where you can write scripts in.js
files and execute them. There are JavaScript APIs for interacting with LLMs and embeddings models, using the samellamafile
library as thellamafile
server.There are a lot of builtin JS APIs and features, including a builtin
jamfile:sqlite
module for storing data in SQLite, withsqlite-vec
support.There's also a few JS builtins:
jamfile:cli
for parsing CLI arguments,jamfile:zod
for structured outputs,jamfile:colors
for printing coloring text to the terminal, etc.Structured outputs are possible with
CompletionModel
, working with JSON schema or raw GBNf files. A sample, using the bundled-in version ofzod
:And finally, you could "bundle" a JavaScript file + gguf models into a jamfile itself, just like llamafile. So a developer could "compile" their JS code + GGUF models into a standalone, cross-platform single-file executable and share it with friends. There's a sample of this in
jamfile/tests/standalone
, I'll try to get it on huggingface soon.This PR still needs a ton of work -
make install
support, error handling,man
pages, docs, etc. But it works pretty well and is a ton of fun to play with. There are examples injamfile/examples
that you can take a look at, but some may be out-of-date. I'll be working on this branch throughout the holidays and will update this PR body when features are added.But overall I'm pretty excited about this! I can see people using
jamfile
to create standalone CLI's, TUIs, scripts, or other AI applications. In a veeerrry long-term I could even see support for custom server-side endpoints written in JavaScript in llamafile itself, to create even more powerful AI apps with frontend support. There's a lot we could build with this!