I want ChatGPT to remember past conversations and have a consistent (stateful) conversation.
I have seen several code of ChatGPT prompt engineering.
There were two ways to design the prompt shown below (pseudo code):
Use a single input (Cheap) <- Better if possible
Stack all of previous history (Expensive, Token Limitation)
def openai_chat(prompt):
completions = openai.Completion.create(
engine = "text-davinci-003",
prompt = prompt,
max_tokens = 1024,
n = 1,
temperature = 0.8,
)
response = completions.choices[0].text.strip()
return response
# 1. Use a single input
while True:
prompt = input("User: ")
completion = openai_chat(prompt)
# 2. Stack all of previous history (prompt + completion)
prompt = ""
while True:
cur_prompt = input("User: ")
prompt += cur_prompt # pseudo code
completion = openai_chat(prompt)
prompt += completion # pseudo code
Is it possible to choose the first way (the cheap one) to have a consistent conversation?
In other words, does ChatGPT remember past history even if the prompt only has the current input?