OpenAI: Write Code

Posted by agiletortoise, Last update about 1 month ago

Submit the selected text as instructions to generate code with the edit endpoint, and insert the response. Things like “Write JavaScript function to return the square root of a number”, etc.

For more information on using this action, visit our OpenAI integration guide


  • script

    // get editor values
    const [st, len] = editor.getSelectedRange()
    const instruction = editor.getSelectedText()
    // create OpenAI API object and use single response
    // convenience function to send prompt
    let ai = new OpenAI()
    let answer = ai.quickCodeEdit("", instruction)
    // if we got a reply, add it to the draft
    if (answer) {
    	let newValue = `\`\`\`
    	editor.setSelectedRange(st, newValue)
    else {


  • 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.