mirror of https://github.com/knrd1/chatgpt.git
improved error handling
This commit is contained in:
parent
95ce7866b2
commit
43e84a2a3b
|
@ -12,7 +12,7 @@ Install python3 and the official Python bindings:
|
|||
```
|
||||
$ apt install python3 python3-pip (Debian/Ubuntu)
|
||||
$ yum install python3 python3-pip (RedHat/CentOS)
|
||||
$ pip3 install openai pyshorteners
|
||||
$ pip3 install openai==0.28 pyshorteners
|
||||
$ git clone https://github.com/knrd1/chatgpt.git
|
||||
$ cd chatgpt
|
||||
$ cp example-chat.conf chat.conf
|
||||
|
|
18
chatgpt.py
18
chatgpt.py
|
@ -126,9 +126,12 @@ while True:
|
|||
except openai.error.Timeout as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes("PRIVMSG " + channel + " :API call timed out. Try again later.\n", "UTF-8"))
|
||||
except openai.error.OpenAIError as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes(f"PRIVMSG {channel} :API call failed. {str(e)}\n", "UTF-8"))
|
||||
except Exception as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes("PRIVMSG " + channel + " :API call failed. Check console for error message.\n", "UTF-8"))
|
||||
irc.send(bytes(f"PRIVMSG {channel} :An unexpected error occurred. {str(e)}\n", "UTF-8"))
|
||||
elif model in completion_models:
|
||||
try:
|
||||
response = openai.Completion.create(
|
||||
|
@ -156,9 +159,12 @@ while True:
|
|||
except openai.error.Timeout as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes("PRIVMSG " + channel + " :API call timed out. Try again later.\n", "UTF-8"))
|
||||
except openai.error.OpenAIError as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes(f"PRIVMSG {channel} :API call failed. {str(e)}\n", "UTF-8"))
|
||||
except Exception as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes("PRIVMSG " + channel + " :API call failed. Check console for error message.\n", "UTF-8"))
|
||||
irc.send(bytes(f"PRIVMSG {channel} :An unexpected error occurred. {str(e)}\n", "UTF-8"))
|
||||
elif model == "dalle":
|
||||
try:
|
||||
response = openai.Image.create(
|
||||
|
@ -170,9 +176,15 @@ while True:
|
|||
type_tiny = pyshorteners.Shortener()
|
||||
short_url = type_tiny.tinyurl.short(long_url)
|
||||
irc.send(bytes("PRIVMSG " + channel + " :" + short_url + "\n", "UTF-8"))
|
||||
except openai.error.Timeout as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes("PRIVMSG " + channel + " :API call timed out. Try again later.\n", "UTF-8"))
|
||||
except openai.error.OpenAIError as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes(f"PRIVMSG {channel} :API call failed. {str(e)}\n", "UTF-8"))
|
||||
except Exception as e:
|
||||
print("Error: " + str(e))
|
||||
irc.send(bytes("PRIVMSG " + channel + " :API call failed. Check console for error message..\n", "UTF-8"))
|
||||
irc.send(bytes(f"PRIVMSG {channel} :An unexpected error occurred. {str(e)}\n", "UTF-8"))
|
||||
else:
|
||||
print("Invalid model.")
|
||||
irc.send(bytes("PRIVMSG " + channel + " :Invalid model.\n", "UTF-8"))
|
||||
|
|
Loading…
Reference in New Issue