Я создаю простого чат-бота с Python и библиотекой chatterbot.Я смог заставить что-то работать, когда пользователь что-то вводит, и бот отвечает на основе .json
шаблонов и ответов.
Каждый раз, когда я выполняю бот, он может сказать, какой "тег"Пользовательский ввод и отвечает соответственно только в этом формате: "patterns": ["cya", "See you later", "Goodbye", "I am Leaving", "Have a Good day"],
Но я хотел бы удалить цитаты, запятые и т. д. и просто выбрать один ответ наугад.Я пробовал эту вещь токенизации?Кажется, не работает
Код
## MODULES
from chatterbot import ChatBot #This imports the chatbot
from chatterbot.trainers import ListTrainer #Method used for training the chatbot
import chatterbot #Just in case
import os
## BOT VARIABLES
bot = ChatBot("Test") #This creates the chatbot and names it 'Test'
trainer = ListTrainer(bot) #Creates the trainer
data = "C:/Users/PAVILION/Desktop/ChatBotTest2/INTS/"
for files in os.listdir(data):
conv = open(data + files, 'r').readlines() #This opens the direrctory full of data
trainer.train(conv) #This trains the chatbot trainer with data from the directory
## CHATTERBOT OUTPUT
while True:
message = input("You: ")
if message.strip() != "Bye":
response = bot.get_response(message)
print("ChatBot: ", response)
if message.strip() == "Bye":
print("ChatBot: Farewell")
break
Intentions.json
{"intents": [
{"tag": "greeting",
"patterns": ["Hi", "How are you", "Is anyone there?", "Hello", "Good day", "Whats up"],
"responses": ["Hello!", "Good to see you again!", "Hi there, how can I help?"],
"context_set": ""
},
{"tag": "goodbye",
"patterns": ["cya", "See you later", "Goodbye", "I am Leaving", "Have a Good day"],
"responses": ["Sad to see you go :(", "Talk to you later", "Goodbye!"],
"context_set": ""
},
{"tag": "age",
"patterns": ["how old", "how old is tim", "what is your age", "how old are you", "age?"],
"responses": ["I am 18 years old!", "18 years young!"],
"context_set": ""
},
{"tag": "name",
"patterns": ["what is your name", "what should I call you", "whats your name?"],
"responses": ["You can call me Tim.", "I'm Tim!", "I'm Tim aka Tech With Tim."],
"context_set": ""
},
{"tag": "shop",
"patterns": ["Id like to buy something", "whats on the menu", "what do you reccommend?", "could i get something to eat"],
"responses": ["We sell chocolate chip cookies for $2!", "Cookies are on the menu!"],
"context_set": ""
},
{"tag": "hours",
"patterns": ["when are you guys open", "what are your hours", "hours of operation"],
"responses": ["We are open 7am-4pm Monday-Friday!"],
"context_set": ""
}
]
}
json был получен из Tech с руководством по Тимукстати.