mirror of https://github.com/knrd1/chatgpt.git
model update
This commit is contained in:
parent
816fb9f0c3
commit
aef5f082db
|
@ -1,2 +1,2 @@
|
|||
chatgpt_new.py
|
||||
chatgpt_dev.py
|
||||
chat.conf
|
||||
|
|
14
README.md
14
README.md
|
@ -44,7 +44,7 @@ request_timeout=180
|
|||
```
|
||||
Also, you can edit the model, the list of compatible models below:
|
||||
```
|
||||
model="text-davinci-003",
|
||||
model="gpt-3.5-turbo",
|
||||
```
|
||||
### Connecting bot to IRC server:
|
||||
```
|
||||
|
@ -61,16 +61,8 @@ ChatGPT will interact only if you mention its nickname:
|
|||
```
|
||||
### Model endpoint compatibility
|
||||
|
||||
ChatGPT uses endpoint v1/completions. Following models are compatible.
|
||||
ChatGPT uses endpoint v1/chat/completions. Following models are compatible.
|
||||
```
|
||||
text-davinci-003
|
||||
text-davinci-002
|
||||
text-curie-001
|
||||
text-babbage-001
|
||||
text-ada-001
|
||||
davinci
|
||||
curie
|
||||
babbage
|
||||
ada
|
||||
gpt-4, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301
|
||||
```
|
||||
More details about models: https://platform.openai.com/docs/models
|
||||
|
|
29
chatgpt.py
29
chatgpt.py
|
@ -34,9 +34,11 @@ while True:
|
|||
|
||||
# Listen for messages from users
|
||||
while True:
|
||||
message = irc.recv(2048).decode("UTF-8")
|
||||
try:
|
||||
message = irc.recv(2048).decode("UTF-8")
|
||||
except UnicodeDecodeError:
|
||||
continue
|
||||
if message.find("PING") != -1:
|
||||
# Respond to server PING requests
|
||||
irc.send(bytes("PONG " + message.split()[1] + "\n", "UTF-8"))
|
||||
elif message.find("KICK " + channel + " " + nickname) != -1:
|
||||
irc.send(bytes("JOIN " + channel + "\n", "UTF-8"))
|
||||
|
@ -44,22 +46,29 @@ while True:
|
|||
elif message.find("PRIVMSG " + channel + " :" + nickname + ":") != -1:
|
||||
question = message.split(nickname + ":")[1].strip()
|
||||
try:
|
||||
response = openai.Completion.create(
|
||||
model="text-davinci-003",
|
||||
prompt="Q: " + question + "\nA:",
|
||||
response = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[{"role": "user", "content": question}],
|
||||
temperature=0.8,
|
||||
max_tokens=1000,
|
||||
top_p=1,
|
||||
frequency_penalty=0,
|
||||
presence_penalty=0,
|
||||
request_timeout=180 # Set request timeout to 3 minutes
|
||||
request_timeout=180
|
||||
)
|
||||
answers = [x.strip() for x in response.choices[0].text.strip().split('\n')]
|
||||
answers = [x.strip() for x in response.choices[0].message.content.strip().split('\n')]
|
||||
for answer in answers:
|
||||
while len(answer) > 0:
|
||||
irc.send(bytes("PRIVMSG " + channel + " :" + answer[:400] + "\n", "UTF-8"))
|
||||
answer = answer[400:]
|
||||
except openai.error.Timeout as e: # Catch the timeout error
|
||||
if len(answer) <= 392:
|
||||
irc.send(bytes("PRIVMSG " + channel + " :" + answer + "\n", "UTF-8"))
|
||||
answer = ""
|
||||
else:
|
||||
last_space_index = answer[:392].rfind(" ")
|
||||
if last_space_index == -1:
|
||||
last_space_index = 392
|
||||
irc.send(bytes("PRIVMSG " + channel + " :" + answer[:last_space_index] + "\n", "UTF-8"))
|
||||
answer = answer[last_space_index:].lstrip()
|
||||
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 Exception as e:
|
||||
|
|
|
@ -4,5 +4,5 @@ api_key = sk-XXXXXXXXXXXXXXX
|
|||
[irc]
|
||||
server = open.ircnet.net
|
||||
port = 6667
|
||||
channel = #irc
|
||||
channel = #ircnet
|
||||
nickname = MyBot
|
||||
|
|
Loading…
Reference in New Issue