Spaces:
Running
Running
更新提示
Browse files- request_llm/bridge_chatgpt.py +2 -2
- toolbox.py +13 -0
request_llm/bridge_chatgpt.py
CHANGED
@@ -21,7 +21,7 @@ import importlib
|
|
21 |
|
22 |
# config_private.py放自己的秘密如API和代理网址
|
23 |
# 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件
|
24 |
-
from toolbox import get_conf, update_ui, is_any_api_key, select_api_key
|
25 |
proxies, API_KEY, TIMEOUT_SECONDS, MAX_RETRY = \
|
26 |
get_conf('proxies', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY')
|
27 |
|
@@ -118,7 +118,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
|
|
118 |
"""
|
119 |
if is_any_api_key(inputs):
|
120 |
chatbot._cookies['api_key'] = inputs
|
121 |
-
chatbot.append(("输入已识别为openai的api_key",
|
122 |
yield from update_ui(chatbot=chatbot, history=history, msg="api_key已导入") # 刷新界面
|
123 |
return
|
124 |
elif not is_any_api_key(chatbot._cookies['api_key']):
|
|
|
21 |
|
22 |
# config_private.py放自己的秘密如API和代理网址
|
23 |
# 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件
|
24 |
+
from toolbox import get_conf, update_ui, is_any_api_key, select_api_key, what_keys
|
25 |
proxies, API_KEY, TIMEOUT_SECONDS, MAX_RETRY = \
|
26 |
get_conf('proxies', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY')
|
27 |
|
|
|
118 |
"""
|
119 |
if is_any_api_key(inputs):
|
120 |
chatbot._cookies['api_key'] = inputs
|
121 |
+
chatbot.append(("输入已识别为openai的api_key", what_keys(inputs)))
|
122 |
yield from update_ui(chatbot=chatbot, history=history, msg="api_key已导入") # 刷新界面
|
123 |
return
|
124 |
elif not is_any_api_key(chatbot._cookies['api_key']):
|
toolbox.py
CHANGED
@@ -432,6 +432,19 @@ def is_any_api_key(key):
|
|
432 |
else:
|
433 |
return is_openai_api_key(key) or is_api2d_key(key)
|
434 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
|
436 |
def select_api_key(keys, llm_model):
|
437 |
import random
|
|
|
432 |
else:
|
433 |
return is_openai_api_key(key) or is_api2d_key(key)
|
434 |
|
435 |
+
def what_keys(keys):
|
436 |
+
avail_key_list = {'OpenAI Key':0, "API2D Key":0}
|
437 |
+
key_list = keys.split(',')
|
438 |
+
|
439 |
+
for k in key_list:
|
440 |
+
if is_openai_api_key(k):
|
441 |
+
avail_key_list['OpenAI Key'] += 1
|
442 |
+
|
443 |
+
for k in key_list:
|
444 |
+
if is_api2d_key(k):
|
445 |
+
avail_key_list['API2D Key'] += 1
|
446 |
+
|
447 |
+
return f"检测到: OpenAI Key {avail_key_list['OpenAI Key']} 个,API2D Key {avail_key_list['API2D Key']} 个"
|
448 |
|
449 |
def select_api_key(keys, llm_model):
|
450 |
import random
|