问题实现Sql_tracker_store

时间:2019-07-30 08:55:14

标签: rasa-nlu rasa-core rasa

我想使用sql tracker存储将对话历史记录存储在db中,但似乎对我不起作用。 我有要连接的MySQL数据库,我在endpoint.yml中使用以下代码

tracker_store:
    type: SQL
    dialect: "sqlite"  # the dialect used to interact with the db
    url: "localhost"  # (optional) host of the sql db
    db: "chatbot"  # path to your db
    username: "root"  # username used for authentication
    password: "test"  # password used for authentication

我在跑步rasa shell -m models --endpoints endpoints.yml时 我遇到错误了。

" sqlite:////absolute/path/to/file.db" % (url,)
sqlalchemy.exc.ArgumentError: Invalid SQLite URL: sqlite://root:test@localhost/c
hatbot
Valid SQLite URL forms are:
 sqlite:///:memory: (or, sqlite://)
 sqlite:///relative/path/to/file.db
 sqlite:////absolute/path/to/file.db

当我尝试使用python代码连接相同的数据库时,它为我工作。下面是我的python代码。

import mysql.connector

mydb = mysql.connector.connect(host="localhost",port="3306",user="root",database="chatbot",password="test")
mycursor = mydb.cursor()

sql = "Show tables;"

mycursor.execute(sql)
myresult = mycursor.fetchall()
print(myresult)
for x in myresult:
    print(x)

请帮助我如何解决这个问题。

2 个答案:

答案 0 :(得分:1)

您需要更改dialect以使用MySQL,并需要更改db以在您的.db中包含后缀endpoint.yml

tracker_store:
    type: SQL
    dialect: "mysql"  # the dialect used to interact with the db
    url: somewhere    
    db: "chatbot.db"  
    username: "root"  
    password: "test"  

SQLALchemy文档?

中的更多信息

答案 1 :(得分:0)

您需要使用pip安装pymysql。

    tracker_store:
        type: SQL
        dialect: "mysql+pymysql"
        url: "localhost"
        db: "Rasabot"
        username: "root"
        password: "xyz"