问题描述
我正在尝试使用 api 获取当前温度,并传递位置槽。我只使用了 spacy 管道。我可以从操作 CLI 中看到正在执行自定义操作,并获取我打印的温度。那为什么会出现这个错误?
pipeline:
- name: "SpacyNLP" # Language model
- name: "SpacyTokenizer" # Tokenizer
- name: "SpacyFeaturizer" # Featurizer
- name: "SpacyEntityExtractor" #Entity Extractor
- name: "EntitySynonymMapper" # Maps synonymous entity values to the same value.
- name: "SklearnIntentClassifier" # Sklearn intent classifier
nlu.yml
- intent: get_weather
examples: |
- what's the weather in [Kolkata](GPE)
- what's the weather in [Mumbai](GPE)
- what is the weather in [Delhi](GPE)
- what is the weather in [Kolkata](GPE)
- whats the weather in [Kolkata](GPE)
- whats the weather in [Delhi](GPE)
故事.yml
- story: weather path
steps:
- intent: get_weather
- action: action_weather
域.yml
slots:
PERSON:
type: text
GPE:
type: text
entities:
- PERSON
- GPE
intents:
- greeting
- how_are_you
- bye
- my_name_is
- get_weather
actions: # actions define the responses of your bot.
- utter_greeting # Simple text response names start with utter_.
- utter_how_i_am
- utter_bye
- utter_its_nice_to_meet_you
- action_weather
responses:
utter_greeting:
- text: "Hi! Could you please help me with your name?"
- text: "Hello,my friend. What can I call you?"
utter_how_i_am:
- text: "I am doing ok."
- text: "I am good."
utter_bye:
- text: "Bye."
- text: "Good bye."
utter_its_nice_to_meet_you:
- text: "It's nice to meet you,{PERSON}."
- text: "Nice to meet you,{PERSON}."
actions.py
from typing import Any,Text,Dict,List
from rasa_sdk import Action,Tracker
from rasa_sdk.executor import Collectingdispatcher
import requests
class ActionGetWeather(Action):
def name(self):
return "action_weather"
def run(self,dispatcher: Collectingdispatcher,tracker: Tracker,domain: Dict[Text,Any]) -> List[Dict[Text,Any]]:
location = tracker.get_slot("GPE")
#person = tracker.get_slot("PERSON")
params = {"appid": "xxxxxxxx",'q': location,"units": "metric"}
response = requests.get("https://api.openweathermap.org/data/2.5/weather",params = params).json()
temp = str(response['main']['temp'])
print(temp)
dispatcher.utter_message(temp)
return []
附上错误截图
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)