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.

'Chatbot' is not defined in Chatterbot and few more questions

See original GitHub issue

I am making a chatbot through Chatterbot. I am facing the problems as follow:

  1. when I run the code, it shows error, but the ChatBot is imported from chatterbot at the beginning?

File “…/SquirralBot.py”, line 5, in class SquirralBot: File “…SquirralBot.py”, line 6, in SquirralBot bot = Chatbot(“SquirralBot”, NameError: name ‘Chatbot’ is not defined

  1. I want to make the chatbot to distinguish specific texts then to trigger specific corpus, how can I make it? Is the “chatterbot.conversation.Response(text, **kwargs)” class for this purpose? e.g. when the user types “I am leaving”, then it will trigger to call the training set “chatterbot.corpus.chinese.squirral_bye_conversation”?

  2. Is it possible if I can store the reply specifically to the database e.g. MongoDB for different users? e.g. when user A replies “I am sick. I got fever and running nose”, then the system store “sick” into “status” and “fever” and “running nose” into “symptoms” in the user A’s data so that inside the database it would be like JSON:

{
     "user A", 
     "gender": "male", 
     "record": 
  [ 
        {
             "date": "25-12-2018", 
             "status": "fine", 
             "symptoms": "", 
        }, 
        { 
            "date": "26-12-2018", 
            "status": "sick", 
            "symptoms": "fever", "running nose"
        } 
}
  1. Is it possible to make the chatbot can text the user in specific time range?

The code for the above mentioned is as following. I am very new in programming so the code may be a bit messy. Please feel free to correct. Many thanks.

import sys 
from chatterbot import ChatBot 
from chatterbot.trainers import ChatterBotCorpusTrainer

class SquirralBot:
    chatbot = Chatbot("SquirralBot",
    logic_adapters=[
        {
            "import_path": "chatterbot.logic.BestMatch",
            "statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
            "response_selection_method": "chatterbot.response_selection.get_first_response"
        }
    ],storage_adapter = "chatterbot.storage.JsonFileStorageAdapter",database = "./SquirralBot_DB.json")

    def __init__(self):
        self.chatbot.set_trainer(ChatterBotCorpusTrainer)
        self.chatbot.train("chatterbot.corpus.chinese.squirral_greeting", "chatterbot.corpus.chinese.squirral_bye_conversation", "chatterbot.corpus.chinese.squirral_normal_conversation", "chatterbot.corpus.chinese.squirral_rabbit_bye_conversation", "chatterbot.corpus.chinese.squirral_rabbit_conversation")

    def getResponse(self, message=""):
        return self.chatbot.get_response(message)

if __name__ == "__main__":
    bot = SquirralBot()
    print(bot.getResponse(sys.argv[1]))

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
gunthercoxcommented, Jan 2, 2019

@vkosuri I suppose that could possibly prevent confusion to an extent, but I’d prefer to follow the recommended naming conventions for classes in Python.

https://www.python.org/dev/peps/pep-0008/#class-names

0reactions
lock[bot]commented, May 20, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'Chatbot' is not defined in Chatterbot - Stack Overflow
I want to make the chatbot to distinguish specific texts then to trigger specific corpus, how can I make it? Is the "chatterbot.conversation....
Read more >
Frequently Asked Questions — ChatterBot 1.0.8 documentation
This document is comprised of questions that are frequently asked about ChatterBot and chat bots in general. Python String Encoding · Does ChatterBot...
Read more >
ChatterBot Tutorial — ChatterBot 1.0.8 documentation
Creating your first chat bot. Create a new file named chatbot.py . Then open chatbot.py in your editor of choice. Before we do...
Read more >
Examples — ChatterBot 1.0.8 documentation - Read the Docs
Your chat bot will learn based on each new input statement it receives. If you want to disable this learning feature after your...
Read more >
ChatterBot Documentation
ChatterBot is a Python library that makes it easy to generate automated responses to a user's input. ChatterBot uses.
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