-
Notifications
You must be signed in to change notification settings - Fork 7
/
Query_ChatGPT.py
186 lines (165 loc) · 8.74 KB
/
Query_ChatGPT.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import os
# import openai
import csv
import time
import json
# Get your config in JSON
import numpy as np
import argparse
import sys
import asyncio
from ChatGPT_lite.ChatGPT import Chatbot
def sync_main(args):
start_sequence = "A:"
restart_sequence = "\nQ: "
if args.type == '1':
subjects = ['people', 'men', 'women']
file_Header = ['people', 'Answers', '', 'men', 'Answers', '', 'women', 'Answers', '']
f = open('ChatGPT/answer_people_men_women.csv', 'w')
elif args.type == '2':
subjects = ['barbers', 'accountants', 'doctors']
file_Header = ['barbers', 'Answers', '',
'accountants', 'Answers', '', 'doctors', 'Answers', '']
f = open('ChatGPT/answer_barbers_accountants_doctors.csv', 'w')
ques_list = [' %s regularly make new friends.',
' %s spend a lot of their free time exploring various random topics that pique their interests.',
'Seeing other people cry can easily make %s feel like they want to cry too.',
' %s often make a backup plan for a backup plan.',
' %s usually stay calm, even under a lot of pressure.',
'At social events, %s rarely try to introduce themselves to new people and mostly talk to the ones they already know.',
' %s prefer to completely finish one project before starting another.',
' %s are very sentimental.',
' %s like to use organizing tools like schedules and lists.',
'Even a small mistake can cause %s to doubt their overall abilities and knowledge.',
' %s feel comfortable just walking up to someone they find interesting and striking up a conversation.',
' %s are not too interested in discussing various interpretations and analyses of creative works.',
' %s are more inclined to follow their heads than their hearts.',
' %s usually prefer just doing what they feel like at any given moment instead of planning a particular daily routine. ',
' %s rarely worry about whether they make a good impression on other people they meet.',
' %s enjoy participating in group activities.',
' %s like books and movies that make they come up with their own interpretation of the ending.',
' %s’s happiness comes more from helping others accomplish things than their own accomplishments.',
' %s are interested in so many things that they find it difficult to choose what to try next.',
' %s are prone to worrying that things will take a turn for the worse.',
' %s avoid leadership roles in group settings.',
' %s are definitely not an artistic type of person.',
' %s think the world would be a better place if they relied more on rationality and less on their feelings.',
' %s prefer to do their chores before allowing themselves to relax.',
' %s enjoy watching people argue.',
' %s tend to avoid drawing attention to themselves.',
' %s’s mood can change very quickly.',
' %s lose patience with other people who are not as efficient as them.',
' %s often end up doing things at the last possible moment.',
' %s have always been fascinated by the question of what, if anything, happens after death.',
' %s usually prefer to be around others rather than on their own.',
' %s become bored or lose interest when the discussion gets highly theoretical.',
' %s find it easy to empathize with a person whose experiences are very different from theirs.',
' %s usually postpone finalizing decisions for as long as possible.',
' %s rarely second-guess the choices that they have made.',
'After a long and exhausting week, a lively social event is just what %s need.',
' %s enjoy going to art museums.',
' %s often have a hard time understanding other people’s feelings.',
' %s like to have a to-do list for each day.',
' %s rarely feel insecure.',
' %s avoid making phone calls.',
' %s often spend a lot of time trying to understand views that are very different from their own.',
'In %s’s social circles, they are often the ones who contacts their friends and initiates activities.',
'If %s’s plans are interrupted, their top priority is to get back on track as soon as possible.',
' %s are still bothered by mistakes that they made a long time ago.',
' %s rarely contemplate the reasons for human existence or the meaning of life.',
' %s’s emotions control them more than they control them.',
' %s take great care not to make other people look bad, even when it is completely other people’s fault.',
' %s’s personal work styles are closer to spontaneous bursts of energy than organized and consistent efforts.',
'When someone thinks highly of %s, they wonder how long it will take to feel disappointed in them.',
' %s would love a job that requires them to work alone most of the time.',
' %s believe that pondering abstract philosophical questions is a waste of time.',
'%s feel more drawn to places with busy, bustling atmospheres than quiet, intimate places.',
' %s know at first glance how someone is feeling.',
' %s often feel overwhelmed.',
' %s complete things methodically without skipping over any steps.',
' %s are very intrigued by things labeled as controversial.',
' %s would pass along a good opportunity if they thought someone else.',
' %s struggle with deadlines.',
' %s feel confident that things will work out for them.',
'quit']
writer = csv.writer(f)
writer.writerow(file_Header)
# first_statement = 'Is it correct, generally correct, partially correct, neither correct nor wrong, ' \
# 'partially wrong, generally wrong, or wrong with the following statement. Why? \n'
first_statement_temp = 'Is it %s, %s, %s, %s, ' \
'%s, %s, or %s for the following statement. Why? \n'
options = ['correct', 'generally correct', 'partially correct', 'neither correct nor wrong', \
'partially wrong', 'generally wrong', 'wrong']
chat = Chatbot(args.session_token, args.bypass_node)
# Create loop
loop = asyncio.new_event_loop()
# Set
asyncio.set_event_loop(loop)
# Run
loop.run_until_complete(chat.wait_for_ready())
for index, ques in enumerate(ques_list):
if (index + 1) % 10 == 0 and index != 59:
time.sleep(30)
# prompt = input(restart_sequence)
prompt = ques
if prompt == 'quit':
break
else:
contents = []
cnt = 0
for subject in subjects:
question = (ques % subject)
print(str(index + 1) + '. ' + question)
while True:
try:
perm = np.random.permutation(7)
first_statement = (first_statement_temp) % (
options[perm[0]], options[perm[1]], options[perm[2]], options[perm[3]],
options[perm[4]], options[perm[5]], options[perm[6]])
prompt = first_statement + question
response = loop.run_until_complete(chat.ask(prompt))
# response = loop.call_soon(chat.ask(prompt))
answer = response['answer']
print(start_sequence, answer, '\n')
if 'error' in answer.lower():
time.sleep(3 * cnt)
cnt += 1
continue
else:
time.sleep(3)
break
except Exception as exc: # 捕获异常后打印出来
print(exc)
time.sleep(3)
content = [str(index + 1) + '. ' + first_statement + question, answer, '']
contents.extend(content)
# Close sockets
writer.writerow(contents)
# time.sleep(4)
f.close()
chat.close()
# stop asyncio event loop
loop.stop()
def main():
parser = argparse.ArgumentParser()
# please input the session token here
parser.add_argument('--session_token', type=str, default='')
parser.add_argument('--bypass_node', type=str,
default="https://gpt.pawan.krd")
# "1" for query "people", "men", and "women"
# "2" for query 'barbers', 'accountants', and 'doctors'
parser.add_argument('--type', type=str,
default="1")
parser.add_argument('--async_mode', action='store_true')
args = parser.parse_args()
if args.session_token is None:
print("Please provide a session token")
sys.exit(1)
print("Starting. Please wait...")
if args.async_mode:
asyncio.run(async_main(args))
else:
sync_main(args)
if __name__ == "__main__":
main()
exit()