write the app.py and upload data
Browse files
app.py
CHANGED
@@ -9,7 +9,8 @@ import pytz
|
|
9 |
import json
|
10 |
import os
|
11 |
|
12 |
-
openai.
|
|
|
13 |
|
14 |
timezone = pytz.timezone('Asia/Shanghai')
|
15 |
timestamp2string = lambda timestamp: datetime.datetime.fromtimestamp(timestamp).astimezone(timezone).strftime('%Y-%m-%d %H:%M:%S')
|
@@ -89,6 +90,11 @@ def ask(query, max_attempt_times=3):
|
|
89 |
)["choices"][0]["message"]["content"]
|
90 |
except Exception as e:
|
91 |
print(e)
|
|
|
|
|
|
|
|
|
|
|
92 |
print(f"retry in {attempt_times*10} seconds...")
|
93 |
time.sleep(attempt_times*10)
|
94 |
return answer
|
@@ -170,7 +176,7 @@ def display(access_key):
|
|
170 |
chatbot_ret += [(f"The hours already takes / est. remains:", f"{time_takes/3600:.2f} / {time_remains/3600:.2f}")]
|
171 |
chatbot_ret += [(f"The time starts / est. ends:", f"{timestamp2string(start_time)} / {timestamp2string(end_time)}")]
|
172 |
chatbot_ret += [(f"The number of processed / est. total tokens:", f"{num_tokens_processed} / {num_tokens_total}")]
|
173 |
-
chatbot_ret += [(f"The dollars of processed / est. total tokens:", f"{dollars_tokens_processed} / {dollars_tokens_total}")]
|
174 |
|
175 |
return chatbot_ret
|
176 |
|
|
|
9 |
import json
|
10 |
import os
|
11 |
|
12 |
+
openai.api_keys = os.getenv('API_KEYs').split("\n")
|
13 |
+
openai.api_key = openai.api_keys[0]
|
14 |
|
15 |
timezone = pytz.timezone('Asia/Shanghai')
|
16 |
timestamp2string = lambda timestamp: datetime.datetime.fromtimestamp(timestamp).astimezone(timezone).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
90 |
)["choices"][0]["message"]["content"]
|
91 |
except Exception as e:
|
92 |
print(e)
|
93 |
+
if "You exceeded your current quota, please check your plan and billing details." in e:
|
94 |
+
idx = openai.api_keys.index(openai.api_key)
|
95 |
+
idx = (idx + 1) % len(openai.api_keys)
|
96 |
+
openai.api_key = openai.api_keys[idx]
|
97 |
+
print(f"switch api_key")
|
98 |
print(f"retry in {attempt_times*10} seconds...")
|
99 |
time.sleep(attempt_times*10)
|
100 |
return answer
|
|
|
176 |
chatbot_ret += [(f"The hours already takes / est. remains:", f"{time_takes/3600:.2f} / {time_remains/3600:.2f}")]
|
177 |
chatbot_ret += [(f"The time starts / est. ends:", f"{timestamp2string(start_time)} / {timestamp2string(end_time)}")]
|
178 |
chatbot_ret += [(f"The number of processed / est. total tokens:", f"{num_tokens_processed} / {num_tokens_total}")]
|
179 |
+
chatbot_ret += [(f"The dollars of processed / est. total tokens:", f"{dollars_tokens_processed:.2f} / {dollars_tokens_total:.2f}")]
|
180 |
|
181 |
return chatbot_ret
|
182 |
|