rasa.core.处理器运行操作“action\u weather”时遇到异常

2024-05-19 10:09:40 发布

您现在位置:Python中文网/ 问答频道 /正文

rasa.core.processor-运行操作“action\u weather”时遇到异常。Bot将继续,但操作事件将丢失。确保修复自定义代码中的异常。你知道吗

你知道吗动作.py你知道吗

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function

from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet

class ActionWeather(Action):
    def name(self):
        return 'action_weather'

    def run(self, dispatcher, tracker, domain):
        from apixu.client import ApixuClient
        api_key = '5c84ed6c89dd48909d862228192607' #your apixu key
        client = ApixuClient(api_key)

        loc = tracker.get_slot('location')
        current = client.current(q=loc)

        country = current['location']['country']
        city = current['location']['name']
        condition = current['current']['condition']['text']
        temperature_c = current['current']['temp_c']
        humidity = current['current']['humidity']
        wind_mph = current['current']['wind_mph']

        response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph)

        dispatcher.utter_message(response)
        return [SlotSet('location',loc)]

这是端点

action_endpoint:
  url: "http://localhost:5055/webhook/"

当我询问天气时,它给出了一些错误,我使用的是rasa版本1.1.4和python版本3.7.3


Tags: keyfromcoreimportclientisfutureaction

热门问题