Мой чат-бот не может получить доступ к API - PullRequest
0 голосов
/ 29 июня 2018

У меня возникла проблема с моим ботом Weather. Разговор работает нормально, за исключением действия по прогнозированию погоды после указания местоположения, которое на самом деле является основным действием. Я использую 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

Есть идеи, пожалуйста?

1 Ответ

0 голосов
/ 29 июня 2018

Поскольку ваш бот работает на Python, программа использует для анализа файла YAML файл ruamel.yaml или PyYAML.

Если вы попытаетесь проанализировать 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)

Вы также можете попробовать это онлайн .

Ваш бот, скорее всего, ловит эти ошибки, но не предпринимает надлежащих действий по ним.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...