Text response every other message

I’m getting a blank message after every response from the AI

> Hello


Hello there! How are you doing?
1
> im going well

2
> 


That's great to hear! Is there anything I can help you with?
3
> 

this is the relevant code

context = []
messageCount = 0


def response(prompt):
    test = openai.Completion.create(
        model="text-davinci-003",
        prompt=prompt,
        max_tokens=2000,
        temperature=0.7)

    return test.choices[0].text


while True:
    messageCount += 1
    inputText = input("> ")
    answer = response(inputText + '. '.join(context))
    print(answer)
    print(messageCount)
    context.append(f"This is the user's message numbered: {messageCount} and this was the message: " + inputText)
    context.append(f"This was the artificial intelligence's message numbered: {messageCount} and this was the message: "
                   + answer)

If you slow down your while loop, you will have better results. If you hit the API too hard, you will see these types of issues. Try using some value of time.sleep which works for you. I typically use 4 seconds, as I am not in a big hurry, but you can use less if you like.

Example

import time
 
 while True:
    messageCount += 1
    inputText = input("> ")
    answer = response(inputText + '. '.join(context))
    print(answer)
    print(messageCount)
    context.append(f"This is the user's message numbered: {messageCount} and this was the message: " + inputText)
    context.append(f"This was the artificial intelligence's message numbered: {messageCount} and this was the message: "
                   + answer)
    time.sleep(2)

I tried it and it didn’t change anything. I also got rid of the “context” variable and that fixes the issue, but i want it to keep the context because it allows the bot to see the entire conversation.