eliza

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

eliza implements a mock LLM provider based on the classic ELIZA chatbot, created by Joseph Weizenbaum at MIT in 1966, which simulates a psychotherapist using pattern matching and transformation rules. It has a model for each of its languages, and makes no network calls at all, so it's always reachable, which is useful for exercising provider code paths (like connectivity checks, and generating messages) without depending on a real LLM backend.

Index

Constants

View Source
const ModelName = "eliza"

ModelName is an alias of eliza's English model, which is its default

Variables

This section is empty.

Functions

func LoadLanguages

func LoadLanguages() (map[string]*Language, error)

LoadLanguages reads all embedded lang/*.json files and returns them keyed by model name

Types

type Client

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

Client implements the ELIZA chatbot as an LLM provider

func New

func New(opts ...Opt) (*Client, error)

New creates a new eliza client, with its languages. It takes no endpoint, since it makes no network calls at all.

func (*Client) GetModel

func (c *Client) GetModel(ctx context.Context, name string) (llm.Model, error)

GetModel returns the model with the name, or the English model for eliza, or a not-found error

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) ([]llm.Model, error)

ListModels returns a model for each of eliza's languages, in order of their names

func (*Client) Name

func (*Client) Name() string

Name returns the provider name

func (*Client) Ping

func (*Client) Ping(ctx context.Context) error

Ping always succeeds: eliza makes no network calls.

func (*Client) Self

func (c *Client) Self() llm.Provider

Self returns the underlying client implementation.

func (*Client) URL added in v0.5.0

func (*Client) URL() *url.URL

URL returns nil: eliza has no endpoint.

func (*Client) WithoutSession

func (c *Client) WithoutSession(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, stream llm.GeneratorStreamFn, opts ...llm.Opt) (llm.Message, llm.Usage, error)

WithoutSession returns eliza's reply to the last of the messages, which is the user's, and must be for a model of this client, and the tokens used, which are estimated, as eliza has no tokens. Eliza remembers what the user said in the earlier messages, and with WithThinking, the reply's thinking is what it remembers. It can't call tools, so there can't be any. When the stream function isn't nil, it's called with the reply's thinking, and then its text a word at a time, as a model would generate it. The reply is the same for the same messages, with the client's seed.

type Engine

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

Engine implements the classic ELIZA conversation algorithm created by Joseph Weizenbaum at MIT in 1966.

func NewEngine

func NewEngine(lang *Language, seed int64) (*Engine, error)

NewEngine creates a new ELIZA conversation engine using the given language data

func (*Engine) InferMemory

func (e *Engine) InferMemory(inputs []string)

InferMemory rebuilds the memory from the text of the user's earlier messages which match memorable rules, so the engine can be created fresh for each request while remembering the conversation

func (*Engine) Memory

func (e *Engine) Memory() []string

Memory returns the current memory contents

func (*Engine) Reset

func (e *Engine) Reset()

Reset clears the conversation memory

func (*Engine) Response

func (e *Engine) Response(input string) string

Response generates an ELIZA response to the given input

type Language

type Language struct {
	Model             string            `json:"model"`
	Description       string            `json:"description"`
	LanguageCode      string            `json:"language"`
	Quits             []string          `json:"quits"`
	Greetings         []string          `json:"greetings"`
	Reflections       map[string]string `json:"reflections"`
	Rules             []Rule            `json:"rules"`
	GreetingResponses []string          `json:"greetingResponses"`
	GoodbyeResponses  []string          `json:"goodbyeResponses"`
	DefaultResponses  []string          `json:"defaultResponses"`
	MemoryResponses   []string          `json:"memoryResponses"`
}

Language defines all the text data for an ELIZA language variant

type Model added in v0.5.0

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

Model is one of eliza's languages

func (*Model) Aliases added in v0.5.0

func (m *Model) Aliases() []string

Aliases returns eliza for the English model, which is its default

func (*Model) Capabilities added in v0.5.0

func (m *Model) Capabilities() llm.ModelCap

Capabilities returns that eliza replies to messages, and thinks, with WithThinking, without tools, and does nothing else. Each capability is its own value, so it can be changed without changing the others.

func (*Model) Created added in v0.5.0

func (m *Model) Created() time.Time

func (*Model) Description added in v0.5.0

func (m *Model) Description() string

func (*Model) InputTokenLimit added in v0.5.0

func (m *Model) InputTokenLimit() *uint

InputTokenLimit is not meaningful for a mock model.

func (*Model) Meta added in v0.5.0

func (m *Model) Meta() map[string]json.RawMessage

Meta returns who created ELIZA, and the model's language

func (*Model) Name added in v0.5.0

func (m *Model) Name() string

func (*Model) OutputTokenLimit added in v0.5.0

func (m *Model) OutputTokenLimit() *uint

OutputTokenLimit is not meaningful for a mock model.

func (*Model) Provider added in v0.5.0

func (m *Model) Provider() llm.Provider

type Opt

type Opt func(*Client) error

Opt is an option for creating the eliza client

func WithSeed

func WithSeed(seed int64) Opt

WithSeed sets the seed of the replies, so they're the same each time

type Rule

type Rule struct {
	Pattern   string   `json:"pattern"`
	Responses []string `json:"responses"`
	Memorable bool     `json:"memorable,omitempty"`
}

Rule defines a pattern-matching rule with its responses

Jump to

Keyboard shortcuts

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