Spaces:
Runtime error
Runtime error
Jin Ziqi
commited on
Commit
·
c98240c
1
Parent(s):
ee0fa6a
Add application file
Browse files
app.py
CHANGED
@@ -18,50 +18,9 @@ import datetime
|
|
18 |
import pandas as pd
|
19 |
import sys
|
20 |
|
21 |
-
def greet(
|
22 |
-
|
23 |
-
|
24 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
25 |
-
iface.launch()
|
26 |
-
|
27 |
-
|
28 |
-
# Sentence Generator (Decoder) for GPT-3 ...
|
29 |
-
def decoder_for_gpt3(args, input, max_length, i, k, filename):
|
30 |
-
|
31 |
-
# GPT-3 API allows each users execute the API within 60 times in a minute ...
|
32 |
-
# time.sleep(1)
|
33 |
-
time.sleep(args.api_time_interval)
|
34 |
-
|
35 |
-
# https://beta.openai.com/account/api-keys
|
36 |
-
# api_list = []
|
37 |
-
# with open(filename,"r") as f:
|
38 |
-
# api_list = [line.rstrip('\n') for line in f]
|
39 |
-
# first_api = api_list[0]
|
40 |
-
# api_list = api_list[1:]
|
41 |
-
# api_list.append(first_api)
|
42 |
-
openai.api_key = "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"
|
43 |
-
|
44 |
-
#print(openai.api_key)
|
45 |
-
|
46 |
-
# Specify engine ...
|
47 |
-
# Instruct GPT3
|
48 |
-
if args.model == "gpt3":
|
49 |
-
engine = "text-ada-001"
|
50 |
-
elif args.model == "gpt3-medium":
|
51 |
-
engine = "text-babbage-001"
|
52 |
-
elif args.model == "gpt3-large":
|
53 |
-
engine = "code-cushman-001"
|
54 |
-
elif args.model == "gpt3-xl": # Please change this back
|
55 |
-
engine = "code-davinci-002"
|
56 |
-
elif args.model == "chatgpt":
|
57 |
-
engine = "gpt-3.5-turbo-0301"
|
58 |
-
else:
|
59 |
-
raise ValueError("model is not properly defined ...")
|
60 |
-
cnt = 0
|
61 |
-
while True:
|
62 |
-
try:
|
63 |
-
if args.model=="chatgpt":
|
64 |
-
response = openai.ChatCompletion.create(
|
65 |
model="gpt-3.5-turbo",
|
66 |
messages=[
|
67 |
{"role": "system", "content": "You are a helpful assistant that generate table to solve reasoning problem."},
|
@@ -69,51 +28,10 @@ def decoder_for_gpt3(args, input, max_length, i, k, filename):
|
|
69 |
|
70 |
]
|
71 |
)
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
# temperature=0,
|
79 |
-
# stop='\n\n'
|
80 |
-
# )
|
81 |
-
# return response["choices"][0]["text"]
|
82 |
-
except KeyboardInterrupt:
|
83 |
-
print('Interrupted')
|
84 |
-
try:
|
85 |
-
sys.exit(0)
|
86 |
-
except SystemExit:
|
87 |
-
os._exit(0)
|
88 |
-
except openai.error.RateLimitError:
|
89 |
-
time.sleep(3)
|
90 |
-
cnt += 1
|
91 |
-
print(cnt)
|
92 |
-
if cnt >= 10:
|
93 |
-
print("!!!Error Occur " + input)
|
94 |
-
print("Unexpected error:", sys.exc_info()[0])
|
95 |
-
print(len(api_list))
|
96 |
-
api_list.remove(api_list[0])
|
97 |
-
with open(filename, 'w') as f:
|
98 |
-
for s in api_list:
|
99 |
-
f.write(s + '\n')
|
100 |
-
continue
|
101 |
|
102 |
-
except openai.error.ServiceUnavailableError:
|
103 |
-
time.sleep(2)
|
104 |
-
continue
|
105 |
-
except openai.error.APIConnectionError:
|
106 |
-
time.sleep(2)
|
107 |
-
continue
|
108 |
-
except openai.error.APIError:
|
109 |
-
time.sleep(2)
|
110 |
-
continue
|
111 |
-
except:
|
112 |
-
print("!!!Error Occur " + input)
|
113 |
-
print("Unexpected error:", sys.exc_info()[0])
|
114 |
-
print(len(api_list))
|
115 |
-
api_list.remove(api_list[0])
|
116 |
-
with open(filename, 'w') as f:
|
117 |
-
for s in api_list:
|
118 |
-
f.write(s + '\n')
|
119 |
-
continue
|
|
|
18 |
import pandas as pd
|
19 |
import sys
|
20 |
|
21 |
+
def greet(question):
|
22 |
+
input = question + '\n\n' + "|step|subquestion|process|result|"
|
23 |
+
response = openai.ChatCompletion.create(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
model="gpt-3.5-turbo",
|
25 |
messages=[
|
26 |
{"role": "system", "content": "You are a helpful assistant that generate table to solve reasoning problem."},
|
|
|
28 |
|
29 |
]
|
30 |
)
|
31 |
+
response = response["choices"][0]["message"]["content"]
|
32 |
+
return "|step|subquestion|process|result|\n" + response
|
33 |
+
|
34 |
+
|
35 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
36 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|