chatbot - 在 Rasa Actions 中调用自定义函数
问题描述
我在使用 rasa 开发聊天机器人时遇到问题。
我正在尝试在 rasa 操作文件中调用自定义函数。但我收到一条错误消息,提示“未定义名称‘areThereAnyErrors’”
这是我的动作课。我想从 run 方法调用 areThereAnyErrors 函数。有人可以帮忙解决这个问题吗?
类 ActionDayStatus(动作):
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/决定是否需要静态方法或类方法或实例方法并适当地调用它。此外,当您在函数中使用连接时,它应该是成员变量或传递给方法您没有 self 作为参数,因此您可能打算将其作为静态方法 - 但您没有这样创建它
推荐阅读
- c# - 为什么 C# 将隐式类型变量转换为可空类型?
- docker - 在集群上的 Singularity 容器中运行的 MPI 程序
- google-cloud-platform - 更改 Google Cloud 上的 Littlest Jupyterhub 登录页面
- python - Spyder ide:在try except子句中包围选定的代码块
- pine-script - 尝试在 Pine 脚本中制作一个在不同时间尺度上工作的 RSI 指标
- laravel - 如何选择图像干预应该存储的图像?
- python - 尝试使用 SQLite 数据库和 Python 按顺序为每个项目创建记录
- sql - SQL-自动插入自定义记录
- reactjs - React 和 core-js 不能为 IE10 填充
- python - 试图通过运行函数来找到列表中一对数字的概率?