ChatterBot icon indicating copy to clipboard operation
ChatterBot copied to clipboard

Save Chat history conversations in txt file or json file or yml file in python

Open mady143 opened this issue 7 years ago • 6 comments

Hi,

I want to save the chat conversations between user and bot and save it on the txt file or yml file or json format this help in avoid training all the time and i want call this chat history file for further process could any one help in this issue please

Thank you in advance

Happy codding...

mady143 avatar Feb 21 '19 07:02 mady143

This might helpful https://chatterbot.readthedocs.io/en/stable/corpus.html#exporting-your-chat-bot-s-database-as-a-training-corpus

vkosuri avatar Feb 21 '19 07:02 vkosuri

@vkosuri hi this is my code

from flask import Flask, render_template, request from chatterbot import ChatBot from chatterbot.trainers import ChatterBotCorpusTrainer

app = Flask(name)

english_bot = ChatBot("Chatterbot", storage_adapter="chatterbot.storage.SQLStorageAdapter")

english_bot.set_trainer(ChatterBotCorpusTrainer) english_bot.train("./data")

@app.route("/") def home(): return render_template("index.html")

@app.route("/get") def get_bot_response(): userText = request.args.get('msg') reply = str(english_bot.get_response(userText))

if name == "main": app.run()

now i want to save the chat conversations which are from the data folder(contains yml files) and after the conversation is finished i want to save that conversation in one file

could you help me in that way

Thank you in advance

Happy codding....

mady143 avatar Feb 21 '19 08:02 mady143

You can probably do this manually. Every time the user asks a question, add it do a dict. When you get the bot response, add it to the dict as well and so on and so forth. At the end, when the user exists the program, you can export the dict into a file. For example, if you use PyYAML, you can simply do yaml.dump(dict) . Then you can use the resulting .yaml file to train your bot via the ChatterbotCorpusTrainer.

Ligh7bringer avatar Feb 21 '19 12:02 Ligh7bringer

Thank you @Ligh7bringer

mady143 avatar Feb 21 '19 12:02 mady143

Hi every one while i am saving the chat data into a yml file i failed to save the url data how can i save that data in then yml file in chatterbot using python

Thank you in advance ..... Happy codding......

mady143 avatar Mar 25 '19 09:03 mady143

Hi everyone, I want to save the chat conversations which are from the data folder and after the conversation is finished, I want to save that conversation in on file.

mrityunjays1 avatar Aug 11 '21 12:08 mrityunjays1