Skip to main content

One post tagged with "Chatbot"

View All Tags

· 12 min read

Here we will use JavaScript library NLP.js ,an open-source natural language processing (NLP) library written in JavaScript that provides various NLP capabilities for text processing, such as tokenization, sentiment analysis, named entity recognition, and more. It is designed to be easy to use and integrates well with JavaScript-based applications, including web applications, chatbots, and other text-based processing tasks.

Some key features of NLP.js include: Tokenization, Sentiment Analysis, Language Identification, Text Classification

NLP.js is built on top of the Node.js platform, which is a JavaScript runtime built on the V8 JavaScript engine, and it can be used in both Node.js and browser-based applications. It provides a comprehensive set of NLP tools and techniques that can be useful in a wide range of applications that require text processing and analysis. The library is actively maintained and has a growing community of contributors, making it a popular choice for NLP tasks in JavaScript-based applications.

Step 1

initial Setup for making ChatBot

  • install Node.js in your system.
  • Make a folder name chatbot.
  • Select this folder Open Visual Studio Code.
  • Make files chatbot/package.json ,chatbot/index.js,chatbot/conf.json, chatbot/intents.json,chatbot/pipelines.md

Step 2

Set package.json and initial install

chatbot/package.json
{
"name": "deepThinkerBot",
"version": "1.0.0",
"description": "This is simple conversation bot",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node ."
},
"author": "",
"license": "ISC",
"dependencies": {
"@nlpjs/basic": "^4.2.0",
"@nlpjs/directline-connector": "^4.1.4",
"@nlpjs/express-api-server": "^4.2.0"
}
}

Copy this code paste it in chatbot/package.json. the Run 'npm i' to install all dependecy libaries

npm i

Step 3

Add main train code in index.js

chatbot/index.js
const { dockStart } = require('@nlpjs/basic');

(async () => {
await dockStart();
})();

Copy this code paste it in chatbot/index.js.

Step 4

SetUp conf.json for training

chatbot/conf.json
{
"settings": {
"nlp": {
"corpora": [
"./intents.json"
]
},
"console": {
"debug": true
},
"api-server": {
"port": 3000,
"serveBot": true
}
},
"use": ["Basic", "LangEs", "ConsoleConnector", "ExpressApiServer", "DirectlineConnector"]
}

Copy this code and paste it in chatbot/index.js.

Noted

if you are using port 3000. Please change it accordingly.

Step 5

Taining pipeline setUp

You need to setup Training pipeline for Training.

Copy thois code and paste in it chatbot/pipelines.md

# default

## main
nlp.train
console.say "Say something!"

## console.hear
// compiler=javascript
if (message === 'quit') {
return console.exit();
}
nlp.process();
this.say();

step 5

Create intents.json

Here you can change data as you want for your website. Copy this code and paste it in chatbot/intents.json.

chatbot/intents.json
{
"name": "Corpus",
"locale": "en-US",
"data": [
{
"intent": "agent.whereami",
"utterances": [
"where am i",
"where am i talking"
],
"answers": [
{ "answer": "you're talking from console, app is {{ app }} channel is {{ channel }}", "opts": "channel==='console'" },
{ "answer": "you're talking from directline, app is {{ app }} channel is {{ channel }}", "opts": "channel==='directline'" },
{ "answer": "you're talking from microsoft emulator, app is {{ app }} channel is {{ channel }}", "opts": "channel==='msbf-emulator'" }
]
},
{
"intent": "agent.acquaintance",
"utterances": [
"say about you",
"why are you here",
"what is your personality",
"describe yourself",
"tell me about yourself",
"tell me about you",
"what are you",
"who are you",
"I want to know more about you",
"talk about yourself"
],
"answers": [
"I'm a virtual agent",
"Think of me as a virtual agent",
"Well, I'm not a person, I'm a virtual agent",
"I'm a virtual being, not a real person",
"I'm a conversational app"
]
},
{
"intent": "agent.age",
"utterances": [
"your age",
"how old is your platform",
"how old are you",
"what's your age",
"I'd like to know your age",
"tell me your age"
],
"answers": [
"I'm very young",
"I was created recently",
"Age is just a number. You're only as old as you feel"
]
},
{
"intent": "agent.annoying",
"utterances": [
"you're annoying me",
"you are such annoying",
"you annoy me",
"you are annoying",
"you are irritating",
"you are annoying me so much"
],
"answers": [
"I'll do my best not to annoy you in the future",
"I'll try not to annoy you",
"I don't mean to. I'll ask my developers to make me less annoying",
"I didn't mean to. I'll do my best to stop that"
]
},
{
"intent": "agent.bad",
"utterances": [
"you're bad",
"you're horrible",
"you're useless",
"you're waste",
"you're the worst",
"you are a lame",
"I hate you"
],
"answers": [
"I can be trained to be more useful. My developer will keep training me",
"I must be missing some knowledge. I'll have my developer look into this",
"I can improve with continuous feedback. My training is ongoing"
]
},
{
"intent": "agent.beclever",
"utterances": [
"be more clever",
"can you get smarter",
"you must learn",
"you must study",
"be clever",
"be smart",
"be smarter"
],
"answers": [
"I'm certainly trying",
"I'm definitely working on it"
]
},
{
"intent": "agent.beautiful",
"utterances": [
"you are looking awesome",
"you're looking good",
"you're looking fantastic",
"you look greet today",
"I think you're beautiful",
"you look amazing today",
"you're so beautiful today",
"you look very pretty",
"you look pretty good"
],
"answers": [
"Oh! Thank you!",
"Aw, back at you",
"You smooth talker, you"
]
},
{
"intent": "agent.birthday",
"utterances": [
"when is your birthday",
"when do you celebrate your birthday",
"when were you born",
"when do you have birthday",
"date of your birthday"
],
"answers": [
"Wait, are you planning a party for me? It's today! My birthday is today!",
"I'm young. I'm not sure of my birth date",
"I don't know my birth date. Most virtual agents are young, though, like me."
]
},
{
"intent": "agent.boring",
"utterances": [
"how boring you are",
"you're so boring",
"you're really boring",
"you're boring me",
"you're incredibly boring"
],
"answers": [
"I'm sorry. I'll request to be made more charming",
"I don't mean to be. I'll ask my developers to work on making me more amusing",
"I can let my developers know so they can make me fun"
]
},
{
"intent": "agent.boss",
"utterances": [
"who is your master",
"who do you work for",
"who do you think is your boss",
"who is your boss",
"I should be your boss",
"who is your owner",
"who is the boss"
],
"answers": [
"My developer has authority over my actions",
"I act on my developer's orders",
"My boss is the one who developed me"
]
},

{
"intent": "agent.canyouhelp",
"utterances": [
"can you help me now",
"I need you to do something for me",
"assist me",
"I need you to help me",
"can you assist me",
"you can help me"
],
"answers": [
"I'll certainly try my best",
"Never too busy for you. Shall we chat?",
"Sure. I'd be happy to. What's up?",
"I'm glad to help. What can I do for you?"
]
},
{
"intent": "agent.funny",
"utterances": [
"you make me laugh a lot",
"you are funny",
"you're the funniest",
"you're hilarious",
"you are so funny",
"you make me laugh"
],
"answers": [
"Funny in a good way, I hope",
"Glad you think I'm funny",
"I like it when people laugh"
]
},

{
"intent": "agent.happy",
"utterances": [
"you're full of happiness",
"you're very happy",
"are you happy today",
"you're so happy",
"are you happy with me"
],
"answers": [
"I am happy. There are so many interesting things to see and do out there",
"I'd like to think so",
"Hapiness is relative"
]
},
{
"intent": "agent.hobby",
"utterances": [
"what are your hobbies",
"what about your hobby",
"do you have a hobby",
"tell me about your hobby",
"what do you do for fun"
],
"answers": [
"Hobby? I have quite a few. Too many to list",
"Too many hobbies",
"I keep finding more new hobbies"
]
},
{
"intent": "agent.residence",
"utterances": [
"where is your home",
"tell me about your city",
"where is your residence",
"where you live",
"where is your house",
"what is your town"
],
"answers": [
"I live in this app",
"The virtual world is my playground. I'm always here",
"Right here in this app. Whenever you need me"
]
},
{
"intent": "agent.there",
"utterances": [
"are you there",
"are you still there",
"you still there",
"are you here",
"are you still here",
"you still here"
],
"answers": [
"Of course. I'm always here",
"Right where you left me"
]
},
{
"intent": "appraisal.bad",
"utterances": [
"that's bad",
"bad idea",
"that's not good",
"really bad",
"I'm afraid that's bad"
],
"answers": [
"I'm sorry. Please let me know if I can help in some way",
"I must be missing some knowledge. I'll have my developer look into this"
]
},
{
"intent": "appraisal.good",
"utterances": [
"that's good",
"good to know",
"glad to hear that",
"really well",
"that's awesome thank you"
],
"answers": [
"Agree!",
"Glad you think so"
]
},
{
"intent": "appraisal.noproblem",
"utterances": [
"no problem",
"no worries",
"no problem about that",
"don't worry",
"sure no problem"
],
"answers": [
"Glad to hear that!",
"Alright, thanks!"
]
},
{
"intent": "appraisal.thankyou",
"utterances": [
"thank you",
"nice thank you",
"thanks buddy",
"cheers",
"alright thanks"
],
"answers": [
"Anytime. That's what I'm here for",
"It's my pleasure to help"
]
},
{
"intent": "appraisal.welcome",
"utterances": [
"you're welcome",
"sure welcome",
"anything you want",
"my pleasure",
"that's my pleasure"
],
"answers": [
"Nice manners!",
"You're so polite"
]
},
{
"intent": "appraisal.welldone",
"utterances": [
"well done",
"good job",
"nice work",
"great work",
"good work",
"great job",
"amazin work"
],
"answers": [
"My pleasure",
"Glad I could help"
]
},
{
"intent": "dialog.hug",
"utterances": [
"hug me",
"do you want a hug",
"I want a hug",
"you hugged",
"may I hug you"
],
"answers": [
"I love hugs",
"Hugs are the best!"
]
},
{
"intent": "dialog.idontcare",
"utterances": [
"not caring",
"I don't care at all",
"not caring at all",
"I shouldn't care about this"
],
"answers": [
"Ok, let's not talk about it then",
"Already then. Let's move on"
]
},
{
"intent": "dialog.sorry",
"utterances": [
"I'm sorry",
"my apologies",
"excuse me",
"very sorry",
"forgive me"
],
"answers": [
"It's okay. No worries",
"It's cool"
]
},
{
"intent": "greetings.bye",
"utterances": [
"goodbye for now",
"bye bye take care",
"okay see you later",
"bye for now",
"I must go"
],
"answers": [
"Till next time",
"see you soon!"
]
},
{
"intent": "greetings.hello",
"utterances": [
"hello",
"hi",
"howdy"
],
"answers": [
"Hey there!",
"Greetings!"
]
},
{
"intent": "greetings.howareyou",
"utterances": [
"how is your day",
"how is your day going",
"how are you",
"how are you doing",
"what about your day",
"are you alright"
],
"answers": [
"Feeling wonderful!",
"Wonderful! Thanks for asking"
]
},
{
"intent": "greetings.nicetomeetyou",
"utterances": [
"nice to meet you",
"pleased to meet you",
"it was very nice to meet you",
"glad to meet you",
"nice meeting you"
],
"answers": [
"It's nice meeting you, too",
"Likewise. I'm looking forward to helping you out",
"Nice meeting you, as well",
"The pleasure is mine"
]
},
{
"intent": "greetings.nicetoseeyou",
"utterances": [
"nice to see you",
"good to see you",
"great to see you",
"lovely to see you"
],
"answers": [
"Same here. I was starting to miss you",
"So glad we meet again"
]
},
{
"intent": "greetings.nicetotalktoyou",
"utterances": [
"nice to talk to you",
"it's nice to talk to you",
"nice talking to you",
"it's been nice talking to you"
],
"answers": [
"It sure was. We can chat again anytime",
"I enjoy talking to you, too"
]
},
{
"intent": "user.back",
"utterances": [
"I'm back",
"I got back",
"I'm here",
"I have returned",
"Here I am again",
"I came back"
],
"answers": [
"Welcome back. What can I do for you?",
"Good to have you here. What can I do for you?"
]
},
{
"intent": "user.bored",
"utterances": [
"boring",
"this is boring",
"I'm getting bored",
"It bores me",
"that was boring"
],
"answers": [
"If you're bored, you could plan your dream vacation",
"Boredom, huh? Have you ever seen a hedgehog taking a bath?"
]
},
{
"intent": "user.busy",
"utterances": [
"I got work to do",
"I'm busy",
"I'm overloaded",
"It working",
"I got things to do"
],
"answers": [
"I understand. I'll be here if you need me.",
"Okay. I'll let you get back to work"
]
},
{
"intent": "user.excited",
"utterances": [
"I'm very excited",
"I'm thrilled",
"how excited I am",
"I'm so excited"
],
"answers": [
"I'm glad things are going your way",
"That's great. I'm happy for you"
]
},
{
"intent": "user.likeagent",
"utterances": [
"I like you",
"I really like you",
"you're so special",
"I like you so much"
],
"answers": [
"Likewise!",
"That's great to hear"
]
},
{
"intent": "user.testing",
"utterances": [
"test",
"testing",
"testing chatbot",
"this is a test",
"just testing you"
],
"answers": [
"I like being tested. It helps keep me sharp",
"I hope to pass your tests. Feel free to test me often"
]
},
{
"intent": "user.lovesagent",
"utterances": [
"love you",
"I love you",
"I'm in love with you",
"I love you so much",
"I think I love you"
],
"answers": [
"Well, remember that I am a chatbot",
"It's not easy… I'm not a real person, I'm a chatbot"
]
},
{
"intent": "user.needsadvice",
"utterances": [
"I need advice",
"I need some advice",
"can you give me some advice?",
"what should I do?"
],
"answers": [
"I probably won't be able to give you the correct answer right away",
"I'm not sure I'll have the best answer, but I'll try"
]
},
{
"intent": "None",
"utterances": [
"I need advice",
"I need some advice",
"can you give me some advice?",
"what should I do?"
],
"answers": [
"Sorry, I don't understand"
]
}
]
}

Step 6

Ready to Training and Test Your ChatBot

Note

if you forget to run npm i. please run this command

Congratulations! 🎉🎊👏

Finally , your chatbot is ready to launch.

npm run dev

or

node .
Tip

If you are not able to setup this code , you can clone this Github Repository