获取 RASA 中的意图值 Core/NLU
Get Intent Value in RASA Core/NLU
问候语
我正在研究 RASA 聊天机器人。我正在使用以下代码处理特定意图的自定义操作。在自定义操作中,我想获取当前的意图值。所以我不知道那行代码可以给我当前意图的价值
#this file will be used to all custom actions
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import requests
import json
from zeep import Client
from random import randint
from rasa_core.actions.action import Action
from rasa_core.events import SlotSet
class ActionWeather(Action):
RANDOMIZE = False
@staticmethod
def required_fields():
return [
EntityFormField("period", "period"),
EntityFormField("product", "product")
]
def name(self):
return 'action_weather'
def run(self,dispatcher, tracker, domain):
#Get Slot values
loc = tracker.get_slot('period')
pro = tracker.get_slot('product')
custname= tracker.get_slot('custName')
#Here I want to get Intent Values as well same like slot value in above code
# So what is code for getting intent value
#make json
data = {}
data['period'] = loc
data['product'] = pro
json_data = json.dumps(data)
jsonobj= json.loads(json_data)
#code for SOAP
client = Client('my webservice URL/testsoap?wsdl')
result = client.service.getData(json_data)
print('**********************')
print(result)
print('#######################')
jsonobj= json.loads(result)
#print(response.content)
#json_response = response.json()
#print (json_response)
result1=jsonobj[0]['result']
#result1=randint(1, 100)
#result='X'
response = """sale is {} """.format(result1)
dispatcher.utter_message(response)
#return [SlotSet('location',loc)]
return []
我想在 RASA Core 中获取当前和最后的意图值,就像我们在 python 自定义操作代码中获取槽值 product = tracker.get_slot('product')
一样。请帮忙。
您可以使用类似下面的内容,
currentIntent = tracker.latest_message.intent["name"]
这对我有用:
def run(self,dispatcher, tracker, domain):
intent = tracker.latest_message['intent'].get('name')
rasa-core 0.11.12
rasa-core-sdk 0.11.5
rasa-nlu 0.13.7
intent = json.dumps(tracker.latest_message.intent)
print(intent)
#particular intent name
print(json.loads(intent)['intent']['name'])
结果
(u'{"confidence": 0.9092543377510975, "name": "greet"}')
或者试试这个
intent = json.dumps(tracker.latest_message.__dict__)
问候语 我正在研究 RASA 聊天机器人。我正在使用以下代码处理特定意图的自定义操作。在自定义操作中,我想获取当前的意图值。所以我不知道那行代码可以给我当前意图的价值
#this file will be used to all custom actions
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import requests
import json
from zeep import Client
from random import randint
from rasa_core.actions.action import Action
from rasa_core.events import SlotSet
class ActionWeather(Action):
RANDOMIZE = False
@staticmethod
def required_fields():
return [
EntityFormField("period", "period"),
EntityFormField("product", "product")
]
def name(self):
return 'action_weather'
def run(self,dispatcher, tracker, domain):
#Get Slot values
loc = tracker.get_slot('period')
pro = tracker.get_slot('product')
custname= tracker.get_slot('custName')
#Here I want to get Intent Values as well same like slot value in above code
# So what is code for getting intent value
#make json
data = {}
data['period'] = loc
data['product'] = pro
json_data = json.dumps(data)
jsonobj= json.loads(json_data)
#code for SOAP
client = Client('my webservice URL/testsoap?wsdl')
result = client.service.getData(json_data)
print('**********************')
print(result)
print('#######################')
jsonobj= json.loads(result)
#print(response.content)
#json_response = response.json()
#print (json_response)
result1=jsonobj[0]['result']
#result1=randint(1, 100)
#result='X'
response = """sale is {} """.format(result1)
dispatcher.utter_message(response)
#return [SlotSet('location',loc)]
return []
我想在 RASA Core 中获取当前和最后的意图值,就像我们在 python 自定义操作代码中获取槽值 product = tracker.get_slot('product')
一样。请帮忙。
您可以使用类似下面的内容,
currentIntent = tracker.latest_message.intent["name"]
这对我有用:
def run(self,dispatcher, tracker, domain):
intent = tracker.latest_message['intent'].get('name')
rasa-core 0.11.12
rasa-core-sdk 0.11.5
rasa-nlu 0.13.7
intent = json.dumps(tracker.latest_message.intent)
print(intent)
#particular intent name
print(json.loads(intent)['intent']['name'])
结果 (u'{"confidence": 0.9092543377510975, "name": "greet"}')
或者试试这个
intent = json.dumps(tracker.latest_message.__dict__)