From a55ae8a51126099a3418ce7f9b6889e5f233bdf9 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 30 Jun 2021 17:29:00 -0400 Subject: [PATCH 1/4] Use Bobloy's chatterbot fork --- chatter/README.md | 66 +++++++------------------------------ chatter/chat.py | 8 ++++- chatter/info.json | 12 +------ chatter/requirements.txt | 24 +++++++------- chatter/storage_adapters.py | 2 +- 5 files changed, 33 insertions(+), 79 deletions(-) diff --git a/chatter/README.md b/chatter/README.md index 06331b2..bcd6cbc 100644 --- a/chatter/README.md +++ b/chatter/README.md @@ -74,77 +74,35 @@ If you get an error at this step, stop and skip to one of the manual methods bel #### Step 2: Install additional dependencies -Assuming the previous commands had no error, you can now use `pipinstall` to add the remaining dependencies. +Here you need to decide which training models you want to have available to you. -NOTE: This method is not the intended use case for `pipinstall` and may stop working in the future. +Shutdown the bot and run any number of these in the console: ``` -[p]pipinstall --no-deps chatterbot>=1.1 -``` - -#### Step 3: Load the cog and get started - -``` -[p]load chatter -``` +python -m spacy download en_core_web_sm # ~15 MB -### Windows - Manually -#### Step 1: Built-in Downloader +python -m spacy download en_core_web_md # ~50 MB -You need to get a copy of the requirements.txt provided with chatter, I recommend this method. +python -m spacy download en_core_web_lg # ~750 MB (CPU Optimized) -``` -[p]repo add Fox https://github.com/bobloy/Fox-V3 +python -m spacy download en_core_web_trf # ~500 MB (GPU Optimized) ``` -#### Step 2: Install Requirements - -Make sure you have your virtual environment that you installed Red on activated before starting this step. See the Red Docs for details on how. - -In a terminal running as an admin, navigate to the directory containing this repo. - -I've used my install directory as an example. - -``` -cd C:\Users\Bobloy\AppData\Local\Red-DiscordBot\Red-DiscordBot\data\bobbot\cogs\RepoManager\repos\Fox\chatter -pip install -r requirements.txt -pip install --no-deps "chatterbot>=1.1" -``` - -#### Step 3: Load Chatter +#### Step 3: Load the cog and get started ``` -[p]repo add Fox https://github.com/bobloy/Fox-V3 # If you didn't already do this in step 1 -[p]cog install Fox chatter [p]load chatter ``` -### Linux - Manually - -#### Step 1: Built-in Downloader - -``` -[p]repo add Fox https://github.com/bobloy/Fox-V3 -[p]cog install Fox chatter -``` - -#### Step 2: Install Requirements - -In your console with your virtual environment activated: - -``` -pip install --no-deps "chatterbot>=1.1" -``` - -### Step 3: Load Chatter +### Windows - Manually +Deprecated -``` -[p]load chatter -``` +### Linux - Manually +Deprecated # Configuration -Chatter works out the the box without any training by learning as it goes, +Chatter works out the box without any training by learning as it goes, but will have very poor and repetitive responses at first. Initial training is recommended to speed up its learning. diff --git a/chatter/chat.py b/chatter/chat.py index 5ad3efb..b8cf75d 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -29,6 +29,12 @@ def my_local_get_prefix(prefixes, content): return None +class ENG_TRF: + ISO_639_1 = "en_core_web_trf" + ISO_639 = "eng" + ENGLISH_NAME = "English" + + class ENG_LG: ISO_639_1 = "en_core_web_lg" ISO_639 = "eng" @@ -70,7 +76,7 @@ class Chatter(Cog): # TODO: Move training_model and similarity_algo to config # TODO: Add an option to see current settings - self.tagger_language = ENG_MD + self.tagger_language = ENG_TRF self.similarity_algo = SpacySimilarity self.similarity_threshold = 0.90 self.chatbot = self._create_chatbot() diff --git a/chatter/info.json b/chatter/info.json index fc31e7c..a9bb96b 100644 --- a/chatter/info.json +++ b/chatter/info.json @@ -7,17 +7,7 @@ "hidden": false, "install_msg": "Thank you for installing Chatter! Please make sure you check the install instructions at https://github.com/bobloy/Fox-V3/blob/master/chatter/README.md\nAfter that, get started ith `[p]load chatter` and `[p]help Chatter`", "requirements": [ - "git+git://github.com/gunthercox/chatterbot-corpus@master#egg=chatterbot_corpus", - "mathparse>=0.1,<0.2", - "nltk>=3.2,<4.0", - "pint>=0.8.1", - "python-dateutil>=2.8,<2.9", - "pyyaml>=5.3,<5.4", - "sqlalchemy>=1.3,<1.4", - "pytz", - "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm", - "https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz#egg=en_core_web_md", - "spacy>=2.3,<2.4", + "git+git://github.com/bobloy/ChatterBot@fox#egg=ChatterBot", "kaggle" ], "short": "Local Chatbot run on machine learning", diff --git a/chatter/requirements.txt b/chatter/requirements.txt index 88cd662..bbcfcf9 100644 --- a/chatter/requirements.txt +++ b/chatter/requirements.txt @@ -1,12 +1,12 @@ -git+git://github.com/gunthercox/chatterbot-corpus@master#egg=chatterbot_corpus -mathparse>=0.1,<0.2 -nltk>=3.2,<4.0 -pint>=0.8.1 -python-dateutil>=2.8,<2.9 -pyyaml>=5.3,<5.4 -sqlalchemy>=1.3,<1.4 -pytz -spacy>=2.3,<2.4 -https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm -https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz#egg=en_core_web_md -# https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.3.1/en_core_web_lg-2.3.1.tar.gz#egg=en_core_web_lg \ No newline at end of file +# git+git://github.com/gunthercox/chatterbot-corpus@master#egg=chatterbot_corpus +# mathparse>=0.1,<0.2 +# nltk>=3.2,<4.0 +# pint>=0.8.1 +# python-dateutil>=2.8,<2.9 +# # pyyaml>=5.3,<5.4 +# sqlalchemy>=1.3,<1.4 +# pytz +# spacy>=2.3,<2.4 +# https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm +# https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz#egg=en_core_web_md +# # https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.3.1/en_core_web_lg-2.3.1.tar.gz#egg=en_core_web_lg \ No newline at end of file diff --git a/chatter/storage_adapters.py b/chatter/storage_adapters.py index 4de2f00..6f11601 100644 --- a/chatter/storage_adapters.py +++ b/chatter/storage_adapters.py @@ -19,7 +19,7 @@ class MyDumbSQLStorageAdapter(SQLStorageAdapter): self.database_uri = "sqlite:///db.sqlite3" self.engine = create_engine( - self.database_uri, convert_unicode=True, connect_args={"check_same_thread": False} + self.database_uri, connect_args={"check_same_thread": False} ) if self.database_uri.startswith("sqlite://"): From 9c63c126563153e3c5290bc5d6c2dde06c1a4c37 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 30 Jun 2021 17:29:31 -0400 Subject: [PATCH 2/4] Don't need requirements file --- chatter/requirements.txt | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 chatter/requirements.txt diff --git a/chatter/requirements.txt b/chatter/requirements.txt deleted file mode 100644 index bbcfcf9..0000000 --- a/chatter/requirements.txt +++ /dev/null @@ -1,12 +0,0 @@ -# git+git://github.com/gunthercox/chatterbot-corpus@master#egg=chatterbot_corpus -# mathparse>=0.1,<0.2 -# nltk>=3.2,<4.0 -# pint>=0.8.1 -# python-dateutil>=2.8,<2.9 -# # pyyaml>=5.3,<5.4 -# sqlalchemy>=1.3,<1.4 -# pytz -# spacy>=2.3,<2.4 -# https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm -# https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz#egg=en_core_web_md -# # https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.3.1/en_core_web_lg-2.3.1.tar.gz#egg=en_core_web_lg \ No newline at end of file From c165313031644c4480aedff848859a7a1c36da8b Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 1 Jul 2021 15:25:38 -0400 Subject: [PATCH 3/4] no reply errors in cache --- chatter/chat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index b8cf75d..2deb082 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -63,7 +63,7 @@ class Chatter(Cog): self.bot = bot self.config = Config.get_conf(self, identifier=6710497116116101114) default_global = {"learning": True} - default_guild = { + self.default_guild = { "whitelist": None, "days": 1, "convo_delta": 15, @@ -711,7 +711,9 @@ class Chatter(Cog): ) replying = None - if self._guild_cache[guild.id]["reply"]: + if ( + "reply" not in self._guild_cache[guild.id] and self.default_guild["reply"] + ) or self._guild_cache[guild.id]["reply"]: if message != ctx.channel.last_message: replying = message From 6f0c88b1ac31b424de5af46cade5b6f1fb816879 Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 1 Jul 2021 17:19:29 -0400 Subject: [PATCH 4/4] change default models, fix requirements --- chatter/chat.py | 9 +++++---- chatter/info.json | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index 2deb082..e3f14cc 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -76,7 +76,7 @@ class Chatter(Cog): # TODO: Move training_model and similarity_algo to config # TODO: Add an option to see current settings - self.tagger_language = ENG_TRF + self.tagger_language = ENG_SM self.similarity_algo = SpacySimilarity self.similarity_threshold = 0.90 self.chatbot = self._create_chatbot() @@ -85,7 +85,7 @@ class Chatter(Cog): # self.trainer = ListTrainer(self.chatbot) self.config.register_global(**default_global) - self.config.register_guild(**default_guild) + self.config.register_guild(**self.default_guild) self.loop = asyncio.get_event_loop() @@ -371,11 +371,12 @@ class Chatter(Cog): 0: Small 1: Medium 2: Large (Requires additional setup) + 3. Accurate (Requires additional setup) """ - models = [ENG_SM, ENG_MD, ENG_LG] + models = [ENG_SM, ENG_MD, ENG_LG, ENG_TRF] - if model_number < 0 or model_number > 2: + if model_number < 0 or model_number > 3: await ctx.send_help() return diff --git a/chatter/info.json b/chatter/info.json index a9bb96b..0004709 100644 --- a/chatter/info.json +++ b/chatter/info.json @@ -8,6 +8,7 @@ "install_msg": "Thank you for installing Chatter! Please make sure you check the install instructions at https://github.com/bobloy/Fox-V3/blob/master/chatter/README.md\nAfter that, get started ith `[p]load chatter` and `[p]help Chatter`", "requirements": [ "git+git://github.com/bobloy/ChatterBot@fox#egg=ChatterBot", + "en_core_web_sm", "kaggle" ], "short": "Local Chatbot run on machine learning",