rj1
about | log | files | refs | license
commit 789507c0909e7438a6680739d5948d17d6c0179c
parent dd40337e6218c52fe13bc97a39ce54065daec91a
author: rj1 <[email protected]>
date:   Thu,  8 Dec 2022 04:04:38 -0600

!reset command resets the conversation w/ chatgpt properly now

Diffstat:
Mchatgpt-irc.py | 44+++++++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/chatgpt-irc.py b/chatgpt-irc.py @@ -12,9 +12,11 @@ class ChatGPT: self.conversation_id = options["conversation_id"] self.parent_message_id = options["parent_message_id"] self.message_id = self.parent_message_id + self.clear = False def reset(self): self.message_id = self.parent_message_id + self.clear = True def prompt(self, message): self.parent_message_id = self.message_id @@ -22,21 +24,24 @@ class ChatGPT: url = "https://chat.openai.com/backend-api/conversation" - payload = json.dumps( - { - "action": "next", - "messages": [ - { - "id": self.message_id, - "role": "user", - "content": {"content_type": "text", "parts": [message]}, - } - ], - "conversation_id": self.conversation_id, - "parent_message_id": self.parent_message_id, - "model": "text-davinci-002-render", - } - ) + payload = { + "action": "next", + "messages": [ + { + "id": self.message_id, + "role": "user", + "content": {"content_type": "text", "parts": [message]}, + } + ], + "conversation_id": self.conversation_id, + "parent_message_id": self.parent_message_id, + "model": "text-davinci-002-render", + } + + if self.clear == True: + del payload["conversation_id"] + + payload = json.dumps(payload) headers = { "Authorization": f"Bearer {self.access_token}", @@ -53,8 +58,13 @@ class ChatGPT: try: last = response.split(("data:"))[-2] - items = json.loads(last)["message"]["content"]["parts"][0] - messages = parse_outgoing(items) + data = json.loads(last) + message = data["message"]["content"]["parts"][0] + + if self.clear == True: + self.conversation_id = data["conversation_id"] + + messages = parse_outgoing(message) return messages except IndexError: