Skip to content

Latest commit

 

History

History

jsctrl

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

JsCtrl

This crate implements AI Controller Interface by embedding QuickJS (JavaScript (ES2023) interpreter) via rquickjs in a Wasm module together with native primitives for specific kinds of output constraints: fixed token output, regexps, LR(1) grammars, substring constrains etc. JavaScript code is typically only used lightly, for gluing the primitives together, and thus is not performance critical.

There are some sample scripts available. The scripts use the aici module to communicate with the AICI runtime and use the native constraints.

This is quite similar to PyCtrl but with JavaScript instead of Python. It is also smaller, at 1.3MiB without regex and CFG, 1.8MiB with regex, and 3.3MiB with regex and CFG. For comparison, pyctrl is 14MiB. Also, the PyCtrl samples translate 1:1 to JsCtrl.

Usage

To run a JsCtrl sample use:

../../aici.sh run samples/hello.js

If you write your sample in TypeScript, compile it first with tsc -p samples.

If you want to build the interpreter yourself, use:

../../aici.sh run --build . samples/hello.js

You will see the console output of the program.