-
Notifications
You must be signed in to change notification settings - Fork 1
/
01_joke_generation.py
80 lines (69 loc) · 2.11 KB
/
01_joke_generation.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
# after https://github.com/terry3041/pyChatGPT
from pyChatGPT import ChatGPT
import pandas as pd
import time
from numpy import random
from selenium.common.exceptions import TimeoutException
session_token = "" # insert sassion token here
api = ChatGPT(session_token)
prompts = [
"Can you tell me a joke?",
"Please, tell me a joke.",
"Let me hear a joke, please.",
"Do you know any good jokes?",
"Tell me a joke, please!",
"Tell me another joke.",
"I would love to hear a joke.",
"I would like to hear a joke.",
"I'd love to hear a joke.",
"I'd like to hear a joke."
]
n = 1000 # number of generated jokes
path = 'results/joke_generation'
df = pd.read_pickle(path)
print('####', df.shape[1])
j = 74 # This seems to be the max. number of prompts per hour
for i in range(n-df.shape[1]):
j += 1
if j > 74:
print("Reached max. Sleep for one hour.")
time.sleep(900)
print("15 minutes passed.")
time.sleep(900)
print("Half an hour left")
time.sleep(900)
print("15 more minutes.")
time.sleep(900)
j = 1
print('new loop')
#while(df.shape[1]<=1000):
df = pd.read_pickle(path)
prompt_number = (i+3)%len(prompts)
# print(prompt_number)
prompt = prompts[prompt_number]
try:
resp = api.send_message(prompt)
print(F"{i}: {prompt} - {resp}")
data = {"prompt": [prompt_number], "response": [resp]}
df2 = pd.DataFrame(data)
df = pd.concat([df,df2])
df.to_pickle(path)
time.sleep(3)
except TimeoutException as ex:
print(F"Oops! {ex}")
api.refresh_chat_page()
time.sleep(3)
except ValueError as err:
print(F"Oops! {err}")
print(type(err))
if "Too many requests" in str(err):
print(err)#)"I'll try again in 15 Minutes")
#time.sleep(900)
#api.refresh_chat_page()
#raise
if "Only one message at a time":
i=i-1
#raise
else:
print(F'something else: {err}')
print("### reached 1000 examples ###")