-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv2.py
39 lines (36 loc) · 1.13 KB
/
v2.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
from revChatGPT.V2 import Chatbot
import sys
import json
import time
import random
"""
pip3 install --upgrade revChatGPT
Refer to https://github.com/acheong08/ChatGPT
for more information
"""
async def main(prompt):
chatbot = Chatbot(email="<email>", password="<password>")
messages = ""
async for line in chatbot.ask(prompt):
print(line["choices"][0]["text"].replace("<|im_end|>", ""), end="")
sys.stdout.flush()
message = line["choices"][0]["text"].replace("<|im_end|>", "")
messages = messages + message
q_a = {"question":prompt,"answer":messages}
json_objects = json.dumps(q_a,indent=4)
# change the file name by yourself
with open("sample.json","a") as f:
f.write(json_objects)
print()
#print(response["choices"][0]["text"])
if __name__ == "__main__":
import asyncio
# change the file name by yourself, each line end with "\n"
with open("test.txt","r") as f:
prompts = f.read()
for prompt in prompts.split("\n"):
print(prompt)
if prompt == "":
continue
asyncio.run(main(prompt))
time.sleep(random.random()*3)