-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversation.py
70 lines (44 loc) · 2.08 KB
/
conversation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from pyGptBot import ChatBot as ChatBot
import subprocess
import os
import json
import time
class ConversationRoom:
def __init__(self,GPTconfig,recording_filename,botNameA="personA",botNameB="personB",length=100):
self.init_message = "Hello"
# https://github.com/acheong08/ChatGPT/wiki/Setup
self.length = length
self.botNameA = botNameA
self.botNameB = botNameB
self.chatGPT_1 = ChatBot(self.botNameA,organization=GPTconfig["organization"],apiKey=GPTconfig["apiKey"],personalityFile=f"{self.botNameA}.txt",debug=True)
self.chatGPT_2 = ChatBot(self.botNameB,organization=GPTconfig["organization"],apiKey=GPTconfig["apiKey"],personalityFile=f"{self.botNameB}.txt",debug=True)
self.filename = recording_filename
self.__stop = True
pass
def updatePersonalities(self,GPTconfig,botNameA,botNameB):
self.botNameA = botNameA
self.botNameB = botNameB
self.chatGPT_1 = ChatBot(self.botNameA,organization=GPTconfig["organization"],apiKey=GPTconfig["apiKey"],personalityFile=f"{self.botNameA}.txt")
self.chatGPT_2 = ChatBot(self.botNameB,organization=GPTconfig["organization"],apiKey=GPTconfig["apiKey"],personalityFile=f"{self.botNameB}.txt")
def update_file(self,gpt,message):
with open(self.filename,"a",encoding="utf-8") as f:
scribe = f"\n<li>{message}</li>\n"
f.write(scribe)
def start(self):
with open(self.filename,"w",encoding="utf-8") as f:
f.write("")
self.__stop = False
def stop(self):
self.__stop = True
def run(self):
counter = 0
while(self.__stop):
time.sleep(1)
response = self.chatGPT_1.ask(self.init_message)
self.update_file(self.botNameA,response)
while(not self.__stop and self.length > counter):
response = self.chatGPT_2.ask(response)
self.update_file(self.botNameB,response)
response = self.chatGPT_1.ask(response)
self.update_file(self.botNameA,response)
counter+=1