llama

package module
v0.0.0-...-6692d06 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2023 License: MIT Imports: 13 Imported by: 0

README

go-llama.cpp

LLama.cpp golang bindings

Clone the repository locally:

git clone --recurse-submodules https://github.com/go-skynet/go-llama.cpp

To build the bindings locally, run:

cd go-llama.cpp
make libbinding.a

Then you can run the example with:

LIBRARY_PATH=$PWD C_INCLUDE_PATH=$PWD go run ./examples -m "/model/path/here" -t 14

Enjoy!

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Install

func Install()

func InstallCuda

func InstallCuda()

func LlaMA_allocate_params

func LlaMA_allocate_params(version string, input string, seed int, threads int, tokens int, topK int, topP float64, temperature float64, penalty float64, repeat int, ignoreEOS bool, f16KV bool, batch int) easycgo.ValueInf

func LlaMA_free_model

func LlaMA_free_model(version string, p easycgo.ValueInf)

func LlaMA_free_params

func LlaMA_free_params(version string, p easycgo.ValueInf)

func LlaMA_load_model

func LlaMA_load_model(version string, modelPath string, contextSize int, parts int, seed int, f16Memory bool, mLock bool, nGPULayers int) easycgo.ValueInf

func LlaMA_predict

func LlaMA_predict(version string, p easycgo.ValueInf, model easycgo.ValueInf) int

func LoadDll

func LoadDll(dllFile string, version string)

Types

type LLama

type LLama struct {
	// contains filtered or unexported fields
}

func New

func New(model string, opts ...ModelOption) (*LLama, error)

func (*LLama) Free

func (l *LLama) Free()

func (*LLama) Predict

func (l *LLama) Predict(text string, opts ...PredictOption) (string, error)

type ModelOption

type ModelOption func(p *ModelOptions)
var EnableF16Memory ModelOption = func(p *ModelOptions) {
	p.F16Memory = true
}
var EnableMLock ModelOption = func(p *ModelOptions) {
	p.MLock = true
}

func SetContext

func SetContext(c int) ModelOption

SetContext sets the context size.

func SetModelSeed

func SetModelSeed(c int) ModelOption

func SetNGPULayers

func SetNGPULayers(c int) ModelOption

func SetParts

func SetParts(c int) ModelOption

type ModelOptions

type ModelOptions struct {
	ContextSize int
	Parts       int
	Seed        int
	F16Memory   bool
	MLock       bool
	NGPULayers  int
}
var DefaultModelOptions ModelOptions = ModelOptions{
	ContextSize: 512,
	Seed:        0,
	F16Memory:   false,
	MLock:       false,
	NGPULayers:  0,
}

func NewModelOptions

func NewModelOptions(opts ...ModelOption) ModelOptions

Create a new PredictOptions object with the given options.

type PredictOption

type PredictOption func(p *PredictOptions)
var EnableF16KV PredictOption = func(p *PredictOptions) {
	p.F16KV = true
}
var IgnoreEOS PredictOption = func(p *PredictOptions) {
	p.IgnoreEOS = true
}

func SetBatchSize

func SetBatchSize(batchSize int) PredictOption

func SetPenalty

func SetPenalty(penalty float64) PredictOption

SetPenalty sets the repetition penalty for text generation.

func SetRepeat

func SetRepeat(repeat int) PredictOption

SetRepeat sets the number of times to repeat text generation.

func SetSeed

func SetSeed(seed int) PredictOption

SetSeed sets the random seed for sampling text generation.

func SetStreamFn

func SetStreamFn(stream func(outputText string) (stop bool)) PredictOption

SetStreamFn sets the stream callback for text generation.

func SetTemperature

func SetTemperature(temp float64) PredictOption

SetTemperature sets the temperature value for text generation.

func SetThreads

func SetThreads(threads int) PredictOption

SetThreads sets the number of threads to use for text generation.

func SetTokens

func SetTokens(tokens int) PredictOption

SetTokens sets the number of tokens to generate.

func SetTopK

func SetTopK(topk int) PredictOption

SetTopK sets the value for top-K sampling.

func SetTopP

func SetTopP(topp float64) PredictOption

SetTopP sets the value for nucleus sampling.

type PredictOptions

type PredictOptions struct {
	Seed, Threads, Tokens, TopK, Repeat int
	TopP, Temperature, Penalty          float64
	F16KV                               bool
	BatchSize                           int
	IgnoreEOS                           bool
	Stream                              func(outputText string) (stop bool)
}
var DefaultOptions PredictOptions = PredictOptions{
	Seed:        -1,
	Threads:     defaultThreadNum,
	Tokens:      128,
	TopK:        10000,
	TopP:        0.7,
	Temperature: 0.7,
	Penalty:     1,
	Repeat:      64 * 4,
}

func NewPredictOptions

func NewPredictOptions(opts ...PredictOption) PredictOptions

Create a new PredictOptions object with the given options.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL