How to highlight phrase and send to open AI to rewrite?

Hi! I am trying to have a box that says “rewrite” when I highlight a certain phrase in a paragraph of text, and then send it to open AI to rewrite only that phrase.

After receiving the open AI input, I want to display it in the rewrite box and then if user clicks okay, to replace the highlighted text with the new rewritten phrase. How do I do that in Weweb?

Oooohhh love the use case! But no idea :sweat_smile: Let me ask around and get back to you on that one :slight_smile:

You would need to do something like this inside a custom JS Action Workflow, then you would be able to get the data in the next block in the Results


var text = "";
if (wwLib.getFrontWindow().getSelection) {
  text = wwLib.getFrontWindow().getSelection().toString();
} else if (wwLib.getFrontDocument().selection && wwLib.getFrontDocument().selection.type != "Control") {
  text = wwLib.getFrontDocument().selection.createRange().text;
}
return text;

I just tested it into the console, but it seems to be workable with.

1 Like

Ohhhhh, I see now. How do I get a “toolbar” to appear on top of the cursor, so that the user can click on “Rewrite” and then we can send that off to Open AI?

You could to if(text.length) … show your toolbar
This will check if the text.length of your highlight is > 0, but it’s just an idea, there might be better ways :slight_smile:

Oo. Good idea. How do I get the container to show up just on where I’ve highlighted?