Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Intent Value in RASA Core/NLU

Greeting I am working on RASA chatbot. I am handling Custom actions for a particular intent using below code. In the custom action I want to get current intent value. SO i dont know that line of code which can give me value of current intent

#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 []

I want to get current and last value of intent in RASA Core in same way as we can get slots value product = tracker.get_slot('product') in python custom action code. Please help.

like image 504
ASING Avatar asked Jan 27 '23 16:01

ASING


2 Answers

This works for me:

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

like image 148
Veliander Avatar answered Jan 31 '23 21:01

Veliander


intent = json.dumps(tracker.latest_message.intent)
print(intent)
#particular intent name
print(json.loads(intent)['intent']['name'])

outcome (u'{"confidence": 0.9092543377510975, "name": "greet"}')

or try this

        intent = json.dumps(tracker.latest_message.__dict__)
like image 25
hepzi Avatar answered Jan 31 '23 23:01

hepzi