Our Eliza (oureliza)
A minimal Python implementation of the classic ELIZA chatbot with zero dependencies.
Try the Demo
Chat with ELIZA in your browser: Interactive Demo
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@wordmatches 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 License - see LICENSE for details.
Author
Craig Trim - craigtrim@gmail.com
More NLP articles and demos at craigtrim.com
Metadata
Release files for oureliza 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oureliza-1.2.1.tar.gz | 23.3 kB | Without provenance | Details for oureliza-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oureliza-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for oureliza-1.2.1-py3-none-any.whl |
Total release size: 44.8 kB
Release files / oureliza-1.2.1.tar.gz
| Download URL | oureliza-1.2.1.tar.gz |
|---|---|
| Size | 23.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80a9fc287974edfb019b16c0e3a0156655b7607a8df390d291a454d270c40028
|
|
BLAKE2b-256 checksum How to use checksums |
828a3550f3b38f487253a5667823054a69038981df241e34c6eff78c7f53c597
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.11.9 Darwin/24.6.0
|
Release files / oureliza-1.2.1-py3-none-any.whl
| Download URL | oureliza-1.2.1-py3-none-any.whl |
|---|---|
| Size | 21.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
209afb0bfb68c207c980fdebe28d5edf1a7b87815eea7a9c1b2e79c7f246aedc
|
|
BLAKE2b-256 checksum How to use checksums |
a78ac937d387cc41455e30686ea9f756f5829e05520286abca10c0db15dd4202
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.11.9 Darwin/24.6.0
|
Security for oureliza 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.