0.4.242 • Published 1 month ago

llmatic v0.4.242

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

LLMatic

Use self-hosted LLMs with an OpenAI compatible API

Project status

This project was the result of my curiousity and experimentation with OpenAI's API and I enjoyed building it. It is certainly not the first nor the last project of its kind. Given my limited time and resources, I'd like to pause the development of this project for now. I'll list some other similar projects below that can be used as alternatives:

  1. Ollama
  2. LLaMA.cpp HTTP Server
  3. GPT4All Chat Server Mode
  4. FastChat

Synopsis

LLMatic can be used as a drop-in replacement for OpenAI's API v1.2.0 (see the supported endpoints). By default, it uses llama-node with llama.cpp backend to run the models locally. However, you can easily create your own adapter to use any other model or service.

Supported endpoints:

  • /completions (stream and non-stream)
  • /chat/completions (stream and non-stream)
  • /embeddings
  • /models

How to use

If you prefer a video tutorial, you can watch the following video for step-by-step instructions on how to use this project:

Requirements

  • Node.js >=18.16
  • Unix-based OS (Linux, macOS, WSL, etc.)

Installation

Create an empty directory and run npm init:

export LLMATIC_PROJECT_DIR=my-llmatic-project
mkdir $LLMATIC_PROJECT_DIR
cd $LLMATIC_PROJECT_DIR
npm init -y

Install and configure LLMatic:

npm add llmatic
# Download a model and generate a config file
npx llmatic config

Adjust the config file to your needs and start the server:

npx llmatic start

You can run llmatic --help to see all available commands.

Usage with chatbot-ui

Clone the repo and install the dependencies:

git clone https://github.com/mckaywrigley/chatbot-ui.git
cd chatbot-ui
npm install

Create a .env.local file:

cat <<EOF > .env.local
# For now, this is ignored by LLMatic
DEFAULT_MODEL=Ignored

NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT=A chat between a curious human (user) and an artificial intelligence assistant (assistant). The assistant gives helpful, detailed, and polite answers to the human's questions.

user: Hello!
assistant: Hello! How may I help you today?
user: Please tell me the largest city in Europe.
assistant: Sure. The largest city in Europe is Moscow, the capital of Russia.

OPENAI_API_KEY=ANYTHING_WILL_DO
OPENAI_API_HOST=http://localhost:3000

GOOGLE_API_KEY=YOUR_API_KEY
GOOGLE_CSE_ID=YOUR_ENGINE_ID
EOF

Run the server:

npm run dev -- --port 3001

Demo:

chatbot-ui Demo

Usage with LangChain

There are two examples of using LLMatic with LangChain in the examples directory.

To run the Node.js example, first install the dependencies:

cd examples/node-langchain
npm install

Then run the main script:

npm start
[chain/start] [1:chain:llm_chain] Entering Chain run with input: {
  "humanInput": "Rememeber that this is a demo of LLMatic with LangChain.",
  "history": ""
}
[llm/start] [1:chain:llm_chain > 2:llm:openai] Entering LLM run with input: {
  "prompts": [
    "A chat between a curious user and an artificial intelligence assistant.\nThe assistant gives helpful, detailed, and polite answers to the user's questions.\n\n\nHuman: Rememeber that this is a demo of LLMatic with LangChain.\nAI:"
  ]
}
[llm/end] [1:chain:llm_chain > 2:llm:openai] [5.92s] Exiting LLM run with output: {
  "generations": [
    [
      {
        "text": " Yes, I understand. I am ready to assist you with your queries.",
        "generationInfo": {
          "finishReason": "stop",
          "logprobs": null
        }
      }
    ]
  ],
  "llmOutput": {
    "tokenUsage": {}
  }
}
[chain/end] [1:chain:llm_chain] [5.92s] Exiting Chain run with output: {
  "text": " Yes, I understand. I am ready to assist you with your queries."
}
[chain/start] [1:chain:llm_chain] Entering Chain run with input: {
  "humanInput": "What did I ask you to remember?",
  "history": "Human: Rememeber that this is a demo of LLMatic with LangChain.\nAI:  Yes, I understand. I am ready to assist you with your queries."
}
[llm/start] [1:chain:llm_chain > 2:llm:openai] Entering LLM run with input: {
  "prompts": [
    "A chat between a curious user and an artificial intelligence assistant.\nThe assistant gives helpful, detailed, and polite answers to the user's questions.\n\nHuman: Rememeber that this is a demo of LLMatic with LangChain.\nAI:  Yes, I understand. I am ready to assist you with your queries.\nHuman: What did I ask you to remember?\nAI:"
  ]
}
[llm/end] [1:chain:llm_chain > 2:llm:openai] [6.51s] Exiting LLM run with output: {
  "generations": [
    [
      {
        "text": " You asked me to remember that this is a demo of LLMatic with LangChain.",
        "generationInfo": {
          "finishReason": "stop",
          "logprobs": null
        }
      }
    ]
  ],
  "llmOutput": {
    "tokenUsage": {}
  }
}
[chain/end] [1:chain:llm_chain] [6.51s] Exiting Chain run with output: {
  "text": " You asked me to remember that this is a demo of LLMatic with LangChain."
}

To run the Python example, first install the dependencies:

cd examples/python-langchain
pip3 install -r requirements.txt

Then run the main script:

python3 main.py
> Entering new LLMChain chain...
Prompt after formatting:
A chat between a curious user and an artificial intelligence assistant.
The assistant gives helpful, detailed, and polite answers to the user's questions.


Human: Rememeber that this is a demo of LLMatic with LangChain.
AI:

> Finished chain.
 Yes, I understand. I am ready to assist you with your queries.


> Entering new LLMChain chain...
Prompt after formatting:
A chat between a curious user and an artificial intelligence assistant.
The assistant gives helpful, detailed, and polite answers to the user's questions.

Human: Rememeber that this is a demo of LLMatic with LangChain.
AI:  Yes, I understand. I am ready to assist you with your queries.
Human: What did I ask you to remember?
AI:

> Finished chain.
 You asked me to remember that this is a demo of LLMatic with LangChain.

Custom Adapters

LLMatic is designed to be easily extensible. You can create your own adapters by extending the LlmAdapter class. See examples/custom-adapter for an example.

To start llmatic with a custom adapter, use the --llm-adapter flag:

llmatic start --llm-adapter ./custom-llm-adapter.ts
0.4.242

1 month ago

0.4.241

1 month ago

0.4.240

1 month ago

0.4.239

1 month ago

0.4.238

1 month ago

0.4.237

1 month ago

0.4.236

1 month ago

0.4.235

1 month ago

0.4.234

1 month ago

0.4.233

2 months ago

0.4.230

2 months ago

0.4.232

2 months ago

0.4.231

2 months ago

0.4.229

2 months ago

0.4.228

2 months ago

0.4.227

2 months ago

0.4.226

2 months ago

0.4.225

2 months ago

0.4.224

2 months ago

0.4.223

2 months ago

0.4.222

2 months ago

0.4.221

2 months ago

0.4.219

2 months ago

0.4.220

2 months ago

0.4.218

2 months ago

0.4.217

2 months ago

0.4.216

2 months ago

0.4.215

2 months ago

0.4.214

2 months ago

0.4.213

3 months ago

0.4.212

3 months ago

0.4.211

3 months ago

0.4.209

3 months ago

0.4.210

3 months ago

0.4.208

3 months ago

0.4.207

3 months ago

0.4.206

3 months ago

0.4.205

3 months ago

0.4.204

3 months ago

0.4.202

3 months ago

0.4.201

3 months ago

0.4.199

3 months ago

0.4.200

3 months ago

0.4.198

3 months ago

0.4.197

3 months ago

0.4.193

3 months ago

0.4.196

3 months ago

0.4.195

3 months ago

0.4.194

3 months ago

0.4.192

3 months ago

0.4.191

3 months ago

0.4.190

3 months ago

0.4.189

3 months ago

0.4.188

4 months ago

0.4.187

4 months ago

0.4.186

4 months ago

0.4.185

4 months ago

0.4.184

4 months ago

0.4.183

4 months ago

0.4.182

4 months ago

0.4.181

4 months ago

0.4.177

4 months ago

0.4.176

4 months ago

0.4.175

4 months ago

0.4.174

4 months ago

0.4.173

4 months ago

0.4.172

4 months ago

0.4.171

4 months ago

0.4.170

5 months ago

0.4.169

5 months ago

0.4.168

5 months ago

0.4.167

5 months ago

0.4.166

5 months ago

0.4.165

5 months ago

0.4.164

5 months ago

0.4.163

5 months ago

0.4.162

5 months ago

0.4.161

5 months ago

0.4.160

5 months ago

0.4.142

6 months ago

0.4.141

6 months ago

0.4.146

6 months ago

0.4.145

6 months ago

0.4.144

6 months ago

0.4.143

6 months ago

0.4.149

5 months ago

0.4.148

5 months ago

0.4.147

6 months ago

0.4.153

5 months ago

0.4.152

5 months ago

0.4.151

5 months ago

0.4.150

5 months ago

0.4.157

5 months ago

0.4.156

5 months ago

0.4.155

5 months ago

0.4.154

5 months ago

0.4.159

5 months ago

0.4.158

5 months ago

0.4.140

6 months ago

0.4.129

6 months ago

0.4.131

6 months ago

0.4.130

6 months ago

0.4.135

6 months ago

0.4.134

6 months ago

0.4.133

6 months ago

0.4.132

6 months ago

0.4.139

6 months ago

0.4.138

6 months ago

0.4.137

6 months ago

0.4.136

6 months ago

0.4.119

7 months ago

0.4.118

7 months ago

0.4.120

7 months ago

0.4.124

7 months ago

0.4.123

7 months ago

0.4.122

7 months ago

0.4.121

7 months ago

0.4.128

6 months ago

0.4.127

6 months ago

0.4.126

6 months ago

0.4.125

7 months ago

0.4.97

8 months ago

0.4.109

7 months ago

0.4.98

8 months ago

0.4.108

7 months ago

0.4.95

8 months ago

0.4.107

7 months ago

0.4.96

8 months ago

0.4.93

8 months ago

0.4.94

8 months ago

0.4.91

8 months ago

0.4.92

8 months ago

0.4.99

8 months ago

0.4.113

7 months ago

0.4.112

7 months ago

0.4.90

8 months ago

0.4.111

7 months ago

0.4.110

7 months ago

0.4.117

7 months ago

0.4.116

7 months ago

0.4.115

7 months ago

0.4.114

7 months ago

0.4.101

7 months ago

0.4.100

7 months ago

0.4.106

7 months ago

0.4.105

7 months ago

0.4.86

8 months ago

0.4.87

8 months ago

0.4.84

8 months ago

0.4.85

8 months ago

0.4.82

8 months ago

0.4.83

8 months ago

0.4.80

8 months ago

0.4.81

8 months ago

0.4.88

8 months ago

0.4.89

8 months ago

0.4.79

8 months ago

0.4.77

8 months ago

0.4.78

8 months ago

0.4.76

8 months ago

0.4.75

8 months ago

0.4.74

8 months ago

0.4.73

8 months ago

0.4.72

9 months ago

0.4.71

9 months ago

0.4.70

9 months ago

0.4.69

9 months ago

0.4.68

9 months ago

0.4.67

9 months ago

0.4.66

9 months ago

0.4.65

9 months ago

0.4.64

9 months ago

0.4.63

9 months ago

0.4.62

9 months ago

0.4.61

9 months ago

0.4.60

9 months ago

0.4.59

9 months ago

0.4.58

9 months ago

0.4.57

9 months ago

0.4.56

9 months ago

0.4.55

9 months ago

0.4.54

9 months ago

0.4.53

9 months ago

0.4.52

9 months ago

0.4.51

9 months ago

0.4.50

10 months ago

0.4.49

10 months ago

0.4.48

10 months ago

0.4.47

10 months ago

0.4.46

10 months ago

0.4.45

10 months ago

0.4.44

10 months ago

0.4.41

10 months ago

0.4.40

10 months ago

0.4.39

10 months ago

0.4.38

10 months ago

0.4.36

10 months ago

0.4.35

10 months ago

0.4.34

10 months ago

0.4.33

10 months ago

0.4.32

10 months ago

0.4.31

10 months ago

0.4.30

10 months ago

0.4.29

10 months ago

0.4.28

11 months ago

0.4.27

11 months ago

0.4.26

11 months ago

0.4.25

11 months ago

0.4.24

11 months ago

0.4.23

11 months ago

0.4.22

11 months ago

0.4.21

11 months ago

0.4.20

11 months ago

0.4.19

11 months ago

0.4.18

11 months ago

0.4.17

11 months ago

0.4.16

11 months ago

0.4.15

11 months ago

0.4.14

11 months ago

0.4.13

11 months ago

0.4.12

11 months ago

0.4.11

11 months ago

0.4.10

11 months ago

0.4.9

11 months ago

0.4.8

11 months ago

0.4.7

11 months ago

0.4.6

11 months ago

0.4.4

11 months ago

0.4.3

11 months ago

0.4.2

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.3.1

12 months ago

0.3.0

12 months ago

0.2.1

12 months ago

0.2.0

12 months ago