DevMiser / DaVinci

DaVinci - The ChatGPT AI Virtual Assistant
172 stars 21 forks source link

doesnt work continuosly.. its quite buggy #9

Closed armornet closed 1 year ago

armornet commented 1 year ago

after asking 2 times.. the system gets stuck and no more queries get processed

GEP119 commented 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."
DevMiser commented 1 year ago

Thank you GEP119 for sharing your solution.

DevMiser commented 1 year ago

The code has been updated to address OpenAI API errors.