Search code examples
openai-api

how to force openai to save the context of the whole chat?


How do you maintain historical context in repeat API calls?

i was searching that question but has found 0 answers

so i found this demo chat: https://next-openai-chatgpt.vercel.app/ and its source code: https://github.com/koalamango/next-openai-chatgpt/blob/main/pages/api/chat.ts

it can save context of conversation for real, but can anyboy tell me how?


Solution

  • the only one solution is the send to api all conversation history that must be under 3500 symbols, cuz u need around 500 points to make answer as example in json format:

    {"messages":["user:hello","bot:Hello there!","user:whats your name","bot:My name is Bot. What's yours?","user:now spell your name backwards pls","bot:tob","user:and now capitalise letters","bot:TOB"]}
    

    but in the end you must add "bot:" to suggest AI that he must answer by his role now. example works very well