rj1
about | log | files | refs | license
commit 7bc5404c17135c16ffc49202126da1a6a8519e5a
parent 789507c0909e7438a6680739d5948d17d6c0179c
author: rj1 <[email protected]>
date:   Thu,  8 Dec 2022 13:28:49 -0600

we no longer need to specify conversation or message id in the config

Diffstat:
MREADME.md | 10+++-------
Mchatgpt-irc.py | 19++++++++++---------
Mexample-config.json | 4+---
3 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/README.md b/README.md @@ -8,15 +8,13 @@ chat with chatgpt on irc! - open the network tab in devtools (press F12) - say "hi" to chatgpt - collect your auth token from the *headers* tab -- collect your conversation id & parent message id from the *payload* tab -- create `config.json` using [the example configuration](#example-config.json) +- create `config.json` using [the example configuration](#example-config) below or by copying `example-config.json` - run the bot: `python chatgpt-irc.py` ![](https://rj1.su/img/chatgpt-irc-sshot1.png) -![](https://rj1.su/img/chatgpt-irc-sshot2.png) -## example config.json +## example config ``` { @@ -27,8 +25,6 @@ chat with chatgpt on irc! "ident": "chatgpt", "realname": "chatgpt", "channels": ["#rj1"], - "access_token": "", - "conversation_id": "", - "parent_message_id": "" + "auth_token": "", } ``` diff --git a/chatgpt-irc.py b/chatgpt-irc.py @@ -8,15 +8,15 @@ import uuid class ChatGPT: def __init__(self): - self.access_token = options["access_token"] - self.conversation_id = options["conversation_id"] - self.parent_message_id = options["parent_message_id"] + self.auth_token = options["auth_token"] + self.conversation_id = "" + self.parent_message_id = str(uuid.uuid4()) self.message_id = self.parent_message_id - self.clear = False + self.new_conversation = True def reset(self): - self.message_id = self.parent_message_id - self.clear = True + self.message_id = str(uuid.uuid4()) + self.new_conversation = True def prompt(self, message): self.parent_message_id = self.message_id @@ -38,13 +38,13 @@ class ChatGPT: "model": "text-davinci-002-render", } - if self.clear == True: + if self.new_conversation == True: del payload["conversation_id"] payload = json.dumps(payload) headers = { - "Authorization": f"Bearer {self.access_token}", + "Authorization": f"Bearer {self.auth_token}", "Content-Type": "application/json", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", @@ -61,8 +61,9 @@ class ChatGPT: data = json.loads(last) message = data["message"]["content"]["parts"][0] - if self.clear == True: + if self.new_conversation == True: self.conversation_id = data["conversation_id"] + self.new_conversation = False messages = parse_outgoing(message) diff --git a/example-config.json b/example-config.json @@ -6,7 +6,5 @@ "ident": "chatgpt", "realname": "chatgpt", "channels": ["#rj1"], - "access_token": "", - "conversation_id": "", - "parent_message_id": "" + "auth_token": "" }