You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`:
14
15
15
16
```sh
16
17
(venv) $ cd source_code_final
18
+
(venv) $ python trainer.py # (optional) retrain from chat.txt
17
19
(venv) $ python bot.py
18
20
```
19
21
22
+
A pretrained `db.sqlite3` is included in each step folder, so you can run `bot.py` right away without retraining.
23
+
20
24
After training, you'll see an interactive prompt that you can chat with:
21
25
22
26
```text
23
27
> 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?
39
36
```
40
37
41
38
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`.
42
39
40
+
## Folder Structure
41
+
43
42
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`.
0 commit comments