DEV Community

Cover image for Want to Build Your Own AI Chatbot? Try Pythonaibrain v1.1.8 in Python
Divyanshu Sinha
Divyanshu Sinha

Posted on

Want to Build Your Own AI Chatbot? Try Pythonaibrain v1.1.8 in Python

Want to Build Your Own AI Chatbot? Try Pythonaibrain v1.1.8 in Python

Author: Divyanshu Sinha
Tags: #python #ai #chatbot #pythonaibrain #tutorial


Want to Build Your Own AI?

If you’ve ever wanted to create a chatbot, Pythonaibrain v1.1.8 makes it super easy. Even if you’re new to AI, this Python toolkit lets you train, save, and run your own chatbot using simple intents.

In this tutorial, we’ll go step by step:

  • Install Pythonaibrain
  • Create intents for your chatbot
  • Train and save your AI
  • Run a fully interactive chatbot

By the end, you’ll have a chatbot ready to talk to anyone!


Step 1: Install Pythonaibrain

Open your terminal and run:

pip install pythonaibrain==1.1.8
Enter fullscreen mode Exit fullscreen mode

Make sure you have Python 3.8 or higher installed.


Step 2: Create Your Chatbot Intents

Create a file named intents.json in your project folder. This is where you define what your chatbot can understand and respond to:

{
  "intents": [
    {
      "tag": "greeting",
      "patterns": ["Hi", "Hello", "Hey"],
      "responses": ["Hello!", "Hi there!", "Hey! How can I help you?"]
    },
    {
      "tag": "goodbye",
      "patterns": ["Bye", "See you", "Goodbye"],
      "responses": ["Goodbye!", "See you later!", "Take care!"]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Tip: Each intent has a tag, patterns (user inputs), and responses (bot replies).


Step 3: Write the Chatbot Code

Create a Python file, e.g., chatbot.py, and add:

from pyaitk import Brain

# Initialize Brain object. Leave blank if your intents file is named 'intents.json', it will auto-detect and load.
brain = Brain()

# Train the model using the loaded intents
brain.train()

# Save the trained model for future use
brain.save()

# If the model is already trained, simply load it using:
# brain.load()
# This avoids retraining the model

# Prompt the user to enter their name
username = input("Your name : ")

while True:
    # Take user input (query) in a chat-like format
    query = input(f"{username} : ")

    # Process the user query and generate a response (returns a string)
    answer = brain.process_messages(query, False)

    # If the user types 'bye', exit the chat loop
    if query.lower() == "bye":
        print(f"Pythonaibrain : {answer}")
        break

    # Display the chatbot's response
    print(f"Pythonaibrain : {answer}")
Enter fullscreen mode Exit fullscreen mode

Step 4: How It Works

  • Brain Initialization: Brain() automatically loads intents.json.
  • Training: brain.train() teaches the AI to recognize patterns and respond.
  • Saving: brain.save() stores the trained model for future use.
  • Chat Loop: Keeps asking the user for input until "bye" is typed.
  • Processing Messages: brain.process_messages(query, False) generates AI responses.

Step 5: Try It Out

Run your Python file:

python chatbot.py
Enter fullscreen mode Exit fullscreen mode

Then start chatting with your AI! Try saying Hi, Hello, or Bye, and watch how it responds intelligently.


Optional Enhancements

  • Add more intents to handle more conversations.
  • Integrate with a GUI (Tkinter or CustomTkinter) for a visual chatbot.
  • Save conversations to a log file.
  • Connect it with Telegram, Discord, or a web app.

Conclusion

Building your own AI chatbot is easier than ever with Pythonaibrain v1.1.8. You’ve learned how to:

  • Define intents in JSON
  • Train and save your chatbot
  • Run an interactive chat loop

Now it’s your turn experiment, add more features, and make your AI smarter! 🚀


For more check it out Pythonaibrain v1.1.8

Top comments (0)