我的天气机器人遇到了问题。除了在指定位置后进行天气预报的动作之外,对话运行良好,这实际上是主要动作。我正在使用 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
请问有什么想法吗?