Skip to main content

Minimal Python implementation of the ELIZA chatbot

Project description

Our Eliza (oureliza)

Python 3.8+ PyPI version License: MIT

A minimal Python implementation of the classic ELIZA chatbot with zero dependencies.

Installation

pip install oureliza

Or with Poetry:

poetry add oureliza

Usage

from oureliza import Eliza

eliza = Eliza()

# Get initial greeting
print(eliza.initial())

# Have a conversation
print(eliza.respond("I feel sad today"))
print(eliza.respond("My mother never understood me"))
print(eliza.respond("I dream about flying"))

# Get final message
print(eliza.final())

Script Format

ELIZA uses a script-based pattern matching system designed by Joseph Weizenbaum in 1966. See SCRIPT_FORMAT.md for full history and specification.

The built-in DOCTOR_SCRIPT follows this format:

Tags

Tag Description Example
initial Greeting messages shown at start initial: How do you do. Please tell me your problem.
final Goodbye messages shown at end final: Goodbye. Thank you for talking to me.
quit Words that end the conversation quit: bye
pre Pre-substitution (before matching) pre: dont don't
post Post-substitution (in responses) post: i you
synon Synonym groups synon: sad unhappy depressed
key Keyword with optional weight key: mother 10
decomp Decomposition pattern decomp: * i feel *
reasmb Reassembly response reasmb: Why do you feel (2)?

Pattern Matching

  • * matches zero or more words
  • @word matches any synonym in the group
  • (1), (2), etc. reference captured groups from decomposition

Example Script Block

key: mother 10
  decomp: * my mother *
    reasmb: Tell me more about your mother.
    reasmb: What else comes to mind when you think of your mother?
  decomp: * mother *
    reasmb: Who else in your family (2)?

Special Features

  • goto: Redirect to another keyword's patterns

    reasmb: goto family
    
  • save ($): Save response to memory for later use

    decomp: $ * i want *
    
  • xnone: Fallback responses when no pattern matches

    key: xnone
      decomp: *
        reasmb: Please go on.
        reasmb: Tell me more about that.
    

Custom Scripts

You can provide your own script:

from oureliza import Eliza

my_script = """
initial: Hello! How can I help you today?
final: Goodbye!
quit: bye
quit: exit

key: xnone
  decomp: *
    reasmb: I see. Tell me more.
    reasmb: Please continue.

key: hello 10
  decomp: *
    reasmb: Hi there! What's on your mind?
"""

eliza = Eliza(script=my_script)
print(eliza.respond("hello"))

Development

# Install dependencies
make install

# Run tests
make test

# Build package
make build

# Do everything
make all

References

Based on wadetb/eliza with significant script expansion.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oureliza-1.2.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oureliza-1.2.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file oureliza-1.2.0.tar.gz.

File metadata

  • Download URL: oureliza-1.2.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.9 Darwin/24.6.0

File hashes

Hashes for oureliza-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e0576a3cc2b03e841fefdb773efd3176c7d150a3aea9b986ca3644c7e86c3b34
MD5 34a02f339fef3da3df1572e4b94fc3aa
BLAKE2b-256 8896d0464b82dc149d4cff27f943b850c5db9f4f40fe7e302bd0559ecc0a3a1f

See more details on using hashes here.

File details

Details for the file oureliza-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: oureliza-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.9 Darwin/24.6.0

File hashes

Hashes for oureliza-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed5c0a562200ed7f5ecd46b398b0a61fcf50982b17aa6da869004bfbc0b8e8da
MD5 361d58208048391e2fab34b72aa6967a
BLAKE2b-256 e23b935d2b318849a6e38bd6140412970b8423558d0240f22f9e4d2b15ae41d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page