eliza

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

eliza implements a mock LLM provider based on the classic ELIZA chatbot created by Joseph Weizenbaum at MIT in 1966. It simulates a psychotherapist using pattern matching and transformation rules. It requires no API key or network access.

Index

Constants

This section is empty.

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

func WithThinking

func WithThinking() opt.Opt

WithThinking enables thinking output for ELIZA sessions. When enabled, the accumulated memory from the conversation is emitted as a thinking content block in the response.

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

func (*Client) GetModel

func (c *Client) GetModel(ctx context.Context, name string, opts ...opt.Opt) (*schema.Model, error)

GetModel returns an ELIZA model by name

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context, opts ...opt.Opt) ([]schema.Model, error)

ListModels returns the available models

func (*Client) Name

func (*Client) Name() string

Name returns the provider name

func (*Client) WithSession

func (c *Client) WithSession(ctx context.Context, model schema.Model, session *schema.Conversation, message *schema.Message, opts ...opt.Opt) (*schema.Message, *schema.Usage, error)

WithSession sends a message within a session and returns the response (stateful)

func (*Client) WithoutSession

func (c *Client) WithoutSession(ctx context.Context, model schema.Model, message *schema.Message, opts ...opt.Opt) (*schema.Message, *schema.Usage, error)

WithoutSession sends a single message and returns the response (stateless)

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(messages []*schema.Message)

InferMemory scans conversation messages and rebuilds the memory list from user messages that match memorable rules. This allows the engine to be created fresh per request while preserving memory state.

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 Opt

type Opt func(*Client) error

Opt is a functional option for configuring the ELIZA client

func WithSeed

func WithSeed(seed int64) Opt

WithSeed sets a specific random seed for reproducible responses

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