npm package: @pond918/llm-bots
Description: extendable llm bots sdk to integrate with any system, with tree structured history and conversations support. you can easliy add new own bots under the hood.
Author: pond918
Latest version: 0.0.2

# LLM bots

[![Actions Status](https://github.com/pond918/llm-bots/workflows/ci/badge.svg)](https://github.com/pond918/llm-bots/actions)
[![npm](https://img.shields.io/npm/v/@pond918/llm-bots.svg)](https://www.npmjs.com/package/@pond918/llm-bots)
[![Known Vulnerabilities](https://snyk.io/test/github/pond918/llm-bots/badge.svg?targetFile=package.json)](https://snyk.io/test/github/pond918/llm-bots?targetFile=package.json)
[![prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)
[![license](https://img.shields.io/npm/l/l@pond918/lm-bots.svg)](https://www.npmjs.com/package/@pond918/llm-bots)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpond918%2Fllm-bots.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fpond918%2Fllm-bots?ref=badge_shield)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

## What is it?

An npm package of many large language model (LLMs) client chat bots, e.g. ChatGPT, Bing Chat, bard, Alpaca, Vincuna, Claude, ChatGLM, MOSS, iFlytek Spark, ERNIE and more. You may register your own bots easily.

The package enables bots to support unlimited conversations. each conversation has tree-structured chat history ( each chat message has a `lastMsgId`).

Another use case is to isolate different users for the same bot on the same nodejs server. All user related data: session/conversation/chat history, etc. is stored in the specified BotStorage on different namespaces.

## Getting Started

### Install the library

```sh
npm install --save @pond918/llm-bots
```

### using the bots

```typescript
import { ChatDto, LLMBots } from '@pond918/llm-bots'

const bots = new LLMBots()
const claudeBot = bots.instance('vicuna-13b')
// vicuna-13b needn't token
const token = null
const ready = await claudeBot?.initSession(token)
if (ready) {
  const resp = await claudeBot?.sendPrompt(new ChatDto('hi there. 1 word most'))
  console.log(resp)

  // stream response
  claudeBot?.sendPrompt(new ChatDto('who is Gauss. 5 words most'), (msg) => console.log(msg))
}
```

### register a new bot

```typescript
import { LLMBots } from '@pond918/llm-bots'

// you may apply a custom user data storage
const bots = LLMBots.factory(storage);

// new bot will replace old bot with same name.
bots.register(new MyLLMBot());

const models = LLMBots.list();
console.log(Object.keys(models));
```

## bot state management

There are 3 state for an llm bot instance:

- llm config state: e.g. llm url. Stored as bot class properties.
- server session state: API tokens/login sessions. Stored in the session pool, may be shared among users.
- user data state: conversation/chat history. Stored in the provided storage, usually users isolated.

## TODOs

- [ ] namespaced/scoped storage

## License

This project is [Apache-2.0 Licensed](LICENSE).

## Credits

- bots implementation are based on [ChatAll](https://github.com/sunner/ChatALL). Respect!
- [NodeJS Starter ToolKit](https://github.com/vitorsalgado/create-nodejs-ts)