In your script, there are variables that are not used in the script.But, your function completion(prompt) works fine. Unfortunately, I cannot know your function completion(prompt).You want to replace the selected text with generatedText = completion(prompt).How can I replace the whole selection with a new text? Get the completion prompt from OpenAI API requestĬurrentPosition.insertText(generatedText.toString()) Get the body of the document and the prompt for the OpenAI API requestĬonst prompt = doc.getSelection().getRangeElements().getElement().asText().getText() Get the active Google Docs document and the user-selected textĬonst doc = DocumentApp.getActiveDocument() Ĭonst userText = doc.getSelection().getRangeElements().getElement().asText().getText() I guess that this is due to the fact that selection is nothing to do with cursor position. TypeError: Cannot read properties of null (reading 'insertText') The script will work fine but I cannot update the current selection, as I get the following error I'm trying to write an app script to replace the current text selection with a new AI generated text, via menu item.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |