Conversation history not working, bot replying to older messages

With GPT4 or GPT 3.5-Turbo I send gthe conversation history in an array like this

        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who won the world series in 2020?"},
        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
        {"role": "user", "content": "Where was it played?"}

However, when the bot response (sometimes) it responds to the 2nd to last message from the user, in the above example it would repeat something about “Who on the world series” I instructed it to “respond to the last user input” but it still does this sometimes. Anyone have this happen before?

1 Like

Hi @steven96813

Here’s what I get:

"choices": [
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "The 2020 World Series was played at Globe Life Field in Arlington, Texas.",
        "role": "assistant"

when I run the code in the docs with my API key.

What code are you using to make the API call?

1 Like

Without seeing your code, I would suggest assembling and printing the “messages” right before you see that variable, either to the console or to a log file. Then you can see if your software is omitting the user question in some cases, and can see if there parse errors on the input of certain characters or such.

It could be the way your conversation history code algorithm works if you are adding the user input and then removing the old stuff not to send…