A go wrapper around the rwkv.cpp library

AI without python (1)

Go Reference go-rwkv.cpp

gowrkv.go is a wrapper around rwkv-cpp, which is an adaption of ggml.cpp.

(1) Python required for training and converting the models into the correct format.

Features

rkwv.cpp is generally faster, due to keeping the intermediate state of the model, so the entire prompt doesn't have to be reprocessed every time. For more details, see rwkv-cpp.

Also, the available models for rwkv.cpp are fully open-source, unlike llama. You can use these models commercially, and you can modify them to your heart's content.

Training may also be faster, I haven't had a chance to try that yet.

Installation

Installation is currently complex. go-rkwv.cpp does not work with go get yet (patches very welcome). You will need go, a c++ compiler(clang on Mac), and cmake.

Download

You must clone this repo /recursively/, as it contains submodules.

    git clone --recursive https://github.com/donomii/go-rwkv.cpp

Building

There is a build script, build.sh, which will build the c++ library and the go wrapper. Please file bug reports if it doesn't work for you.

    ./build-mac.sh

There is now an alternate build, which builds statically thanks to a makefile provided by @mudler.

    make example/ai

Download models

The download script will download some models, and convert them to the correct format.

    ./download_models.sh

Install

go-rwkv.cpp currently builds against the dynamic library librwkv.dylib. This is not ideal, but it works for now. You will need to copy this library to a location where the system linker can find it. On Mac, this is /usr/local/lib.

    cp librwkv.dylib /usr/local/lib

If you don't want to install it globally, you can set the DYLD_LIBRARY_PATH environment variable to the directory containing librwkv.dylib.

Use

See the example/ directory for a full working chat program. The following is a minimal example.

    package main

    import (
        "fmt"
        "github.com/donomii/go-rwkv.cpp"
    )

    func main() {
        model := LoadFiles("aimodels/small.bin", "rwkv.cpp/rwkv/20B_tokenizer.json", 8)
    model.ProcessInput("You are a chatbot that is very good at chatting.  blah blah blah")
    response := model.Generate(100, "\n")
    fmt.Println(response)

    }

You must use the tokenizer file from rwkv.cpp. go-rwkv contains a re-implementation of the tokenizer, but it is a minimal implementation that contains just enough code to work with rwkv (and there are probably bugs in it).

Packaging

To ship a working program that includes this AI, you will need to include the following files:

  • librwkv.dylib
  • the model file (e.g. RWKV-4-Raven-1B5-v9-Eng99%-Other1%-20230411-ctx4096_quant4.bin)
  • the tokenizer file (i.e. 20B_tokenizer.json)

If you don't install librwkv.dylib globally, you will need to set the DYLD_LIBRARY_PATH environment variable to the directory containing librwkv.dylib.

License

This program is licensed under the MIT license. See LICENSE for details.

As far as I am aware, the Raven models are also open source.

Similar Resources

800k lines switch case cpp challenge

800k lines switch case cpp challenge

800k lines cpp compile challenge 80万行cpp编译挑战 800k lines cpp 编译 challenge generate 生成Cpp代码 go run generator.go compile 编译Cpp代码 g++ -m64 main.cpp binary

Oct 27, 2021

go2cpp : convert go to cpp using go ast

px_golang2cpp convert go to cpp convert map to std::unordered_map convert array to vector convert 'var test bool' to 'bool test{}' convert 'var test =

Oct 30, 2022

goxml - A thin wrapper around libxml2

golibxml golibxml is a simple wrapper for libxml. The goal is to avoid any extra magic so that a more friendly library can be written to sit on top of

Oct 25, 2020

A simple wrapper around sql.DB to help with structs. Not quite an ORM.

go-modeldb A simple wrapper around sql.DB to help with structs. Not quite an ORM. Philosophy: Don't make an ORM Example: // Setup require "modeldb" db

Nov 16, 2019

Go wrapper around the Iup GUI toolset

Iup Go Wrapper iup is a Go wrapper around the Iup GUI toolkit. The project was started on April 27, 2011. Fork https://github.com/grd/iup is a fork of

Nov 28, 2020

A simple wrapper around libpcap for the Go programming language

PCAP This is a simple wrapper around libpcap for Go. Originally written by Andreas Krennmair [email protected] and only minorly touched up by Mark Smith

Dec 5, 2022

A tiny wrapper around NSQ topic and channel :rocket:

Event Bus NSQ A tiny wrapper around go-nsq topic and channel. Protect nsq calls with gobreaker. Installation go get -u github.com/rafaeljesus/nsq-even

Sep 27, 2022

Package set is a small wrapper around the official reflect package that facilitates loose type conversion and assignment into native Go types.

Package set is a small wrapper around the official reflect package that facilitates loose type conversion and assignment into native Go types. Read th

Dec 27, 2022

A wrapper around cd and xdg-open to use aliases to directory paths in terminal

CDD - Change directories Dynamically I am a lazy linux user and turns out that basic tab completion wasn't enough for me to navigate through my direct

Dec 15, 2022

Convenience wrapper around "go test" + "benchstat".

go-benchrun Convenience wrapper around "go test" + benchstat. Run benchmarking in 1 simple command. Installation & Quick start This install go-benchru

Jul 13, 2022

a simple wrapper around resty to report HTTP calls metrics to prometheus

restyprom a simple wrapper around resty to report HTTP calls metrics to prometheus If you're using resty and want to have metrics of your HTTP calls,

Sep 25, 2022

The NVD API is an unofficial Go wrapper around the NVD API.

NVD API The NVD API is an unofficial Go wrapper around the NVD API. Supports: CVE CPE How to use The following shows how to basically use the wrapper

Jan 7, 2023

Unofficial but convenient Go wrapper around the NVD API

NVD API The NVD API is an unofficial Go wrapper around the NVD API. Supports: CVE CPE How to use The following shows how to basically use the wrapper

Nov 1, 2021

Go wrapper around Device Console Windows tool.

go-devcon Go wrapper around the Windows Device Console (devcon.exe). go install github.com/mikerourke/go-devcon Introduction Here's a brief overview

Nov 4, 2021

A Go wrapper around the Notion API

go-notion A Go wrapper around the Notion API. | ⚠ This package is new and under active development. How to Use Install the package go get github.com/b

Nov 19, 2021

Testing the use of a golang wrapper around UserMode Linux for making stdin

This code is for testing the use of a golang wrapper around UserMode Linux for making stdin, stdout and stderr available to attach, detach and reattach to from the host using Unix sockets.

Dec 24, 2021

A dead simple Go wrapper around the hidden moonarch.app API.

moonarch A dead simple Go wrapper around the hidden moonarch.app API. How-To First, get the repository: go get github.com/lazdotdigital/moonarch. moon

Nov 27, 2021

Simple wrapper around multiple fs.FS instances, recursively merging them together dynamically.

go-layerfs This is a simple wrapper around multiple fs.FS instances, recursively merging them together dynamically. If you have two directories, of wh

Aug 9, 2022

A neat wrapper around the 4chan API for content scraping.

moonarch A neat wrapper around the 4chan API for content scraping. How-To First, get the repository: go get github.com/lazdotdigital/fourscrape. fours

Nov 27, 2021
Comments
  • minor enhancements

    minor enhancements

    Hey @donomii :wave:

    Awesome work! I was about to write a binding myself but then met this project - kudos!

    I've added a Makefile to build the example statically (so no need to carry shared libraries around), added a go.mod file and adapted examples.

    Introduced also a tokenCallback to get unbuffered output from the prediction - a bit of context: I'm planning to use this library in https://github.com/go-skynet/LocalAI/ which supports stream of tokens, so I really need this in - hoping the change is welcome!

    Cheers!

  • Bump rwkv.cpp from `5eb8f09` to `a3178b2`

    Bump rwkv.cpp from `5eb8f09` to `a3178b2`

    Bumps rwkv.cpp from 5eb8f09 to a3178b2.

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Resilient wrapper around Go http.Client that uses exponential backoff and jitter for retries.

Hardy Hardy is a very simple wrapper around http.Client that enables you to add more resilience and reliability for your HTTP calls through retries. A

Dec 29, 2022
Simple Notifier/Listener utility package to pass around messages in-memory

Simple Observer (go) A small simple library to use for sending around messages in-memory. It uses a notifier/listener style messaging. Installation go

Dec 7, 2021
An experimental generic functional utility library inspired by Lodash

go-godash An experimental generic functional utility library inspired by Lodash Implemented functions Map Reduce Sum Filter Take TakeWhile Drop DropWh

May 31, 2022
Goro: A High-level Machine Learning Library for Go
Goro: A High-level Machine Learning Library for Go

Overview Goro is a high-level machine learning library for Go built on Gorgonia. It aims to have the same feel as Keras. Usage import ( . "github.

Nov 20, 2022
A library providing useful functional programming helpers for Go 1.18

Underscore underscore is a Go library providing useful functional programming helpers without extending any built-in objects. It is mostly a port from

Dec 29, 2022
Clarifai - Clarifai library for Golang

Clarifai Golang Library Library for our v1 API. Disclaimer This API client only

Sep 27, 2022
Go-openoffice - Go library for reading OpenOffice odf and ods files

go-openoffice A Go library for reading OpenOffice/LibreOffice .ods (and .odf) fi

Dec 16, 2022
Go-integrals - A numerical integration library in GoLang

Go Integrals About Go Integrals is an implementation of numerical integration al

Jan 19, 2022
`go-redash-query` is a simple library to get structed data from `redash query` sources

go-redash-query go-redash-query is a simple library to get structed data from redash query sources Example Source table id name email 1 Dannyhann rhrn

May 22, 2022
Golang->Haxe->CPP/CSharp/Java/JavaScript transpiler

TARDIS Go -> Haxe transpiler Haxe -> C++ / C# / Java / JavaScript Project status: a non-working curiosity, development currently on-ice The advent of

Dec 30, 2022