You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rasa运行actions.py报错:NameError: name 'null' is not defined求助

Rasa actions.py执行报错:NameError: name 'null' is not defined(代码中未出现null)

执行rasa run actions时持续触发以下错误:

line 46, in "execution_count": null, NameError: name 'null' is not defined

但我的actions.py代码中并未包含null字样,代码如下:

from typing import Any, Text, Dict, List
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
import pandas as pd

class Action_Train_Model(Action):
    def name(self) -> Text:
        return "action_train_model"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        df = pd.read_excel('C:/Users/ahmed.gabr/myenv/Tetuan City power consumption.xlsx')

        X_train, X_test, y_train, y_test = train_test_split(df[['Temp', 'Wind Speed']], df['Power consumption'], test_size=0.2, random_state=42)

        rf = RandomForestRegressor(n_estimators=100, random_state=42)
        rf.fit(X_train, y_train)

        tracker.slots["model"] = rf

        dispatcher.utter_message(text="Model trained successfully.")

        return []

class Action_Test_Model(Action):
    def name(self) -> Text:
        return "action_test_model"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        rf = tracker.get_slot("model")

        test_data = pd.read_excel('C:/Users/ahmed.gabr/myenv/Tetuan City power consumption.xlsx')

        predictions = rf.predict(test_data[['Temp', 'Wind Speed']])
        response = "Predictions: {}".format(predictions)
        dispatcher.utter_message(text=response)

        return []

已尝试的解决方法

  • 确认Excel文件路径正确
  • 将文件保存为actions.ipynb后再导出为.py文件
  • 在Jupyter Notebook中逐段运行代码排查错误
  • 确保actions.py中的动作名称与domain.yml中的配置完全匹配
  • 确认actions.py文件位于Rasa项目根目录下

预期结果

希望执行rasa run actions时无报错,正常启动action服务,以便继续与机器人交互。

内容的提问来源于stack exchange,提问作者ahmed hamdy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 19:52:12