Drafts is a quick-capture note app. This site is dedicated to sharing information about how to use and extend Drafts. For more information, visit getdrafts.com

1 / 82
Mar 2023

Since the release of ChatGPT API on March 1st, I see the possibility that it can be a replacement for ChatGPT web for everyday use. So here I am, presenting to you the ChatGPT Conversation Action:

ChatGPT Conversation | Drafts Directory 617

Features

  • Conversational chat in a draft, just like what ChatGPT web does
  • Define the system role message to clarify the usage of the conversation for better results. This is made possible through the role property in the new API docs 54.
  • Update or delete the history message in the drafts to continuously improve the result you’ll get. While ChatGPT web cannot update or delete the history very efficiently.

Usage

First, install the action from the directory. Upon running the action, the OpenAI API key is required, which can be obtained from https://platform.openai.com/account/api-keys 153.

The simplest way to use it is to create a new draft and type whatever you would like to ask. Then, call the action, and the result will be appended to the end of the draft.

You can also add <!-- block system --> at the top of the draft to tell ChatGPT what you want it to be. There are some curated prompts for your inspiration in this repo: Awesome ChatGPT Prompts 162

Note that the messages ChatGPT returns will be wrapped in <!-- block assistant -->. The action will recognize them as assistant role messages and send them to the ChatGPT API as part of the conversation. So, don’t make the conversation too long; otherwise, the token will be consumed very quickly.

You can change the default behavior of using the whole draft as the context in the conversation by setting the template tag keep-context to false. This will make the action only send the system role message and the last user role message to ChatGPT API.

Here’s a screen record of how ChatGPT understands the context:

drafts-chatgpt

Enjoy!


Update notice 2023-03-11

  1. I’ve created a new template tag for the API called api-base-url. It serves as the default base URL for the API, which is set to https://api.openai.com/v1/. However, it can be altered to another URL if necessary. Please note this change if you intend to use a custom API URL.
  2. I’ve created another action called System Message Template 59. It simply creates a new draft with <!-- block system --> block so that you don’t need to copy-paste it every time.

Update notice 2023-04-08

  1. Template tag api-base-url was moved to credentials, meaning you should configure it when initializing this action. It’s called “OpenAI API Base URL (optional)”, as the name says, you can omit this option.
read 10 min

It is my pleasure to contribute something useful to the community. Thank you for continuously updating and supporting this great tool.

By the way, I have noticed that the “undo” function does not work properly with this action. After a new message is added, I expect the “undo” function to remove the entire message, but it only removes the words I typed before the message. Do you have any ideas on how to improve this? I use the draft.append function to edit the content.

Undo is a function of the editor. If you want changes you make to participate in the undo stack, do not use functions on the draft object to make modifications. Use the related methods on the editor object 1 to manipulate the text, and those changes will participate in the undo system.

Thanks! I’ve updated the action to support undoing/redoing the message appended, by using editor.setTextInRange(draft.content.length, 1, '\n' + textToAppend) instead of draft.append.

Fantastic Job! Thank you so much!
Question for the group. I am going down the rabbit hole of prompts. I read the handbook The Art of ChatGPT Prompting: A Guide to Crafting Clear and Effective Prompts and wanted to know how others were using ChatGPT. I am labeling my conversations and then leaving them open in order to provide history of queries. Is anyone else doing this? The ChatConersation Action might be a way to seutp a Workspace for my list of experts.

I have input my api key but when I run the action on a draft it throws a red bar with an exclamation mark inside of a triangle displaying the name of the action. I also tried manually typing in the api key but receiving the same result. API key seems to work in other locations. Any troubleshooting one could recommend? Thanks

Thanks for the reply. Here’s what’s presented in the Action log.

Script step completed.
Chat failed: 401,
undefined
Script step completed.

thecatfix:

Re: queries (it’s all about the queries), “The Art of…” is definitely the gold standard, but, FWIW, I’ll also throw in this interesting resource 14, a bit more elementary, and more geared toward the new Bing chatbot. I personally can’t get enough of this stuff, so thought I’d share.

Many thanks to OP, too, for his cool efforts!

I’m loving this Action.
I created a workspace, based on the auto-assigned tag, so it’s quicker to find them.
Definitely one I’ll be using.
Thanks.

Very cool @reorx !

Thanks so much for this action.

I tried to run it, though, and got this error message:

Script Error Script Error: TypeError: undefined is not an object (evaluating 'lastBlock.role') Line number: 7, Column 16

I tried searching for others who encountered the same issue but didn’t find any, so have to bug everyone here who might help.

Thanks in advance.

Hi Jose, this definitely is a bug in the code, seems like a case I haven’t considered. Can you give me a minimal example of the draft to reproduce this error?

Hi Jose, would you please update the plugin and try again? I reproduced this error by running the action in an empty draft. Now it will show an alert telling you to enter a prompt.
But if your error is not due to an empty prompt, please send me the text causing the issue.


Also, two things to notice:

  1. I’ve created a new template tag for the API called api-base-url. It serves as the default base URL for the API, which is set to https://api.openai.com/v1/. However, it can be altered to another URL if necessary. Please note this change if you intend to use a custom API URL.
  2. I’ve created another action called System Message Template 3, it simply creates a new draft with <!-- block system --> block so that you don’t need to copy-paste it everytime.

I have the same problem of @iBanks, 401 error, which means the API previously input has been revoked.

However I can’t find a way to input my valid API. I tried to write it in the script code, but failed.

Would you please help me to figure out the solution?

Thankx.

The API key is stored in Draft’s Credentials. You should let ChatGPT Conversation forget about what it stored. Here’s the instruction on how to forget credentials in the official docs: Credentials | Drafts User Guide 30