-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathText2TextGen.py
68 lines (58 loc) · 3.04 KB
/
Text2TextGen.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
import json
convo = {}
class GPTJ:
def __init__(self, user_bot_input_output_example):
assert isinstance(user_bot_input_output_example, dict), "User bot examples must be a dictionary"
self.user_input_example = list(user_bot_input_output_example)
self.bot_output_example = list(user_bot_input_output_example.values())
self.user_inputs = []
self.bot_inputs = []
self.conversation_json = {}
def gptj_examples(self, uu, bb):
full_conversation = [[], []]
def username(user_response=uu):
Examples1 = [str(example) for example in user_response]
return Examples1
def imaginary_character(bot_response=bb):
Examples2 = [str(example2) for example2 in bot_response]
return Examples2
self.user_inputs = username(self.user_input_example)
self.bot_inputs = imaginary_character(self.bot_output_example)
length_of_user_inputs = len(self.user_inputs)
length_of_bot_outputs = len(self.bot_inputs)
if length_of_user_inputs == length_of_bot_outputs:
full_conversation[0].append(self.user_inputs)
full_conversation[1].append(self.bot_inputs)
for element in full_conversation:
for intention in full_conversation[0]:
convo['intentions'] = intention
for response in full_conversation[1]:
convo['responses'] = response
self.conversation_json = json.dumps(convo, indent=4)
return self.conversation_json
else:
if length_of_user_inputs > length_of_bot_outputs:
print([self.user_inputs[length_of_bot_outputs]])
del self.user_inputs[length_of_bot_outputs:]
full_conversation[0].append(self.user_inputs)
full_conversation[1].append(self.bot_inputs)
for element in full_conversation:
for intention in full_conversation[0]:
convo['intentions'] = intention
for response in full_conversation[1]:
convo['responses'] = response
self.conversation_json = json.dumps(convo, indent=2)
return self.conversation_json
elif length_of_bot_outputs > length_of_user_inputs:
print([self.bot_inputs[length_of_user_inputs]])
del self.bot_inputs[length_of_user_inputs:]
full_conversation[0].append(self.user_inputs)
full_conversation[1].append(self.bot_inputs)
for element in full_conversation:
for intention in full_conversation[0]:
convo['intentions'] = intention
for response in full_conversation[1]:
convo['responses'] = response
self.conversation_json = json.dumps(convo, indent=2)
return self.conversation_json
return self.conversation_json