Closed armornet closed 1 year ago
I was having the same issues and could see that from my location I was getting lots of OpenAI API errors, so I added this error handling code and so far it seems to be working way better. It still stumbles but recovers and I can continue to ask questions.
def ChatGPT(query):
try:
chat_log.append ({"role": "user", "content": query})
response = openai.ChatCompletion.create(
model=GPT_model,
messages=chat_log
)
return str.strip(response['choices'][0]['message']['content'])
chat_log.append({"role": "system", "content": response})
except:
print("Error communicating with OpenAI. Please try again.")
return "I apologize, there was an error connecting to OpenAI. Please try rephrasing your question."
Thank you GEP119 for sharing your solution.
The code has been updated to address OpenAI API errors.
after asking 2 times.. the system gets stuck and no more queries get processed