Suppose I want to write a story which is longer than 4000 tokens

Welcome to the OpenAI community @lordjoe

It is not possible to exceed the token limit of an engine. However there are ways to get the desired length explicitly, using multiple calls to the API.

Firstly, if the desired length of completion is under the limits but the original completion isn’t what you want, you’ll have to redesign your prompt and be very specific of what you want from the engine.

E.g. "Write an article about unicorns.""Write an article about unicorns in 100 words."

You can read more about prompt design.

Now if you want to exceed the limit of the engine, the following might be of use:

  1. Rolling memory: Use the last N tokens from your completion as prompt to make the next API call. The last N tokens will help keep the context.

  2. Summarising: Summarise your current completion. In the next API call use that summary along as prompt, along with appended text like “Here’s what happens next:”.
    The summary in prompt will preserve context, which is crucial to the engine to generate coherent completion as the engines don’t have a memory of their own.

Hope this helps.

3 Likes