实施问题 Sql_tracker_store

Issue implementing Sql_tracker_store

我想使用 sql 跟踪器存储将对话历史记录存储在数据库中,但它似乎对我不起作用。 我有 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)

请帮我解决这个问题。

您需要将 dialect 更改为使用 MySQL 和 db 以在 endpoint.yml 中包含 .db 后缀:

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

SQLALchemy 文档中的更多信息

您需要使用pip安装pymysql。

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