llama

package
v0.0.0-...-2e34eb7 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultOptions represent neutral parameters for interacting with LLaMA model.
	DefaultOptions = Options{
		ModelPath: "",
		Seed:      0,
		Temp:      1,
		MinP:      0,
	}
)

Functions

func Close

func Close() error

Close releases all resources used by LLM server.

func Complete

func Complete(ctx context.Context, p Prompt) (chan string, error)

Complete returns a channel with completion results for given string.

func Serve

func Serve(ctx context.Context, modelPath string) error

Serve starts LLM server and returns error if it fails. It is the caller's responsibility to close Server.

func SetDefault

func SetDefault(server Server, client Client)

SetDefault sets default Client and Server.

Types

type Client

type Client struct {
	// Addr specifies the address of the LLM server.
	// If empty, "localhost:24114" is used.
	Addr string

	// Options specifies options for underlying LLM server.
	// If nil, DefaultOptions are used.
	Options *Options

	// Logger specifies logger for the client.
	Logger *slog.Logger
}

Client represents client for LLM server.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, p Prompt) (chan string, error)

Complete returns a channel with completion results for given string.

type CmdLogger

type CmdLogger struct {
	// Log specifies an optional logger for exec.Cmd output
	// If nil, logging is done via the slog package's standard logger.
	Log *slog.Logger
}

CmdLogger is a slog.Logger wrapper for exec.Cmd output.

func (*CmdLogger) Write

func (c *CmdLogger) Write(p []byte) (n int, err error)

Write implements io.Writer.

type Options

type Options struct {
	ModelPath string
	Temp      float32
	MinP      float32
	Seed      uint
}

Options represent parameters for interacting with LLaMA model.

func (*Options) Update

func (o *Options) Update(other Options)

Update updates the Options with the non-default values from other Options.

type Prompt

type Prompt struct {
	Format string
	System string
	// contains filtered or unexported fields
}

Prompt represents prompt for the LLM.

func (*Prompt) Add

func (p *Prompt) Add(userPrompt string)

Add adds user prompt to the prompt.

func (*Prompt) String

func (p *Prompt) String() string

String returns prompt string in format specified by Format. If Format is not specified, returns prompt in default format.

type Server

type Server struct {
	// Path specifies a path to LLM server executable.
	// If empty, "./llm-server" is used.
	Path string

	// Addr optionally specifies the TCP address for the server to listen on,
	// in the form "host:port".
	// If empty, "localhost:24114"is used.
	Addr string

	// Cmd specifies a command for underlying LLM server.
	// If nil, the default command is used: `./llm-server --ctx-size 2048`.
	Cmd *exec.Cmd

	// Logger specifies an optional logger for underlying server errors and
	// debug messages.
	// If nil, logging is done to stderr.
	Logger *slog.Logger
}

Server represents LLM server.

func (*Server) Close

func (s *Server) Close() error

Close frees all resources associated with server.

func (*Server) Ping

func (s *Server) Ping() bool

Ping checks if server is running.

func (*Server) Start

func (s *Server) Start(ctx context.Context, modelPath string) error

Start starts LLM server.

It is the caller's responsibility to close Server.

Jump to

Keyboard shortcuts

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