Another suggestion which may be ‘Rube Goldberging’ the problem: create a chat history of each session/response. (Similar to what the playground provides.) However, after you receive a new message, parse your chat history and see if the message is similar to previous messages. (Let’s just say the last 5 responses.) For a simple yet not necessarily robust solution; you could compare the amount of times each word was found in each message. Example:
Previous message:
“This is the result of your message”
Current response:
“How dare you question my result result result”
Take the length of both messages and the amount of duplicate words that were found.
In our case,
Length of Previous message = 7
Length of Current response = 8
Duplicate words found = 3 (result, result, result)
Use any threshold you desire to deem something a ‘bad’ message.
If you find 3 or more of the same words, delete the current response and query GPT3 again with the previous message. If this occurs more than once (like you get the exact same message back) delete current response and previous message and then send GPT3 your ‘previous previous message’. (You could also compare the total duplicate words to the total length of the response) again, use some threshold.
What you are mainly trying to avoid (in my opinion) is having duplicate data in a close sequence. GPT3 is trying to predict what comes next. If it sees the same message (or close to) it will start repeating itself. This gets worse per message because each response ‘encourages’ the ‘bad’ behavior.
If you want to solve this problem mathematically, use the Cosine Similarity. Just Google for the code and you can pretty much just copy and paste the function.
To support [daveshapautomator]’s response: if you have the temperature at 0, you are almost guaranteed to make GPT3 deterministic. If the model has to take a ‘bad’ guess, it will usually be a repeat of the most seen tokens/words it has seen recently.