Documentation
¶
Overview ¶
Package llm runs a LLM locally via llama.cpp, llamafile, or with a python server. It takes care of everything, including fetching gguf packed models from hugging face.
Index ¶
- type Client
- func (c *Client) GenStream(ctx context.Context, msgs []genai.Message, opts ...genai.Options) (iter.Seq[genai.Reply], func() (genai.Result, error))
- func (c *Client) GenSync(ctx context.Context, msgs []genai.Message, opts ...genai.Options) (genai.Result, error)
- func (c *Client) Unwrap() genai.Provider
- type Conversation
- type Memory
- type Options
- type PackedFileRef
- func (p PackedFileRef) Author() string
- func (p PackedFileRef) Basename() string
- func (p PackedFileRef) ModelRef() huggingface.ModelRef
- func (p PackedFileRef) Repo() string
- func (p PackedFileRef) RepoID() string
- func (p PackedFileRef) RepoURL() string
- func (p PackedFileRef) Revision() string
- func (p PackedFileRef) Validate() error
- type PackedRepoRef
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client wraps a Provider client and logs its calls.
func (*Client) GenStream ¶
func (c *Client) GenStream(ctx context.Context, msgs []genai.Message, opts ...genai.Options) (iter.Seq[genai.Reply], func() (genai.Result, error))
GenStream implements genai.Provider
type Conversation ¶
type Conversation struct {
User string
SystemPrompt string
Channel string
Started time.Time
LastUpdate time.Time
Messages []genai.Message
// contains filtered or unexported fields
}
Conversation is a conversation with one user.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory holds the bot's conversations.
func (*Memory) Get ¶
func (m *Memory) Get(user, channel string) *Conversation
Get gets a previous conversations or returns a new one if it's a new conversation.
type Options ¶
type Options struct {
// Backend is the name of the backend to run. It can be "llama-server" or "python" for genaipy.
Backend string `yaml:"backend"`
// Model specifies a model to use.
Model PackedFileRef `yaml:"model"`
// ContextLength will set the context length when using a locally managed "llamacpp".
ContextLength int `yaml:"context_length"`
// contains filtered or unexported fields
}
Options for NewLLM.
type PackedFileRef ¶
type PackedFileRef string
PackedFileRef is a packed reference to a file in an hugging face repository.
The form is "hf:<author>/<repo>/HEAD/<file>"
HEAD is the git commit reference or "revision". HEAD means the default branch. It can be replaced with a branch name or a commit hash. The default branch used by huggingface_hub official python library is "main".
DEFAULT_REVISION in https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/constants.py
func MakePackedFileRef ¶
func MakePackedFileRef(author, repo, revision, file string) PackedFileRef
MakePackedFileRef returns a PackedFileRef
func (PackedFileRef) Author ¶
func (p PackedFileRef) Author() string
Author returns the <author> part of the packed reference.
func (PackedFileRef) Basename ¶
func (p PackedFileRef) Basename() string
Basename returns the basename part of this reference.
func (PackedFileRef) ModelRef ¶
func (p PackedFileRef) ModelRef() huggingface.ModelRef
ModelRef returns the ModelRef reference to the repo containing this file.
func (PackedFileRef) Repo ¶
func (p PackedFileRef) Repo() string
Repo returns the <repo> part of the packed reference.
func (PackedFileRef) RepoID ¶
func (p PackedFileRef) RepoID() string
RepoID returns the canonical "<author>/<repo>" for this repository.
func (PackedFileRef) RepoURL ¶
func (p PackedFileRef) RepoURL() string
RepoURL returns the canonical URL for this repository.
func (PackedFileRef) Revision ¶
func (p PackedFileRef) Revision() string
Revision returns the HEAD part of the packed reference.
func (PackedFileRef) Validate ¶
func (p PackedFileRef) Validate() error
Validate checks for obvious errors in the string.
type PackedRepoRef ¶
type PackedRepoRef string
PackedRepoRef is a packed reference to an hugging face repository.
The form is "hf:<author>/<repo>"
func (PackedRepoRef) ModelRef ¶
func (p PackedRepoRef) ModelRef() huggingface.ModelRef
ModelRef converts to a ModelRef reference.
func (PackedRepoRef) RepoID ¶
func (p PackedRepoRef) RepoID() string
RepoID returns the canonical "<author>/<repo>" for this repository.
func (PackedRepoRef) RepoURL ¶
func (p PackedRepoRef) RepoURL() string
RepoURL returns the canonical URL for this repository.
func (PackedRepoRef) Validate ¶
func (p PackedRepoRef) Validate() error
Validate checks for obvious errors in the string.
type Server ¶
type Server struct {
HF *huggingface.Client
Model PackedFileRef
URL string
// contains filtered or unexported fields
}
Server runs a llamacpp-server or python.