首页 文章

在Rasa Actions中调用自定义函数

提问于
浏览
0

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

我试图在rasa操作文件中调用自定义函数 . 但我收到一个错误,说“名称'isThereAnyErrors'未定义”

这是我的动作课 . 我想从run方法调用areThereAnyErrors函数 . 有人可以帮忙解决这个问题吗?

class ActionDayStatus(Action):

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))

1 回答

  • 0

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

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

相关问题