question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Training Django ChatterBot

See original GitHub issue

Hi, since the command (with the new version of ChatterBot) python3 manage.py train is no more supported, how can I train my online bot implemented with Django? I read that I have to create a new python file train.py, but I tried and I didn’t solve the problem.

This is part of my settings.py file:

CHATTERBOT = {
    'name': 'My Online Bot',
    'django_app_name': 'django_chatterbot',
	
    'storage_adapter' : 'chatterbot.storage.SQLStorageAdapter',
    'database_uri' : 'sqlite:///online_bot_database.sqlite3',

    'logic_adapters' : [
          {
		'import_path': 'chatterbot.logic.BestMatch',
		'statement_comparison_function': 'chatterbot.comparisons.levenshtein_distance',
		'response_selection_method': get_first_response
	  },
    ]
} 

How to properly set up the train.py file for this bot?

Thanks in advance,

Alan

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:13

github_iconTop GitHub Comments

4reactions
mikekedacommented, May 12, 2019
1reaction
oliver3commented, Oct 21, 2021

For me, using the SQLStorageAdapter was not good enough because then the data would not show up in Django admin, but using a separate train.py with the chatterbot.storage.DjangoStorageAdapter that the chatterbot.ext.django_chatterbot app uses resulted in a django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. error.

I did get it working by creating a custom manage.py command in my own Django application using the folder structure described in https://docs.djangoproject.com/en/3.2/howto/custom-management-commands/

and with the following management/commands/train.py

from django.core.management.base import BaseCommand, CommandError

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

class Command(BaseCommand):
    help = 'Train the chatbot with a corpus'

    def handle(self, *args, **options):
        chatbot = ChatBot(
            'ChatBot name from settings.py CHATTERBOT',
            storage_adapter='chatterbot.storage.DjangoStorageAdapter',
        )

        trainer = ChatterBotCorpusTrainer(chatbot)
        trainer.train(
            "chatterbot.corpus.english"
        )

        self.stdout.write(self.style.SUCCESS('Successfully trained!'))

Edit: and then finally you can use python3 manage.py train again 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django Integration — ChatterBot 1.0.8 documentation
ChatterBot has direct support for integration with Django's ORM. It is relatively easy to use ChatterBot within your Django application to create ...
Read more >
Ramping up a ChatBot, integrate with Django and deploy on ...
This blog will technically guide you how to end up with an innovative machine-learning ChatBot (webApp), ramped-up over ChatterBot and Django frameworks and ......
Read more >
Build Chatbot Using Django - Udemy
This courses will teach you How to Build a Complete Smart Chatbot as a Personal Assistant Using Django & AI. The chatbot will...
Read more >
Build a ChatBot Using Python, Django - Documatic
WebSockets using Django Channels - To send to the client the automated response generated by the machine learning model immediately when ...
Read more >
Create Web Based ChatBot in Python, Django, Flask
We will create a Chatbot using Python, Django, Flask and Chatterbot. ... Then we are training our chatbot with ListTrainer with our personal ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found