Insert slot value without return[SlotSet()]

Hi, I want to insert slot value without using return[SlotSet(' ',..)]. How can I do that between the code?

Is there something like tracker.set_slot()

1 Like

you should do it with returning events as you mentioned

yeah I know it is in good practice but for setting that slot value I have to create a new custom action which don’t have any other work except setting slot value. That’s why I am searching for new method to setting slot.

Resolved!!! tracker.slots[update_slot] = None

Checked with print slot is set but having an issue that it does not save slot in stories, stories have old slot values. Will try to resolve later.

It should be return [SlotSet(update_slot, None)]

@Ghostvv Yeah that’s the another and popular method but there are some people who need to fix the slots using tracker.slots[] method because they want to update slot in the middle of custom_action. I am trying to help those people.

P.S. Resolved my issue by using SlotSet method. Saw other posts so trying to help them.

I am trying to update the slots in the middle of custom_action, i have tried as you mentions above but i am facing the below error “TypeError: Object of type SlotSet is not JSON serializable” . Please help to resolve this issue. complete error as follows:

ERROR:flask.app:Exception on /webhook [POST] Traceback (most recent call last): File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\app.py”, line 2292, in wsgi_app response = self.full_dispatch_request() File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\app.py”, line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask_cors\extension.py”, line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\app.py”, line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask_compat.py”, line 35, in reraise raise value File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\app.py”, line 1813, in full_dispatch_request rv = self.dispatch_request() File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\app.py”, line 1799, in dispatch_request return self.view_functionsrule.endpoint File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask_cors\decorator.py”, line 128, in wrapped_function resp = make_response(f(*args, **kwargs)) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\rasa_core_sdk\endpoint.py”, line 91, in webhook return jsonify(response) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\json_init_.py”, line 321, in jsonify dumps(data, indent=indent, separators=separators) + ‘\n’, File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\json_init_.py”, line 179, in dumps rv = json.dumps(obj, **kwargs) File "C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\simplejson_init.py", line 399, in dumps **kw).encode(obj) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\simplejson\encoder.py”, line 296, in encode chunks = self.iterencode(o, _one_shot=True) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\simplejson\encoder.py”, line 378, in iterencode return iterencode(o, 0) File "C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\json_init.py", line 81, in default return _json.JSONEncoder.default(self, o) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\simplejson\encoder.py”, line 273, in default o.class.name) TypeError: Object of type SlotSet is not JSON serializable.

Please help me, Thanks in advance.

Can you send me your code line like what you typed?

Thank you for your response, when I am trying to update slots in middle of functions I got the above issue, now issue is resolved when I replace the return step as follows - return[SlotSet(’ ',…)]. Thank You.

1 Like

so, when you update tracker.slots, you change the local copy of tracker, that is passed to the custom action, in order to notify rasa_core that the slot has changed, you need to return SlotSet event

2 Likes

Yeah, Thanx @Ghostvv for clarifying it.

Resolved!!!