A rusty interface to llama.cpp for rust

Overview

llama-cpp-rs

Higher level API for the llama-cpp-sys library here: https://github.com/shadowmint/llama-cpp-sys/

A full end-to-end example can be found here: https://github.com/shadowmint/llama-coo-rs/tree/main/example

Usage

See the tests folder, or the example folder for an end-to-end example.

Basic usage is:

use llama_cpp_rs::{
    LContext, LContextConfig, LGenerator, LGeneratorParams, LSampleParams, LToken, LTokenSequence,
};

pub fn main() {
    // Setup params
    let mut config = LContextConfig::new("models/13B/model.bin");
    config.n_ctx = 512;
    config.seed = 0;

    // Load model
    let mut context = LContext::new(config).unwrap();

    // Create a generator
    let mut generator = LGenerator::new(context);
    
    // Run the generator
    let prompt = "... whatever... ";
    let output = generator
        .generate(
            prompt,
            LGeneratorParams {
                worker_thread_count: 8,
                prediction_window_length: 64,
                generate_tokens: 256,
                sample_params: LSampleParams {
                    top_k: 40,
                    top_p: 0.95f32,
                    temp: 0.8f32,
                    repeat_penalty: 1.1f32,
                },
            },
        )
        .unwrap();
        
    println!("{}", output);
}

Input:

bob is a space pilot. Alice is a potato.
This is a conversation between bob and alice:

Output:

ALICE: I am Alice the potato!
BOB: I'm Bob the space pirate!
ALICE: Why are you a space pirate?
BOB: Because I want to fly through space!
ALICE: I want to be made into chips!
BOB: What do you want to talk about?
ALICE: Well, I am Alice the potato.
BOB: I'm Bob the space pirate!

For lower level interactions with the library, see the tests.

Run example

Put your models in the models folder; the test expects a file in the path:

models/13B/model.bin

You can then generate using

cargo test --release --test "test_api" -- --nocapture

Or:

cargo test --release --test "test_generator" -- --nocapture

Running outside of release mode will be significantly slower.

You might also like...
COINGATOR: a statistical rusty searcher 𝗢𝗻 π—Ώπ˜‚π˜€π˜
COINGATOR: a statistical rusty searcher 𝗢𝗻 π—Ώπ˜‚π˜€π˜

🐊 πŸ€– COINGATOR: a statistical rusty searcher πŸ‘Ύ ✨ (need to commit the rest of this work: i will add everything when i am back from vacation) tl; dr ?

A Rust client for the NOAA Weather Wire Service Open Interface.

nwws-oi A Rust client for the NOAA Weather Wire Service Open Interface. NWWS-OI is one of several platforms through which the National Weather Service

A little command-line script written in Rust to interface with Discord webhooks.

Rust Discord Webhook Agent This is a little "script" I wrote for practice with Rust and asynchronous operations within Rust. Getting started Clone thi

GGML bindings that aim to be idiomatic Rust rather than directly corresponding to the C/C++ interface

rusty-ggml GGML bindings that aim to be idiomatic Rust rather than directly corresponding to the C/C++ interface. GG-what? See: https://github.com/gge

This is a simple Telegram bot with interface to Firefly III to process and store simple transactions.
This is a simple Telegram bot with interface to Firefly III to process and store simple transactions.

Firefly Telegram Bot Fireflies are free, so beautiful. (Les lucioles sont libres, donc belles.) ― Charles de Leusse, Les Contes de la nuit This is a s

01 Solana program application interface.

01 abi The abi is a repository for interfacing with the 01 program either through a rust client or through CPIs from another Solana program. Program A

cqlsh-rs is a command-line interface for interacting with Cassandra using CQL

cqlsh-rs is a command-line interface for interacting with Cassandra using CQL (the Cassandra Query Language). Originally shipped with every Cassandra package and implemented in Python 2, this tool is reimplemented in Rust.

First Git on Rust is reimplementation with rust in order to learn about rust, c and git.

First Git on Rust First Git on Rust is reimplementation with rust in order to learn about rust, c and git. Reference project This project refer to the

A stupid macro that compiles and executes Rust and spits the output directly into your Rust code

inline-rust This is a stupid macro inspired by inline-python that compiles and executes Rust and spits the output directly into your Rust code. There

Comments
  • About crate name

    About crate name

    if i attempt to port your binding to nodejs but still keep original llama-rs crate in pure rust. how should i solve package naming conflict.

    would it be better if you rename this to llama-binding or something else to clarify its a different libs compared to llama-rs?

    opened by hlhr202 2
Owner
Doug
bing.
Doug
High-level, optionally asynchronous Rust bindings to llama.cpp

llama_cpp-rs Safe, high-level Rust bindings to the C++ project of the same name, meant to be as user-friendly as possible. Run GGUF-based large langua

Binedge.ai 4 Nov 21, 2023
A Discord bot, written in Rust, that generates responses using the LLaMA language model.

llamacord A Discord bot, written in Rust, that generates responses using the LLaMA language model. Built on top of llama-rs. Setup Model Obtain the LL

Philpax 6 Mar 20, 2023
A Discord bot, written in Rust, that generates responses using the LLaMA language model.

llamacord A Discord bot, written in Rust, that generates responses using the LLaMA language model. Built on top of llama-rs. Setup Model Obtain the LL

Rustformers 18 Apr 9, 2023
Run LLaMA inference on CPU, with Rust πŸ¦€πŸš€πŸ¦™

LLaMA-rs Do the LLaMA thing, but now in Rust ?? ?? ?? Image by @darthdeus, using Stable Diffusion LLaMA-rs is a Rust port of the llama.cpp project. Th

Rustformers 2.7k Apr 17, 2023
Run LLaMA inference on CPU, with Rust πŸ¦€πŸš€πŸ¦™

LLaMA-rs Do the LLaMA thing, but now in Rust ?? ?? ?? Image by @darthdeus, using Stable Diffusion LLaMA-rs is a Rust port of the llama.cpp project. Th

Rustformers 2.7k Apr 17, 2023
A mimimal Rust implementation of Llama.c

llama2.rs Rust meets llama. A mimimal Rust implementation of karpathy's llama.c. Currently the code uses the 15M parameter model provided by Karpathy

null 6 Aug 8, 2023
OpenAI compatible API for serving LLAMA-2 model

Cria - Local llama OpenAI-compatible API The objective is to serve a local llama-2 model by mimicking an OpenAI API service. The llama2 model runs on

AmineDiro 66 Aug 8, 2023
A highly modular Bitcoin Lightning library written in Rust. Its Rust-Lightning, not Rusty's Lightning!

Rust-Lightning is a Bitcoin Lightning library written in Rust. The main crate, lightning, does not handle networking, persistence, or any other I/O. Thus, it is runtime-agnostic, but users must implement basic networking logic, chain interactions, and disk storage. More information is available in the About section.

Lightning Dev Kit 850 Jan 3, 2023
Rusty Reflective DLL Injection - A small reflective loader in Rust 4KB in size

Reflective Loader in Rust (4KB in size) A small reflective loader PoC in Rust. I remade this from my old project (https://github.com/memN0ps/arsenal-r

null 97 Apr 8, 2023
Rusty Ray Tracer

rtrtr - Rusty Ray Tracer Cameron Christensen - Fall 2021 -- I started this both to brush up on ray tracing and to learn Rust. For the former I've been

Cameron Christensen 2 Nov 5, 2021