Action

ChatGPT: Modify Draft

Posted by spryfoci, Last update over 1 year ago

This action prompts the user for a text manipulation instruction and requests ChatGPT to perform that instruction on the entire text of the current draft note. The result from ChatGPT is then appended to the end of the draft, on a new line. This is an effective way to perform complex text transformations on your notes using natural language instructions.

For example, if you run this action on a draft note with the text “Hello world! I’m testing this action.”, and provide the instruction “Translate into Spanish” when prompted, the action will append the translated text “¡Hola mundo! Estoy probando esta acción.” to the end of the draft.

This action is a modification of the “ChatGPT: Modify Selection” action by agiletortoise, available here. The original action worked on a selection of text in the draft, while this modified version works on the full draft text.

ChatGPT was used to write this updated script.

Steps

  • script

    // get the full text of the current draft note
    const draftText = editor.getText()
    
    let f = () => {
    	let p = new Prompt()
    	p.title = "ChatGPT: Modify Draft"
    	p.message = "What do you want ChatGPT to do with the entire draft note?"
    	p.addTextView("instruction", "ChatGPT Prompt", "")
    	p.addLabel("caption", "Provide an instruction to transform the entire draft note, for example `capitalize`, `translate into spanish`")
    	p.addButton("Modify")
    	
    	if (!p.show()) {
    		return false
    	}
    	const instruction = p.fieldValues["instruction"]
    	if (instruction == 0) { return false }
    
    	// build prompt with instruction and draftText
    	let chatPrompt = `${instruction} the following text, returning only the result: ${draftText}`
    	// send that to ChatGPT
    	let ai = new OpenAI()
    	let answer = ai.quickChatResponse(chatPrompt)
    
    	// if we got no reply, cancel
    	if (!answer || answer.length == 0) {
    		return false
    	}
    	
    	// append the result to the end of the draft note
    	editor.setText(editor.getText() + "\n" + answer)
    	return true
    }
    
    if (!f()) {
    	context.fail()
    }
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.