-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: binding for node-llama-cpp (v1) dropped (#43)
- Loading branch information
Showing
18 changed files
with
240 additions
and
973 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.