1

我的天气机器人遇到了问题。除了在指定位置后进行天气预报的动作之外,对话运行良好,这实际上是主要动作。我正在使用 Apixu 进行天气预报

当我运行在线培训时,我收到此错误:

ERROR:rasa_core.processor:Encountered an exception while running action 'action_weather'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.

这是我的天气预报动作的python脚本:

from __future__ import absolute_import from __future__ import division
__future__ import unicode_literals


from rasa_core.actions.action import Action from rasa_core.events
import SlotSet from apixu.client import ApixuClient

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

     def run(self, dispatcher, tracker, domain):

         api_key = '6******************'
         client = ApixuClient(api_key)

         loc = tracker.get_slot('location')
         current = client.getCurrentWeather(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)]

这是我的天气域文件,它是一个 yaml 文件

 slots:   location:
     type: text


 intents:
  - greet
  - goodbye
  - inform


 entities:
  - location

 templates:   utter_greet:
     - 'Hello! How can I help?'   utter_goodbye:
     - 'Talk to you later.'
     - 'Bye bye :('   utter_ask_location:
     - 'In what location?'



 actions:
  - utter_greet
  - utter_goodbye
  - utter_ask_location
  - actions.ActionWeather

请问有什么想法吗?

4

1 回答 1

0

由于您的机器人在 Python 中,因此该程序使用 ruamel.yaml 或 PyYAML 来解析 YAML 文件。

如果您尝试解析您的 YAML 文件,很明显它在第一行是无效的:

import ruamel.yaml
yaml = ruamel.yaml.YAML()

yaml_str = """\
 slots:   location:
     type: text
"""

data = yaml.load(yaml_str)

给出:

ruamel.yaml.scanner.ScannerError: mapping values are not allowed here
  in "<unicode string>", line 1, column 19:
     slots:   location:
                      ^ (line: 1)

您也可以在线尝试。

您的机器人很可能会捕捉到这些错误,但没有对它们采取适当的措施。

于 2018-06-29T17:16:48.923 回答