From 42683a3ec06e68a1b8c3d918ba781299f91a9f4b Mon Sep 17 00:00:00 2001 From: Sparklight Date: Mon, 20 Mar 2023 08:13:08 +0100 Subject: [PATCH] =?UTF-8?q?Gestion=20des=20erreurs.=20A=20impl=C3=A9menter?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SupportPC.py | 1 - handleerrors.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 handleerrors.py diff --git a/SupportPC.py b/SupportPC.py index c9bcde8..793140c 100644 --- a/SupportPC.py +++ b/SupportPC.py @@ -6,7 +6,6 @@ import getpass import socket from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit, QPushButton, QLineEdit -# TODO remplacer logpath, username # TODO gérer les erreurs de timeout, retour et overload de l'API # TODO gérer le formattage / affichage de la réponse quand c'est une liste à points. diff --git a/handleerrors.py b/handleerrors.py new file mode 100644 index 0000000..c685333 --- /dev/null +++ b/handleerrors.py @@ -0,0 +1,64 @@ +import openai + +try: + #Make your OpenAI API request here + response = openai.Completion.create(prompt="Hello world", + model="text-davinci-003") +except openai.error.APIError as e: + #Handle API error here, e.g. retry or log + print(f"OpenAI API returned an API Error: {e}") + pass +except openai.error.Timeout as e: + #Handle connection error here + print(f"Failed to connect to OpenAI API: {e}") + pass +except openai.error.RateLimitError as e: + #Handle rate limit error (we recommend using exponential backoff) + print(f"OpenAI API request exceeded rate limit: {e}") + pass +except openai.error.APIConnectionError as e: + #Handle Issue connecting to our services + print(f"Check your network settings, proxy configuration, SSL certificates, or firewall rules: {e}") + pass +except openai.error.InvalidRequestError as e: + #Handle when your request was malformed or missing some required parameters, such as a token or an input + print(f"The error message should advise you on the specific error made: {e}") + pass +except openai.error.AuthenticationError as e: + #Handle validation of your API key or token fail + print(f"Your API key or token was invalid, expired, or revoked: {e}") + pass +except openai.error.ServiceUnavailableError as e: + #Handle Issue on OpenAI servers + print(f"Retry your request after a brief wait and contact us if the issue persists: {e}") + pass + +""" +APIError +Cause: Issue on our side. +Solution: Retry your request after a brief wait and contact us if the issue persists. + +Timeout +Cause: Request timed out. +Solution: Retry your request after a brief wait and contact us if the issue persists. + +RateLimitError +Cause: You have hit your assigned rate limit. +Solution: Pace your requests. Read more in our Rate limit guide. + +APIConnectionError +Cause: Issue connecting to our services. +Solution: Check your network settings, proxy configuration, SSL certificates, or firewall rules. + +InvalidRequestError +Cause: Your request was malformed or missing some required parameters, such as a token or an input. +Solution: The error message should advise you on the specific error made. Check the documentation for the specific API method you are calling and make sure you are sending valid and complete parameters. You may also need to check the encoding, format, or size of your request data. + +AuthenticationError +Cause: Your API key or token was invalid, expired, or revoked. +Solution: Check your API key or token and make sure it is correct and active. You may need to generate a new one from your account dashboard. + +ServiceUnavailableError +Cause: Issue on our servers. +Solution: Retry your request after a brief wait and contact us if the issue persists. Check the status page +""" \ No newline at end of file