AI Assisted Writing

Version 24.0 introduced AI macros using the OpenAI API (hereafter abbreviated as “API”). Version 24.1 introduces an AI assisted writing feature that predicts and autocompletes what you are typing next while composing text. AI autocomplete can reduce typing effort and improve writing speed. I am writing this text using EmEditor and am personally experiencing the convenience of the AI assisted writing feature.

By default, the AI functionality is disabled. To enable this feature, you need to check the Enable AI option on the AI page of the Customize dialog box in EmEditor, and agree to allow OpenAI to process the text data within documents opened in EmEditor. Please read OpenAI’s Privacy Policy, and if you agree, click the Continue button. According to this privacy policy, data sent to the API will not be used for training OpenAI’s models.

Added the “AI” page to the “Customize” dialog box.

Next, enter your API key in the OpenAI API Key text box. If you are logged into OpenAI, you can obtain your API key here. It is recommended to store the API key in the ‘OPENAI_API_KEY‘ environment variable, but if you use the portable version of EmEditor or do not wish to share the key with other apps because you are sharing the computer, you can disable the Use “OPENAI_API_KEY” environment variable option and save the API key exclusively for EmEditor. By default, gpt-4-turbo-preview is the preferred model. It offers more accurate suggestions than gpt-3.5-turbo. For writing in foreign languages, selecting gpt-4-turbo-preview is advisable. Also, to enable this feature, you must activate the AI assisted writing option on the General page of each configuration properties. It is enabled by default for Text, Markdown, and HTML configurations.

Added the “AI assisted writing” checkbox to the “General” page of the configuration properties.

When this feature is enabled, as you type, AI will automatically predict and suggest the next text. The suggested text appears in gray by default, and you can accept the suggestion by pressing the Tab or End key. If you want to accept only part of the suggested text, press the Right arrow key for the number of characters to accept, or Ctrl+Right to accept one word. Pressing the Delete key will remove the first character of the suggested text. Pressing the Esc key or another key cancels the suggestion. Moreover, if you want to force a prediction by AI when no suggested text is displayed, or request a different suggestion, press Ctrl+Space.

Added the ability to complete a word or phrase by using the OpenAI API.

Simply opening a file in EmEditor does not call the API. It only starts calling the API when you begin typing characters. Moreover, the following conditions must all be met to utilize this functionality:

  • Running EmEditor Professional edition
  • The Enable AI option is set
  • The AI assisted writing option is set
  • Not recording or running a macro
  • The Read-only option is turned off
  • No text is selected
  • Not editing a very large file
  • Not in CSV mode
  • Not comparing files
  • The document being edited is active
  • The cursor is at the end of line
  • Have started typing characters
  • After pausing typing (about 100ms)
  • Have not pressed the Esc key to cancel a suggestion
  • Not just clicked elsewhere with the mouse or executed another command

As described above, we aim to minimize the frequency of API usage. However, using the API still incurs a fee payable to OpenAI, calculated in tokens. Each suggestion consumes about 100 tokens for input and about 10 tokens for output. According to current pricing (as of April 2024), using the default gpt-4-turbo-preview model consumes approx. US$0.0013 per instance. Opting for gpt-3.5-turbo significantly reduces the cost to approx. US$0.000065 per instance. For reference, using ChatGPT Plus provided by the same company incurs a monthly fee of US$20 or more, but if you only use the API with EmEditor, you don’t need to pay for ChatGPT Plus. Using AI with EmEditor is unlikely to amount to US$20 a month, making it an economically viable option. Using the AI macro introduced in v24.0, you can ask EmEditor any free-form questions just like with ChatGPT Plus, making it possible to completely replace ChatGPT Plus with EmEditor.