Skip to content

Commit 7295d16

Browse files
martin-martinclaudebzaczynski
authored
Update chatterbot materials for ChatterBot 1.2.13 (post 2122) (#757)
* Update chatterbot materials for ChatterBot 1.2.13 Syncs the chatterbot/ folder with the revised tutorial (post 2122), including the new LLM integration step with Ollama. - requirements.txt: bump to ChatterBot 1.2.13 + modern spaCy/SQLAlchemy stack and add ollama 0.6.1 so step 6 works out of the box - chat.txt: update sample WhatsApp export dates to 2026 to match the tutorial - cleaner.py: refresh docstring/comment example dates - source_code_step_2/bot.py: reorder imports and format trainer.train() calls to match the updated tutorial listing - source_code_step_5: extract training from bot.py into a dedicated trainer.py - source_code_step_6/: new folder showing the Ollama hybrid configuration (BestMatch + OllamaLogicAdapter with llama3.2) - source_code_final/: mirror of step 6 with the Ollama-enabled bot.py - Regenerate db.sqlite3 in every step folder under ChatterBot 1.2.13, and drop the stale -shm / -wal sidecar files - README: document the trainer.py split, the step 6 Ollama setup, and the additional `spacy download en_core_web_sm` step Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Apply ruff format to step_2/3/4 bot.py --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Bartosz Zaczyński <bartosz.zaczynski@gmail.com>
1 parent 6609bd8 commit 7295d16

38 files changed

Lines changed: 946 additions & 624 deletions

chatterbot/README.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,53 @@ Create and activate a [virtual environment](https://realpython.com/python-virtua
88
$ python -m venv venv
99
$ source venv/bin/activate
1010
(venv) $ python -m pip install -r requirements.txt
11+
(venv) $ python -m spacy download en_core_web_sm
1112
```
1213

13-
Then you can navigate into the folder `source_code_final/` and train and start the interactive command-line interface chatbot by running `bot.py`:
14+
Starting in `source_code_step_5/`, training is handled by a dedicated script, `trainer.py`, that reads from `chat.txt` and populates `db.sqlite3`. The interactive chatbot lives in `bot.py`:
1415

1516
```sh
1617
(venv) $ cd source_code_final
18+
(venv) $ python trainer.py # (optional) retrain from chat.txt
1719
(venv) $ python bot.py
1820
```
1921

22+
A pretrained `db.sqlite3` is included in each step folder, so you can run `bot.py` right away without retraining.
23+
2024
After training, you'll see an interactive prompt that you can chat with:
2125

2226
```text
2327
> hi
24-
🪴 Welcome, friend 🤗
25-
> thanks for the green welcome
26-
🪴 I let you
27-
> you let me be here?
28-
🪴 It's a monsters!
29-
> did you mean monstera?
30-
🪴 The leafs that she had are getting dryer and dryer. But she’s also growing plenty of new ones
31-
> who?
32-
🪴 Do raindrops touch their leaves?
33-
> very philosophical!
34-
🪴 Lol
35-
> ;)
36-
🪴 I don't grow any crop at home
37-
> no crops in pots
38-
🪴 Ah, gotcha!
28+
🪴 Hi! How's your day going so far?
29+
> Do you talk to your plants?
30+
🪴 I do!
31+
> What do they like to hear?
32+
🪴 Motivational speeches
33+
> Do plants need sunlight?
34+
🪴 Yes, most plants need sunlight to undergo photosynthesis,
35+
which is how they make their own food. How's your indoor garden doing?
3936
```
4037

4138
The bot will learn from the replies you give and improve its accuracy. You can quit the interactive prompt by typing any of the `exit_conditions` defined in `bot.py`.
4239

40+
## Folder Structure
41+
4342
You'll find the code for each step of the tutorial in a separate folder. The folders also include a SQLite database that contains the different phases of training at each step. Because of this, you can inspect the project at different stages and notice how it evolves when you add more data and interactions.
43+
44+
- `source_code_step_1/` — minimal chatbot with no training
45+
- `source_code_step_2/` — adds `ListTrainer` with a couple of sample exchanges
46+
- `source_code_step_3/` — includes the WhatsApp `chat.txt` export
47+
- `source_code_step_4/` — adds `cleaner.py` for preprocessing the chat export
48+
- `source_code_step_5/` — splits training into `trainer.py` which trains on the cleaned chat data
49+
- `source_code_step_6/` — adds a local LLM via `OllamaLogicAdapter` (requires Ollama)
50+
- `source_code_final/` — same as step 6
51+
52+
## Using the Ollama integration (step 6 and final)
53+
54+
Step 6 and the `source_code_final/` folder use ChatterBot's experimental [Ollama](https://ollama.com/) integration. To try it, [install Ollama](https://realpython.com/ollama/) on your system and pull a small model:
55+
56+
```sh
57+
$ ollama pull llama3.2:latest
58+
```
59+
60+
Then run `bot.py` as usual. If you don't want to use Ollama, remove the `OllamaLogicAdapter` entry from the `logic_adapters` list in `bot.py`.

chatterbot/requirements.txt

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
1-
ChatterBot==1.0.4
2-
chatterbot-corpus==1.2.0
3-
click==8.1.3
4-
joblib==1.1.0
5-
mathparse==0.1.2
6-
nltk==3.7
7-
Pint==0.19.2
8-
pymongo==3.12.3
9-
python-dateutil==2.7.5
10-
pytz==2022.2.1
11-
PyYAML==3.13
12-
regex==2022.9.11
13-
six==1.16.0
14-
SQLAlchemy==1.2.19
15-
tqdm==4.64.1
1+
annotated-doc==0.0.4
2+
annotated-types==0.7.0
3+
anyio==4.13.0
4+
blis==1.3.3
5+
catalogue==2.0.10
6+
certifi==2026.2.25
7+
charset-normalizer==3.4.7
8+
chatterbot==1.2.13
9+
click==8.3.2
10+
cloudpathlib==0.23.0
11+
confection==1.3.3
12+
cymem==2.0.13
13+
h11==0.16.0
14+
httpcore==1.0.9
15+
httpx==0.28.1
16+
idna==3.11
17+
jinja2==3.1.6
18+
markdown-it-py==4.0.0
19+
markupsafe==3.0.3
20+
mathparse==0.2.8
21+
mdurl==0.1.2
22+
murmurhash==1.0.15
23+
numpy==2.4.4
24+
ollama==0.6.1
25+
packaging==26.1
26+
preshed==3.0.13
27+
pydantic==2.13.2
28+
pydantic-core==2.46.2
29+
pygments==2.20.0
30+
python-dateutil==2.9.0.post0
31+
requests==2.33.1
32+
rich==15.0.0
33+
setuptools==82.0.1
34+
shellingham==1.5.4
35+
six==1.17.0
36+
smart-open==7.6.0
37+
spacy==3.8.13
38+
spacy-legacy==3.0.12
39+
spacy-loggers==1.0.5
40+
sqlalchemy==2.0.49
41+
srsly==2.5.3
42+
thinc==8.3.13
43+
tqdm==4.67.3
44+
typer==0.24.1
45+
typing-extensions==4.15.0
46+
typing-inspection==0.4.2
47+
urllib3==2.6.3
48+
wasabi==1.1.3
49+
weasel==1.0.0
50+
wrapt==2.1.2

chatterbot/source_code_final/bot.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
from chatterbot.trainers import ListTrainer
2-
from cleaner import clean_corpus
3-
41
from chatterbot import ChatBot
52

6-
CORPUS_FILE = "chat.txt"
7-
8-
chatbot = ChatBot("Chatpot")
9-
10-
trainer = ListTrainer(chatbot)
11-
cleaned_corpus = clean_corpus(CORPUS_FILE)
12-
trainer.train(cleaned_corpus)
3+
chatbot = ChatBot(
4+
"Chatpot",
5+
logic_adapters=[
6+
{
7+
"import_path": "chatterbot.logic.BestMatch",
8+
},
9+
{
10+
"import_path": "chatterbot.logic.OllamaLogicAdapter",
11+
"model": "llama3.2:latest",
12+
"host": "http://localhost:11434",
13+
},
14+
],
15+
)
1316

1417
exit_conditions = (":q", "quit", "exit")
1518
while True:

0 commit comments

Comments
 (0)