josStorer / RWKV-Runner

A RWKV management and startup tool, full automation, only 8MB. And provides an interface compatible with the OpenAI API. RWKV is a large language model that is fully open source and available for commercial use.
https://www.rwkv.com
MIT License
5.32k stars 504 forks source link
api api-client chatgpt llm rwkv tool wails

RWKV Runner

This project aims to eliminate the barriers of using large language models by automating everything for you. All you need is a lightweight executable program of just a few megabytes. Additionally, this project provides an interface compatible with the OpenAI API, which means that every ChatGPT client is an RWKV client. [![license][license-image]][license-url] [![release][release-image]][release-url] [![py-version][py-version-image]][py-version-url] English | [简体中文](README_ZH.md) | [日本語](README_JA.md) ### Install [![Windows][Windows-image]][Windows-url] [![MacOS][MacOS-image]][MacOS-url] [![Linux][Linux-image]][Linux-url] [FAQs](https://github.com/josStorer/RWKV-Runner/wiki/FAQs) | [Preview](#Preview) | [Download][download-url] | [Simple Deploy Example](#Simple-Deploy-Example) | [Server Deploy Examples](https://github.com/josStorer/RWKV-Runner/tree/master/deploy-examples) | [MIDI Hardware Input](#MIDI-Input) [license-image]: http://img.shields.io/badge/license-MIT-blue.svg [license-url]: https://github.com/josStorer/RWKV-Runner/blob/master/LICENSE [release-image]: https://img.shields.io/github/release/josStorer/RWKV-Runner.svg [release-url]: https://github.com/josStorer/RWKV-Runner/releases/latest [py-version-image]: https://img.shields.io/pypi/pyversions/fastapi.svg [py-version-url]: https://github.com/josStorer/RWKV-Runner/tree/master/backend-python [download-url]: https://github.com/josStorer/RWKV-Runner/releases [Windows-image]: https://img.shields.io/badge/-Windows-blue?logo=windows [Windows-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/windows/Readme_Install.txt [MacOS-image]: https://img.shields.io/badge/-MacOS-black?logo=apple [MacOS-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/darwin/Readme_Install.txt [Linux-image]: https://img.shields.io/badge/-Linux-black?logo=linux [Linux-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/linux/Readme_Install.txt

Tips

Features

Simple Deploy Example

git clone https://github.com/josStorer/RWKV-Runner

# Then
cd RWKV-Runner
python ./backend-python/main.py #The backend inference service has been started, request /switch-model API to load the model, refer to the API documentation: http://127.0.0.1:8000/docs

# Or
cd RWKV-Runner/frontend
npm ci
npm run build #Compile the frontend
cd ..
python ./backend-python/webui_server.py #Start the frontend service separately
# Or
python ./backend-python/main.py --webui #Start the frontend and backend service at the same time

# Help Info
python ./backend-python/main.py -h

API Concurrency Stress Testing

ab -p body.json -T application/json -c 20 -n 100 -l http://127.0.0.1:8000/chat/completions

body.json:

{
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ]
}

Embeddings API Example

Note: v1.4.0 has improved the quality of embeddings API. The generated results are not compatible with previous versions. If you are using embeddings API to generate knowledge bases or similar, please regenerate.

If you are using langchain, just use OpenAIEmbeddings(openai_api_base="http://127.0.0.1:8000", openai_api_key="sk-")

import numpy as np
import requests

def cosine_similarity(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))

values = [
    "I am a girl",
    "我是个女孩",
    "私は女の子です",
    "广东人爱吃福建人",
    "我是个人类",
    "I am a human",
    "that dog is so cute",
    "私はねこむすめです、にゃん♪",
    "宇宙级特大事件!号外号外!"
]

embeddings = []
for v in values:
    r = requests.post("http://127.0.0.1:8000/embeddings", json={"input": v})
    embedding = r.json()["data"][0]["embedding"]
    embeddings.append(embedding)

compared_embedding = embeddings[0]

embeddings_cos_sim = [cosine_similarity(compared_embedding, e) for e in embeddings]

for i in np.argsort(embeddings_cos_sim)[::-1]:
    print(f"{embeddings_cos_sim[i]:.10f} - {values[i]}")

MIDI Input

Tip: You can download https://github.com/josStorer/sgm_plus and unzip it to the program's assets/sound-font directory to use it as an offline sound source. Please note that if you are compiling the program from source code, do not place it in the source code directory.

If you don't have a MIDI keyboard, you can use virtual MIDI input software like Virtual Midi Controller 3 LE, along with loopMIDI, to use a regular computer keyboard as MIDI input.

USB MIDI Connection

Mac MIDI Bluetooth Connection

Windows MIDI Bluetooth Connection

Related Repositories:

Preview

Homepage

image

Chat

image

image

Completion

image

Composition

Tip: You can download https://github.com/josStorer/sgm_plus and unzip it to the program's assets/sound-font directory to use it as an offline sound source. Please note that if you are compiling the program from source code, do not place it in the source code directory.

image

image

Configuration

image

Model Management

image

Download Management

image

LoRA Finetune

image

Settings

image