在 Rasa Actions 中调用自定义函数

Calling a custom function in Rasa Actions

我在使用 rasa 开发聊天机器人时遇到问题。

我正在尝试调用 rasa 操作文件中的自定义函数。但是我收到一条错误消息 "name 'areThereAnyErrors' is not defined"

这是我的操作 class。我想从 运行 方法调用 areThereAnyErrors 函数。有人可以帮忙解决这个问题吗?

class 动作日状态(动作):

def areThereAnyErrors(procid):
    errormessagecursor = connection.cursor()
    errormessagecursor.execute(u"select  count(*) from MT_PROSS_MEAGE where pro_id = :procid and msg_T =    :messageT",{"procid": procid, "messageT": 'E'})
    counts = errormessagecursor.fetchone()
    errorCount = counts[0]
    print("error count is {}".format(errorCount))
    if errorCount == 0:
        return False
    else:
        return True

def name(self):
    return 'action_day_status'

def run(self, dispatcher, tracker, domain):
    import cx_Oracle
    import datetime
        # Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
    conn_str = dbconnection
    connection = cx_Oracle.connect(conn_str)
    cursor = connection.cursor()
    dateIndicator = tracker.get_slot('requiredDate')
    delta = datetime.timedelta(days = 1)
    now = datetime.datetime.now()
    currentDate = (now - delta).strftime('%Y-%m-%d')
    print(currentDate)
    cursor = connection.cursor()

    cursor.execute(u"select  * from M_POCESS_FILE where CREATE_DATE >= TO_DATE(:createDate,'YYYY/MM/DD') fetch first 50 rows only",{"createDate":currentDate})

    all_files = cursor.fetchall()
    total_number_of_files = len(all_files)

    print("total_number_of_files are {}".format(total_number_of_files))

其中一位知识分子给出的答案:

https://realpython.com/instance-class-and-static-methods-demystified/ 决定是要静态方法还是 class 方法或实例方法并适当地调用它。此外,当您在函数中使用连接时,它应该是一个成员变量或传递给方法您没有 self 作为参数,因此您可能打算将它作为静态方法 - 但您没有这样创建它