mirror of https://github.com/knrd1/chatgpt.git
this update is addressing multiple issues
This commit is contained in:
parent
b3b77f87c2
commit
669cc5aa59
|
@ -1,2 +1,3 @@
|
|||
# ignore test app
|
||||
chatgpt_new.py
|
||||
chat.conf
|
||||
|
|
33
README.md
33
README.md
|
@ -15,35 +15,35 @@ yum install python3 (RedHat/CentOS)
|
|||
pip3 install openai
|
||||
git clone https://github.com/knrd1/chatgpt.git
|
||||
cd chatgpt
|
||||
cp example-chat.conf chat.conf
|
||||
```
|
||||
### Configuration:
|
||||
|
||||
Edit chatgpt.py and change variables. Example configuration for IRCNet:
|
||||
Edit chat.conf and change variables. Example configuration for IRCNet:
|
||||
```
|
||||
openai.api_key = "sk-XXXXXXXXXXXXXXXX"
|
||||
server = "open.ircnet.net"
|
||||
[openai]
|
||||
api_key = sk-XXXXXXXXXXXXXXX
|
||||
|
||||
[irc]
|
||||
server = open.ircnet.net
|
||||
port = 6667
|
||||
channel = "#irc"
|
||||
nickname = "MyBot"
|
||||
```
|
||||
IMPORTANT: When you specify "nickname", make sure you replace all occurences of "ChatGPT" in chatgpt.py file to the new nickname. For example, if your bot nickname is "MyBot", do:
|
||||
```
|
||||
$ sed -i 's/ChatGPT/MyBot/g' chatgpt.py
|
||||
channel = #irc
|
||||
nickname = MyBot
|
||||
```
|
||||
### Optional settings:
|
||||
|
||||
You can optionally adjust following settings, for more details see:
|
||||
You can optionally adjust following settings in chatgpt.py, please see docs for more details:
|
||||
https://platform.openai.com/docs/api-reference/completions
|
||||
```
|
||||
temperature=0.8,
|
||||
max_tokens=500,
|
||||
max_tokens=300,
|
||||
top_p=1,
|
||||
frequency_penalty=0,
|
||||
presence_penalty=0
|
||||
```
|
||||
Also, you can edit the engine, the list of compatible engines below:
|
||||
Also, you can edit the model, the list of compatible models below:
|
||||
```
|
||||
engine="text-davinci-003",
|
||||
model="text-davinci-003",
|
||||
```
|
||||
### Connecting bot to IRC server:
|
||||
```
|
||||
|
@ -54,10 +54,13 @@ ChatGPT will interact only if you mention its nickname:
|
|||
```
|
||||
10:31:12 <@knrd1> ChatGPT: hello, how are you?
|
||||
10:31:14 < ChatGPT> Hi there, I'm doing well, thank you. How about you?
|
||||
10:35:56 <@knrd1> ChatGPT: do you like IRC?
|
||||
10:35:59 < ChatGPT> Yes, I like IRC. It is a great way to communicate with people from around the world.
|
||||
|
||||
```
|
||||
### Model endpoint compatibility
|
||||
|
||||
ChatGPT uses endpoint v1/completions. Following engines are compatible.
|
||||
ChatGPT uses endpoint v1/completions. Following models are compatible.
|
||||
```
|
||||
text-davinci-003
|
||||
text-davinci-002
|
||||
|
@ -69,4 +72,4 @@ curie
|
|||
babbage
|
||||
ada
|
||||
```
|
||||
More details about engines: https://platform.openai.com/docs/models
|
||||
More details about models: https://platform.openai.com/docs/models
|
||||
|
|
25
chatgpt.py
25
chatgpt.py
|
@ -1,20 +1,25 @@
|
|||
import openai
|
||||
import socket
|
||||
import time
|
||||
import configparser
|
||||
|
||||
# Read configuration from file
|
||||
config = configparser.ConfigParser()
|
||||
config.read('chat.conf')
|
||||
|
||||
# Set up OpenAI API key
|
||||
openai.api_key = ""
|
||||
openai.api_key = config.get('openai', 'api_key')
|
||||
|
||||
# Set up IRC connection settings
|
||||
server = ""
|
||||
port =
|
||||
channel = ""
|
||||
nickname = ""
|
||||
server = config.get('irc', 'server')
|
||||
port = config.getint('irc', 'port')
|
||||
channel = config.get('irc', 'channel')
|
||||
nickname = config.get('irc', 'nickname')
|
||||
|
||||
# Connect to IRC server
|
||||
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
irc.connect((server, port))
|
||||
irc.send(bytes("USER " + nickname + " " + nickname + " " + nickname + " :ChatGPT\n", "UTF-8"))
|
||||
irc.send(bytes("USER " + nickname + " " + nickname + " " + nickname + " :" + nickname + "\n", "UTF-8"))
|
||||
irc.send(bytes("NICK " + nickname + "\n", "UTF-8"))
|
||||
irc.send(bytes("JOIN " + channel + "\n", "UTF-8"))
|
||||
|
||||
|
@ -27,10 +32,10 @@ while True:
|
|||
elif message.find("PRIVMSG " + channel + " :" + nickname + ":") != -1:
|
||||
question = message.split(nickname + ":")[1].strip()
|
||||
response = openai.Completion.create(
|
||||
engine="text-davinci-003",
|
||||
model="text-davinci-003",
|
||||
prompt="Q: " + question + "\nA:",
|
||||
temperature=0.8,
|
||||
max_tokens=500,
|
||||
max_tokens=300,
|
||||
top_p=1,
|
||||
frequency_penalty=0,
|
||||
presence_penalty=0
|
||||
|
@ -38,6 +43,6 @@ while True:
|
|||
answers = [x.strip() for x in response.choices[0].text.strip().split('\n')]
|
||||
for answer in answers:
|
||||
while len(answer) > 0:
|
||||
irc.send(bytes("PRIVMSG " + channel + " :" + answer[:350] + "\n", "UTF-8"))
|
||||
answer = answer[350:]
|
||||
irc.send(bytes("PRIVMSG " + channel + " :" + answer[:400] + "\n", "UTF-8"))
|
||||
answer = answer[400:]
|
||||
time.sleep(1)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[openai]
|
||||
api_key = sk-XXXXXXXXXXXXXXX
|
||||
|
||||
[irc]
|
||||
server = open.ircnet.net
|
||||
port = 6667
|
||||
channel = #irc
|
||||
nickname = MyBot
|
Loading…
Reference in New Issue