CHATGPT

Completes the next turn in a conversation between a user and an OpenAI ChatGPT assistant.

Note: If you only need a single response to a single prompt, you should use the GPT function instead as it is a simpler interface. CHATGPT is most useful when representing a continuous back-and-forth conversation between a user and ChatGPT.

Syntax

=CHATGPT(user_message_range, assistant_message_range, gpt_role, chat_model, temperature, max_tokens, cache)

With the following function parameters:

  • user_message_range: A single cell reference, a cell range, or a string value representing a sequence of user message(s).
  • assistant_message_range: [optional] A single cell reference, a cell range, or a string value representing a sequence of assistant message(s). Assistant messages can either be previous replies from ChatGPT that are being input for context, or training examples of how an assistant should respond in the next response.
  • gpt_role: [optional] String description of how the ChatGPT assistant should act when responding. E.g., "Act as a terse and efficient personal assistant".
  • **chat_model: [optional] String representing the OpenAI chat model to use. Choose from "gpt-4" or "gpt-3.5-turbo" (default).
  • temperature: [optional] Number between 0 and 1 representing how much variance to introduce when ChatGPT responds. 0 is very little variance and 1 is the most variance.
  • max_tokens: [optional] Number representing the max number of tokens to return as the ChatGPT response. A max of 4096 is the limit for both the input and output, so plan accordingly if setting this value.
  • cache: [optional] Whether or not to cache the response. Setting to false will incur a re-execution on every cell refresh. Default is true.

** Caution: The GPT4 model uses 25 times more SheetGPT usage credits than the default GPT3.5 model. **

Description

Unlike the GPT function, CHATGPT is meant to represent an ongoing and lengthening conversation between a user and an assistant (powered by ChatGPT). The two primary inputs to CHATGPT are a cell range representing the sequence of user messages, and the cell range representing the sequence of previous assistant messages. These two sequences of messages will be intertwined into an alternating sequence to represent a back and forth conversation. ChatGPT will consume the full history of the conversation and use that context to form the response.

Since each call to CHATGPT is independent, any chat history you wish to be provided as historical context must be included in the next CHATGPT call in the sequence – even previous messages returned by ChatGPT (assuming you want the next response to be aware of these previous messages).

Sample Usage

=CHATGPT("Greet me in the language of your choice")

=CHATGPT("Greet me in the language of your choice",,"Act as an 80-year old man born and raised in the east end of London", "gpt-4")

** Caution: The GPT4 model uses 25 times more SheetGPT usage credits than the default GPT3.5 model. **

=CHATGPT(A2:A5,B2:B4)

Performance & caching

The completion that is returned is cached by SheetGPT to ensure that cell refreshes and other Sheet actions do not cause an unnecessary burn on your tokens. Any CHATGPT request with the same arguments in a Sheet will return the cached value, indefinitely. This is well beyond the typical 6-hour cache limit of most Sheet plugins and is our attempt to make SheetGPT the most cost-effective way to utilize GPT functionality.

If you ever need to avoid hitting the cache and force the generation of a new response, you can set the cache argument to false to force re-generation:

=CHATGPT(A2:A5,B2:B4,,,,,false)

See Also

You may also find the following resources useful: