Skip to content

Commit

Permalink
BREAKING CHANGE: binding for node-llama-cpp (v1) dropped (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto authored Sep 30, 2023
1 parent c28f645 commit 0789e31
Show file tree
Hide file tree
Showing 18 changed files with 240 additions and 973 deletions.
32 changes: 5 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
<br />

Run GGML/GGUF models on your computer with a chat ui.
Run GGUF models on your computer with a chat ui.

> Your own AI assistant runs locally on your computer.
Expand Down Expand Up @@ -49,7 +49,7 @@ Options:
-h, --help display help for command
Commands:
install|i [options] [models...] Install any GGML/GGUF model
install|i [options] [models...] Install any GGUF model
models|ls [options] List all available models
use [model] Set model to use
serve|up [options] Open the chat website
Expand All @@ -65,7 +65,7 @@ Commands:
```
Usage: cli install|i [options] [models...]
Install any GGML model
Install any GGUF model
Arguments:
models Model name/url/path
Expand Down Expand Up @@ -123,35 +123,13 @@ const response = await fetch('http://127.0.0.1:3000/api/chat/prompt', {
const data = await response.text();
```

### Streaming the response

```js
const response = await fetch('http://127.0.0.1:3000/api/chat/prompt', {
method: 'POST',
body: JSON.stringify({
prompt: 'Write me 100 words story'
}),
headers: {
'Content-Type': 'application/json'
}
});


const reader = response.body.pipeThrough(new TextDecoderStream())
.getReader();

while (true) {
const {value, done} = await reader.read();
if (done) break;
console.log('Received', value);
}
```
For more information, please read the [API guide](https://github.com/withcatai/catai/blob/main/docs/api.md)

## Configuration

You can edit the configuration via the web ui.

More information [here](./docs/configuration.md)
More information [here](https://github.com/withcatai/catai/blob/main/docs/configuration.md)

## Contributing

Expand Down
90 changes: 90 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# CatAI API

CatAI provides multiple APIs to interact with the model.

## Local API

The local API is only available in Node.js.

Enable you to chat with the model locally on your computer.

```ts
import {createChat} from 'catai';

const chat = await createChat();

const response = await catai.prompt('Write me 100 words story', token => {
progress.stdout.write(token);
});

console.log(`Total text length: ${response.length}`);
```

If you want to install the model on the fly, please read the [install-api guide](./install-api.md)

## Remote API

Allowing you to run the model on a remote server.

### Simple API

Node.js & Browser compatible API:

```js
const response = await fetch('http://127.0.0.1:3000/api/chat/prompt', {
method: 'POST',
body: JSON.stringify({
prompt: 'Write me 100 words story'
}),
headers: {
'Content-Type': 'application/json'
}
});

const data = await response.text();
```

<details>
<summary>You can also stream the response</summary>

```js
const response = await fetch('http://127.0.0.1:3000/api/chat/prompt', {
method: 'POST',
body: JSON.stringify({
prompt: 'Write me 100 words story'
}),
headers: {
'Content-Type': 'application/json'
}
});

const reader = response.body.pipeThrough(new TextDecoderStream())
.getReader();

while (true) {
const {value, done} = await reader.read();
if (done) break;
console.log('Received', value);
}
```

</details>

### Advanced API

This API is only available only in Node.js.

```ts
import {RemoteCatAI} from 'catai';
import progress from 'progress-stream';

const catai = new RemoteCatAI('ws://localhost:3000');

const response = await catai.prompt('Write me 100 words story', token => {
progress.stdout.write(token);
});

console.log(`Total text length: ${response.length}`);

catai.close();
```
49 changes: 49 additions & 0 deletions docs/install-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# CatAI Install API

You can install models on the fly using the `FetchModels` class.

```ts
import {FetchModels} from 'catai';

const allModels = await FetchModels.fetchModels();
const firstModel = Object.keys(allModels)[0];

const installModel = new FetchModels({
download: firstModel,
latest: true,
model: {
settings: {
// extra model settings
}
}
});

await installModel.startDownload();
```

After the download is finished, this model will be the active model.

## Configuration

You can change the active model by changing the `CatAIDB`

```ts
import {CatAIDB} from 'catai';

CatAIDB.db.activeModel = Object.keys(CatAIDB.db.models)[0];

await CatAIDB.saveDB();
```

You also can change the model settings by changing the `CatAIDB`

```ts
import {CatAIDB} from 'catai';

const selectedModel = CatAIDB.db.models[CatAIDB.db.activeModel];
selectedModel.settings.context = 4096;

await CatAIDB.saveDB();
```

For extra information about the configuration, please read the [configuration guide](./configuration.md)
46 changes: 0 additions & 46 deletions models.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,4 @@
{
"wizard-vicuna-7b-uncensored-superhot-8k-q4_k_m": {
"download": {
"files": {
"model": "wizard-vicuna-7b-uncensored-superhot-8k.ggmlv3.q4_K_M.bin"
},
"repo": "https://huggingface.co/TheBloke/Wizard-Vicuna-7B-Uncensored-SuperHOT-8K-GGML",
"commit": "6c2a10634ab1c7b5ea9f51a36477f93f1b1eb540",
"branch": "main"
},
"hardwareCompatibility": {
"ramGB": 4.6,
"cpuCors": 3,
"compressions": "q4_K_M"
},
"compatibleCatAIVersionRange": [
"2.0.0"
],
"settings": {
"bind": "node-llama-cpp",
"contextSize": 8192
},
"version": 1
},
"wizard-vicuna-13b-uncensored-superhot-8k-q4_k_m": {
"download": {
"files": {
"model": "wizard-vicuna-13b-uncensored-superhot-8k.ggmlv3.q4_K_M.bin"
},
"repo": "https://huggingface.co/TheBloke/Wizard-Vicuna-13B-Uncensored-SuperHOT-8K-GGML",
"commit": "1ad73d203009ec9ab8894180404f9e9a1ad901c9",
"branch": "main"
},
"hardwareCompatibility": {
"ramGB": 8.4,
"cpuCors": 4,
"compressions": "q4_K_M"
},
"compatibleCatAIVersionRange": [
"2.0.0"
],
"settings": {
"bind": "node-llama-cpp",
"contextSize": 8192
},
"version": 1
},
"lokus-13b-q3_k_s": {
"download": {
"files": {
Expand Down
Loading

0 comments on commit 0789e31

Please sign in to comment.