Skip to content

Commit c7aa2c4

Browse files
Chatterbot Final QA updates (#310)
* Final QA updates * Remove the walrus Because Windows, and potentially also some Linux installations, depend on using Python<3.8 (pre-walrus), it has proven too dangerous to keep it around: https://en.wikipedia.org/wiki/Walrus_attack Co-authored-by: martin-martin <[email protected]>
1 parent 3622f53 commit c7aa2c4

File tree

9 files changed

+42
-18
lines changed

9 files changed

+42
-18
lines changed

chatterbot/source_code_final/bot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
trainer.train(cleaned_corpus)
1313

1414
exit_conditions = (":q", "quit", "exit")
15-
while (query := input("> ")) not in exit_conditions:
16-
print(f"🪴 {chatbot.get_response(query)}")
15+
while True:
16+
query = input("> ")
17+
if query in exit_conditions:
18+
break
19+
else:
20+
print(f"🪴 {chatbot.get_response(query)}")

chatterbot/source_code_final/cleaner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def remove_chat_metadata(chat_export_file):
3333

3434
with open(chat_export_file, "r") as corpus_file:
3535
content = corpus_file.read()
36-
cleaned_corpus = re.sub(pattern, "", content)
37-
return tuple(cleaned_corpus.split("\n"))
36+
cleaned_corpus = re.sub(pattern, "", content)
37+
return tuple(cleaned_corpus.split("\n"))
3838

3939

4040
def remove_non_message_text(export_text_lines):

chatterbot/source_code_step_1/bot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
chatbot = ChatBot("Chatpot")
44

55
exit_conditions = (":q", "quit", "exit")
6-
while (query := input("> ")) not in exit_conditions:
7-
print(f"🪴 {chatbot.get_response(query)}")
6+
while True:
7+
query = input("> ")
8+
if query in exit_conditions:
9+
break
10+
else:
11+
print(f"🪴 {chatbot.get_response(query)}")

chatterbot/source_code_step_2/bot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
trainer.train(["Are you a plant?", "No, I'm the pot below the plant!"])
99

1010
exit_conditions = (":q", "quit", "exit")
11-
while (query := input("> ")) not in exit_conditions:
12-
print(f"🪴 {chatbot.get_response(query)}")
11+
while True:
12+
query = input("> ")
13+
if query in exit_conditions:
14+
break
15+
else:
16+
print(f"🪴 {chatbot.get_response(query)}")

chatterbot/source_code_step_3/bot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
trainer.train(["Are you a plant?", "No, I'm the pot below the plant!"])
99

1010
exit_conditions = (":q", "quit", "exit")
11-
while (query := input("> ")) not in exit_conditions:
12-
print(f"🪴 {chatbot.get_response(query)}")
11+
while True:
12+
query = input("> ")
13+
if query in exit_conditions:
14+
break
15+
else:
16+
print(f"🪴 {chatbot.get_response(query)}")

chatterbot/source_code_step_4/bot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
trainer.train(["Are you a plant?", "No, I'm the pot below the plant!"])
99

1010
exit_conditions = (":q", "quit", "exit")
11-
while (query := input("> ")) not in exit_conditions:
12-
print(f"🪴 {chatbot.get_response(query)}")
11+
while True:
12+
query = input("> ")
13+
if query in exit_conditions:
14+
break
15+
else:
16+
print(f"🪴 {chatbot.get_response(query)}")

chatterbot/source_code_step_4/cleaner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def remove_chat_metadata(chat_export_file):
3333

3434
with open(chat_export_file, "r") as corpus_file:
3535
content = corpus_file.read()
36-
cleaned_corpus = re.sub(pattern, "", content)
37-
return tuple(cleaned_corpus.split("\n"))
36+
cleaned_corpus = re.sub(pattern, "", content)
37+
return tuple(cleaned_corpus.split("\n"))
3838

3939

4040
def remove_non_message_text(export_text_lines):

chatterbot/source_code_step_5/bot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
trainer.train(cleaned_corpus)
1313

1414
exit_conditions = (":q", "quit", "exit")
15-
while (query := input("> ")) not in exit_conditions:
16-
print(f"🪴 {chatbot.get_response(query)}")
15+
while True:
16+
query = input("> ")
17+
if query in exit_conditions:
18+
break
19+
else:
20+
print(f"🪴 {chatbot.get_response(query)}")

chatterbot/source_code_step_5/cleaner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def remove_chat_metadata(chat_export_file):
3333

3434
with open(chat_export_file, "r") as corpus_file:
3535
content = corpus_file.read()
36-
cleaned_corpus = re.sub(pattern, "", content)
37-
return tuple(cleaned_corpus.split("\n"))
36+
cleaned_corpus = re.sub(pattern, "", content)
37+
return tuple(cleaned_corpus.split("\n"))
3838

3939

4040
def remove_non_message_text(export_text_lines):

0 commit comments

Comments
 (0)