我正在尝试使用RASA学习和创建聊天机器人,该聊天机器人必须将cmdline的输入传递给显示为Flask API的Python数据帧,并返回响应。
所有小片段都可以很好地工作,但是当我缝合在一起时,我无法将输入参数从RASA cmdline传递给熊猫。
以下是到目前为止我所做的的总体摘要:
class ActionBookSearch(Action): def name(self): return 'action_genre_search' def run(self, dispatcher, tracker, domain): import pyflask_api ### File name of the Python Flask code genre_val = tracker.get_slot('genre') ### Defined slots in domain.yml print(genre_val) ### This always gives None :( That's the issue. Not able to get the value from cmdline genre_results = pyflask_api.get_genre(genre="Action") ### Method present in pyflask_api.py code if genre_results: dispatcher.utter_message(genre_results) return [SlotSet("genre", genre_results if genre_results is not None else "Nothing Matched. Please Try again")]
解决方法:
由于无法从Bot cmdline获取值,因此我在下面的行中进行了硬编码以进行检查:
genre_results = pyflask_api.get_genre(genre =“ Action”)
该值将转至Flask代码,并从Panda数据框中提取数据,并将响应成功返回到命令行。
需要做什么:
所以只有待处理的事情是我应该从cmdline成功获取值,以便每当在action.py代码中执行print(genre_val)时,它都应该返回从cmdline获取的值,而不是像现在那样返回“ None”。
更新:
domain.yml的内容:
entities:
- genre
slots:
genre:
type: text
action_factory: remote
intents:
- greet
- book_search
- thanks
- goodbye
actions:
- utter_greet
- utter_goodbye
- action_genre_search
- utter_happy_reading
stories.md的内容:
#create your story here
## greet
* greet
- utter_greet
## get genre
* book_search{"genre": "Fantasy"}
- action_genre_search
## good bye
* goodbye
- utter_goodbye
## Thank you
* thanks
- utter_happy_reading
nlu_data.md的内容:
## intent:greet
- hey
- hello
## intent:book_search
- I want to read some Fantasy books
- I want to read some Classics books
- I want to read some Fictional books
## intent:thanks
- perfect
- very good
## intent:goodbye
- bye
答案 0 :(得分:0)
您必须annotate your NLU examples,例如:
## intent:book_search
- I want to read some [Fantasy](genre) books
- I want to read some [Classics](genre) books
- I want to read some [Fictional](genre) books
此外,您还必须添加更多示例以使实体提取更加可靠。 为此,请确保ner_crf在您的NLU管道中。