Gpt-3.5-turbo vs text-davinci-003 *ChatBot*

Oh!! I finally figured out how to do make my code pass the Messages array itteratively with each successive message update through the API.

Where I basically set the initial System and User content. and then I push the Assistant and User messages, all recorded to localstorage, and then for the next message, localstorage is read, and the next assistance and user messages are appended. Rinse and repeat.

My first test was a game of 20 questions, and the bot was able to get the correct answer after 11 :smiley:
as well as remembering my name, favorite ice cream, etc. Very happy atm.

    // Messages payload
    // Check if the messages item exists in localStorage
    if (!localStorage.getItem("messages")) {
      // If it does not exist, create an array with the initial messages
      const iMessages = [
        { role: 'system', content: "You are Eva. You have access to previous chats and responses. You will keep conversation to a minimum and answer to the best of your abilities." },
        { role: 'user', content: selPers.value },
      ];

      // Store the initial messages in localStorage
      localStorage.setItem("messages", JSON.stringify(iMessages));
    }

    // Create a new array to store the messages
    let newMessages = [];

    // Push the messages to the new array
    newMessages.push({ role: 'assistant', content: lastResponse.replace(/\n/g, ' ') });
    newMessages.push({ role: 'user', content: sQuestion.replace(/\n/g, '') });

    // Append the new messages to the existing messages in localStorage
    let existingMessages = JSON.parse(localStorage.getItem("messages")) || [];
    existingMessages = existingMessages.concat(newMessages);
    localStorage.setItem("messages", JSON.stringify(existingMessages));

    // Retrieve messages from local storage
    var cStoredMessages = localStorage.getItem("messages");
    kMessages = cStoredMessages ? JSON.parse(cStoredMessages) : [];
2 Likes