基于Rasa构建聊天机器人:Ubuntu本地环境下对话数据获取问题
Hey there! I’ve dealt with this exact situation before when testing Rasa bots locally, so let me share a few straightforward ways to grab your conversation data—no need to deploy to a full HTTP server setup.
方法1:直接读取Rasa默认SQLite数据库
When you run rasa shell locally, Rasa automatically stores all conversation events (user messages, bot responses, intent predictions, etc.) in a SQLite database file right in your working directory. Here’s how to access it:
- First, confirm the database exists: Run
ls -lin your bot’s root folder—you should see a file namedrasa.db. - Install SQLite CLI (if you don’t have it):
sudo apt update && sudo apt install sqlite3 - Access the database and query events:
Once in the SQLite shell, run this query to see all conversation data:sqlite3 rasa.dbSELECT * FROM events; - Export to a readable format (like CSV):
Exit the SQLite shell, then run this command to save events to a CSV file:sqlite3 -header -csv rasa.db "SELECT * FROM events;" > conversation_data.csv
方法2:配置文件型事件日志
You can set up Rasa to write all conversation events directly to a JSON log file. Just add this to your config.yml:
event_broker: type: file path: ./conversation_events.log format: json
Restart your bot with rasa shell, and every time a conversation happens, the events will be appended to conversation_events.log in JSON format. You can parse this file with tools like jq (install with sudo apt install jq) to filter or format the data:
jq '.text' conversation_events.log # Extract only user/bot messages
方法3:启用本地API服务(匹配文档场景)
If you want to use the exact workflow mentioned in the Rasa docs, you can run the API server alongside the shell:
- Open a new terminal window, navigate to your bot’s folder, and start the API:
rasa run --enable-api - In your original terminal, run the shell connected to the local API:
rasa shell --endpoint http://localhost:5005
Now you can use the standard conversation tracker endpoints to fetch data—just send requests to http://localhost:5005 using tools like curl or Postman.
内容的提问来源于stack exchange,提问作者Vincent

