Skip to content
/ dalai Public
forked from cocktailpeanut/dalai

The simplest way to run LLaMA on your local machine

Notifications You must be signed in to change notification settings

finde/dalai

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dalai

Run LLaMA on your computer.

Github Twitter Discord


JUST RUN THIS:

TO GET:

dalai.gif


  1. Powered by llama.cpp and llama-dl CDN
  2. Hackable web app included
  3. Ships with JavaScript API
  4. Ships with Socket.io API

Intro

1. Cross platform

Dalai runs on all of the following operating systems:

  1. Linux
  2. Mac
  3. Windows

2. System Requirements

Runs on most modern computers. Unless your computer is very very old, it should work.

3. Disk Space Requirements

You need a lot of space for storing the models.

You do NOT have to install all models, you can install one by one. Let's take a look at how much space each model takes up:

NOTE

The following numbers assume that you DO NOT touch the original model files and keep BOTH the original model files AND the quantized versions.

You can optimize this if you delete the original models (which are much larger) after installation and keep only the quantized versions.

7B

  • Full: The model takes up 31.17GB
  • Quantized: 4.21GB

7b.png

13B

  • Full: The model takes up 60.21GB
  • Quantized: 4.07GB * 2 = 8.14GB

13b.png

30B

  • Full: The model takes up 150.48GB
  • Quantized: 5.09GB * 4 = 20.36GB

30b.png

65B

  • Full: The model takes up 432.64GB
  • Quantized: 5.11GB * 8 = 40.88GB

65b.png


Quickstart

Mac

Step 1. Install node.js

Install Node.js

Step 2. Install Dalai

Basic install (7B model only)

npx dalai llama

Or, install all models

npx dalai llama 7B 13B 30B 65B

The install command :

  1. Creates a folder named dalai under your home directory (~)
  2. Installs and builds the llama.cpp project under ~/llama.cpp
  3. Downloads all the requested models from the llama-dl CDN to ~/llama.cpp/models
  4. Runs some tasks to convert the LLaMA models so they can be used

Step 3. Run Web UI

After everything has been installed, launch the Web UI with:

npx dalai serve

Now open https://localhost:3000 in your browser. Have fun!


Windows

Step 1. Install Visual Studio

On windows, you need to install Visual Studio before installing Dalai.

Press the button below to visit the Visual Studio downloads page and download:

Download Microsoft Visual Studio


IMPORTANT!!!

When installing Visual Studio, make sure to check the 3 options as highlighted below:

  1. Python development
  2. Node.js development
  3. Desktop development with C++

vs.png

Step 2.1. Install Dalai

Basic install (7B model only)

npx dalai llama

Or, install all models

npx dalai llama 7B 13B 30B 65B

The install command :

  1. Creates a folder named dalai under your home directory (~)
  2. Installs and builds the llama.cpp project under ~/llama.cpp
  3. Downloads all the requested models from the llama-dl CDN to ~/llama.cpp/models
  4. Runs some tasks to convert the LLaMA models so they can be used

If this worked without any errors, go to step 3.

Ohterwise try the troubleshoot below:

Step 2.2. Troubleshoot (optional)

In case above steps fail to install, try installing node.js and python separately.

Install Python:

Download Python

Install Node.js:

Download Node.js

After both have been installed, open powershell and type python to see if the application exists. And also type node to see if the application exists as well.

Once you've checked that they both exist, try the npx dalai llama command again.

Step 3. Run Web UI

After everything has been installed, launch the Web UI with:

npx dalai serve

Now open https://localhost:3000 in your browser. Have fun!


Linux

Step 1. Install Dependencies

You need to make sure you have the correct version of Python and Node.js installed.

Step 1.1. Python <= 3.10

Make sure the version is 3.10 or lower (not 3.11)

Python must be 3.10 or below (pytorch and other libraries are not supported yet on the latest)

Download node.js

Step 1.2. Node.js >= 18

Make sure the version is 18 or higher

Download node.js

Step 2. Install

Basic install (7B model only)

npx dalai llama

Or, install all models

npx dalai llama 7B 13B 30B 65B

The install command :

  1. Creates a folder named dalai under your home directory (~)
  2. Installs and builds the llama.cpp project under ~/llama.cpp
  3. Downloads all the requested models from the llama-dl CDN to ~/llama.cpp/models
  4. Runs some tasks to convert the LLaMA models so they can be used

Step 3. Run Web UI

After everything has been installed, launch the Web UI with:

npx dalai serve

Now open https://localhost:3000 in your browser. Have fun!


API

Dalai is also an NPM package:

  1. programmatically install
  2. locally make requests to the model
  3. run a dalai server (powered by socket.io)
  4. programmatically make requests to a remote dalai server (via socket.io)

Dalai is an NPM package. You can install it using:

npm install dalai

1. constructor()

Syntax

const dalai = new Dalai(home)
  • home: (optional) manually specify the llama.cpp folder

By default, Dalai automatically stores the entire llama.cpp repository under ~/llama.cpp.

However, often you may already have a llama.cpp repository somewhere else on your machine and want to just use that folder. In this case you can pass in the home attribute.

Examples

Basic

Creates a workspace at ~/llama.cpp

const dalai = new Dalai()

Custom path

Manually set the llama.cpp path:

const dalai = new Dalai("/Documents/llama.cpp")

2. request()

Syntax

dalai.request(req, callback)
  • req: a request object. made up of the following attributes:
    • prompt: (required) The prompt string
    • model: (required) The model name to query ("7B", "13B", etc.)
    • url: only needed if connecting to a remote dalai server
      • if unspecified, it uses the node.js API to directly run dalai locally
      • if specified (for example ws:https://localhost:3000) it looks for a socket.io endpoint at the URL and connects to it.
    • threads: The number of threads to use (The default is 8 if unspecified)
    • n_predict: The number of tokens to return (The default is 128 if unspecified)
    • seed: The seed. The default is -1 (none)
    • top_k
    • top_p
    • repeat_last_n
    • repeat_penalty
    • temp: temperature
    • batch_size: batch size
    • skip_end: by default, every session ends with \n\n<end>, which can be used as a marker to know when the full response has returned. However sometimes you may not want this suffix. Set skip_end: true and the response will no longer end with \n\n<end>
  • callback: the streaming callback function that gets called every time the client gets any token response back from the model

Examples

1. Node.js

Using node.js, you just need to initialize a Dalai object with new Dalai() and then use it.

const Dalai = require('dalai')
new Dalai().request({
  model: "7B",
  prompt: "The following is a conversation between a boy and a girl:",
}, (token) => {
  process.stdout.write(token)
})

2. Non node.js (socket.io)

To make use of this in a browser or any other language, you can use thie socket.io API.

Step 1. start a server

First you need to run a Dalai socket server:

// server.js
const Dalai = require('dalai')
new Dalai().serve(3000)     // port 3000
Step 2. connect to the server

Then once the server is running, simply make requests to it by passing the ws:https://localhost:3000 socket url when initializing the Dalai object:

const Dalai = require("dalai")
new Dalai().request({
  url: "ws:https://localhost:3000",
  model: "7B",
  prompt: "The following is a conversation between a boy and a girl:",
}, (token) => {
  console.log("token", token)
})

3. serve()

Syntax

Starts a socket.io server at port

dalai.serve(port)

Examples

const Dalai = require("dalai")
new Dalai().serve(3000)

4. http()

Syntax

connect with an existing http instance (The http npm package)

dalai.http(http)
  • http: The http object

Examples

This is useful when you're trying to plug dalai into an existing node.js web app

const app = require('express')();
const http = require('http').Server(app);
dalai.http(http)
http.listen(3000, () => {
  console.log("server started")
})

5. install()

Syntax

await dalai.install(model1, model2, ...)
  • models: the model names to install ("7B"`, "13B", "30B", "65B", etc)

Examples

Install the "7B" and "13B" models:

const Dalai = require("dalai");
const dalai = new Dalai()
await dalai.install("7B", "13B")

6. installed()

returns the array of installed models

Syntax

const models = await dalai.installed()

Examples

const Dalai = require("dalai");
const dalai = new Dalai()
const models = await dalai.installed()
console.log(models)     // prints ["7B", "13B"]

FAQ

Updating to the latest

Dalai is a young project and will evolve quickly.

To update dalai, you will need to run the dalai command with a version number specified (You only need to do this once when you update).

For example, let's say you've been using [email protected] but a new version [email protected] came out.

The simplest way to update is to just run the dalai server:

Once you run the command it will ask you if you want to update. Confirm, and it will now install 0.2.0, and from that point on you don't need to specify the version. You can just run npx dalai serve and the new version will be executed from that point on.

Staying up to date

Have questions or feedback? Follow the project through the following outlets:

Github Twitter Discord


About

The simplest way to run LLaMA on your local machine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 74.1%
  • EJS 25.8%
  • Shell 0.1%