Pre Process and update user message

Hi,

I’m trying to get some preprocessing done to the user message. I have built a custom component and added in my config right before the Tokenizer and after SpacyNLP. I need to do some processing on the user message that I get from the message object like so message.get(SPACY_DOCS[attribute]) using TEXT as the attribute.

After doing some processing on this I was to place the updated message back into it. I tried message.set(SPACY_DOCS[TEXT], fixed_doc) but I keep getting TypeError on the argument. Can someone please guide me on how can I go about this, what type should be the argument and how do I make sure that it is that type when I pass it? It is currently a string.

The flow:

  1. get doc
  2. do some processing on the message (a string)
  3. place this string back in the message as the updated user message

An urgent help on this will be appreciated please.

Hi @iszainab!

I’m assuming that you want to update the text of the message.

Try using:

message.text = your_new_string

Hope that helps :slightly_smiling_face:

Yes I’ve done that. Thank you.

I’ve changed the solution to a much simpler one now. I’ve taken my custom component right at the top so I only need to do message.text = new_string now. SpacyNLP is being called later so I don’t need to worry about the data and other properties of the message object.

Nice trick! :+1: :slightly_smiling_face:

Hello @saurabh-m523 an you share how you have done that I also want to preprocess the data but have no idea how to do