Spaces:
Runtime error
Runtime error
提示修正
Browse files- request_llm/bridge_chatgpt.py +19 -19
- toolbox.py +2 -3
request_llm/bridge_chatgpt.py
CHANGED
|
@@ -42,17 +42,17 @@ def get_full_error(chunk, stream_response):
|
|
| 42 |
|
| 43 |
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=None, console_slience=False):
|
| 44 |
"""
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
"""
|
| 57 |
watch_dog_patience = 5 # 看门狗的耐心, 设置5秒即可
|
| 58 |
headers, payload = generate_payload(inputs, llm_kwargs, history, system_prompt=sys_prompt, stream=True)
|
|
@@ -105,13 +105,13 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
|
|
| 105 |
|
| 106 |
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
|
| 107 |
"""
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
"""
|
| 116 |
if is_any_api_key(inputs):
|
| 117 |
chatbot._cookies['api_key'] = inputs
|
|
@@ -205,7 +205,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
|
|
| 205 |
|
| 206 |
def generate_payload(inputs, llm_kwargs, history, system_prompt, stream):
|
| 207 |
"""
|
| 208 |
-
|
| 209 |
"""
|
| 210 |
if not is_any_api_key(llm_kwargs['api_key']):
|
| 211 |
raise AssertionError("你提供了错误的API_KEY。\n\n1. 临时解决方案:直接在输入区键入api_key,然后回车提交。\n\n2. 长效解决方案:在config.py中配置。")
|
|
|
|
| 42 |
|
| 43 |
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=None, console_slience=False):
|
| 44 |
"""
|
| 45 |
+
发送至chatGPT,等待回复,一次性完成,不显示中间过程。但内部用stream的方法避免中途网线被掐。
|
| 46 |
+
inputs:
|
| 47 |
+
是本次问询的输入
|
| 48 |
+
sys_prompt:
|
| 49 |
+
系统静默prompt
|
| 50 |
+
llm_kwargs:
|
| 51 |
+
chatGPT的内部调优参数
|
| 52 |
+
history:
|
| 53 |
+
是之前的对话列表
|
| 54 |
+
observe_window = None:
|
| 55 |
+
用于负责跨越线程传递已经输出的部分,大部分时候仅仅为了fancy的视觉效果,留空即可。observe_window[0]:观测窗。observe_window[1]:看门狗
|
| 56 |
"""
|
| 57 |
watch_dog_patience = 5 # 看门狗的耐心, 设置5秒即可
|
| 58 |
headers, payload = generate_payload(inputs, llm_kwargs, history, system_prompt=sys_prompt, stream=True)
|
|
|
|
| 105 |
|
| 106 |
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
|
| 107 |
"""
|
| 108 |
+
发送至chatGPT,流式获取输出。
|
| 109 |
+
用于基础的对话功能。
|
| 110 |
+
inputs 是本次问询的输入
|
| 111 |
+
top_p, temperature是chatGPT的内部调优参数
|
| 112 |
+
history 是之前的对话列表(注意无论是inputs还是history,内容太长了都会触发token数量溢出的错误)
|
| 113 |
+
chatbot 为WebUI中显示的对话列表,修改它,然后yeild出去,可以直接修改对话界面内容
|
| 114 |
+
additional_fn代表点击的哪个按钮,按钮见functional.py
|
| 115 |
"""
|
| 116 |
if is_any_api_key(inputs):
|
| 117 |
chatbot._cookies['api_key'] = inputs
|
|
|
|
| 205 |
|
| 206 |
def generate_payload(inputs, llm_kwargs, history, system_prompt, stream):
|
| 207 |
"""
|
| 208 |
+
整合所有信息,选择LLM模型,生成http请求,为发送请求做准备
|
| 209 |
"""
|
| 210 |
if not is_any_api_key(llm_kwargs['api_key']):
|
| 211 |
raise AssertionError("你提供了错误的API_KEY。\n\n1. 临时解决方案:直接在输入区键入api_key,然后回车提交。\n\n2. 长效解决方案:在config.py中配置。")
|
toolbox.py
CHANGED
|
@@ -461,11 +461,10 @@ def read_single_conf_with_lru_cache(arg):
|
|
| 461 |
if is_any_api_key(r):
|
| 462 |
print亮绿(f"[API_KEY] 您的 API_KEY 是: {r[:15]}*** API_KEY 导入成功")
|
| 463 |
else:
|
| 464 |
-
print亮红( "[API_KEY] 正确的 API_KEY 是
|
| 465 |
-
"(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)")
|
| 466 |
if arg == 'proxies':
|
| 467 |
if r is None:
|
| 468 |
-
print亮红('[PROXY]
|
| 469 |
else:
|
| 470 |
print亮绿('[PROXY] 网络代理状态:已配置。配置信息如下:', r)
|
| 471 |
assert isinstance(r, dict), 'proxies格式错误,请注意proxies选项的格式,不要遗漏括号。'
|
|
|
|
| 461 |
if is_any_api_key(r):
|
| 462 |
print亮绿(f"[API_KEY] 您的 API_KEY 是: {r[:15]}*** API_KEY 导入成功")
|
| 463 |
else:
|
| 464 |
+
print亮红( "[API_KEY] 正确的 API_KEY 是'sk'开头的51位密钥(OpenAI),或者 'fk'开头的41位密钥,请在config文件中修改API密钥之后再运行。")
|
|
|
|
| 465 |
if arg == 'proxies':
|
| 466 |
if r is None:
|
| 467 |
+
print亮红('[PROXY] 网络代理状态:未配置。无代理状态下很可能无法访问OpenAI家族的模型。建议:检查USE_PROXY选项是否修改。')
|
| 468 |
else:
|
| 469 |
print亮绿('[PROXY] 网络代理状态:已配置。配置信息如下:', r)
|
| 470 |
assert isinstance(r, dict), 'proxies格式错误,请注意proxies选项的格式,不要遗漏括号。'
|