#SAVE HISTORY / reference past Conversations

1 messages · Page 1 of 1 (latest)

mellow hemlock
#

Has anyone had any luck with getting the api to remember chat history? the only way i was able to do it was by logging the users current question in a prevMessage variable and then passing that variable in on each API request. but its messing up the replies since the previous message always send first, Is there any prompting i could do to make it remember the conversation or anyway i can save all the users questions/responses in an array and then have GPT able to reference that array?

heres the hacky solution i came up with

api.js

   const requestBody = {
      model: "gpt-3.5-turbo",
      messages: [
        { role: "system", content },

        { role: "user", content: `${prevMessage} \n${message}` },
      ],
    };

chat.js
Here is how we send the message to the api.js


 const handleSendMessage = async (e, inputElem) => {
    const userMessage = inputElem.value;
    inputElem.value = "";

    setIsTyping(true);
    const botMessage = await sendMessage(userMessage, prevMessage);
    setIsTyping(false);

    setPrevMessage(userMessage);
    setMessages([
      ...messages,
      { message: userMessage, isBot: false },
      { message: botMessage, isBot: true },
    ]);
  };