MZhao commited on
Commit
f4e0fdd
·
unverified ·
1 Parent(s): 9c7114f

添加高级设置:apiHost地址、proxy地址 (#205)

Browse files
Files changed (2) hide show
  1. ChuanhuChatbot.py +43 -2
  2. utils.py +16 -0
ChuanhuChatbot.py CHANGED
@@ -183,6 +183,28 @@ with gr.Blocks(css=customCSS) as demo:
183
  with gr.Row():
184
  with gr.Column():
185
  downloadFile = gr.File(interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
  gr.Markdown(description)
188
 
@@ -315,8 +337,27 @@ with gr.Blocks(css=customCSS) as demo:
315
  [downloadFile, systemPromptTxt, history, chatbot],
316
  [saveFileName, systemPromptTxt, history, chatbot],
317
  )
318
-
319
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  logging.info(
321
  colorama.Back.GREEN
322
  + "\n川虎的温馨提示:访问 http://localhost:7860 查看界面"
 
183
  with gr.Row():
184
  with gr.Column():
185
  downloadFile = gr.File(interactive=True)
186
+
187
+ with gr.Tab(label="高级"):
188
+ default_btn = gr.Button("🔙 恢复默认设置")
189
+ gr.Markdown("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置")
190
+
191
+ apiurlTxt = gr.Textbox(
192
+ show_label=True,
193
+ placeholder=f"在这里输入API地址...",
194
+ label="API地址",
195
+ value="https://api.openai.com/v1/chat/completions",
196
+ lines=2
197
+ )
198
+ changeAPIURLBtn = gr.Button("🔄 切换API地址")
199
+ proxyTxt = gr.Textbox(
200
+ show_label=True,
201
+ placeholder=f"在这里输入代理地址...",
202
+ label="代理地址(示例:http://127.0.0.1:10809)",
203
+ value="",
204
+ lines=2
205
+ )
206
+ changeProxyBtn = gr.Button("🔄 设置代理地址")
207
+
208
 
209
  gr.Markdown(description)
210
 
 
337
  [downloadFile, systemPromptTxt, history, chatbot],
338
  [saveFileName, systemPromptTxt, history, chatbot],
339
  )
340
+
341
+ # Advanced
342
+ default_btn.click(
343
+ reset_default,
344
+ [],
345
+ [apiurlTxt, proxyTxt],
346
+ show_progress=True
347
+ )
348
+ changeAPIURLBtn.click(
349
+ change_api_url,
350
+ [apiurlTxt],
351
+ [],
352
+ show_progress=True,
353
+ )
354
+ changeProxyBtn.click(
355
+ change_proxy,
356
+ [proxyTxt],
357
+ [],
358
+ show_progress=True,
359
+ )
360
+
361
  logging.info(
362
  colorama.Back.GREEN
363
  + "\n川虎的温馨提示:访问 http://localhost:7860 查看界面"
utils.py CHANGED
@@ -642,3 +642,19 @@ def reset_state():
642
 
643
  def reset_textbox():
644
  return gr.update(value="")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642
 
643
  def reset_textbox():
644
  return gr.update(value="")
645
+
646
+ def reset_default():
647
+ global API_URL
648
+ API_URL = "https://api.openai.com/v1/chat/completions"
649
+ os.environ.pop("HTTPS_PROXY", None)
650
+ os.environ.pop("https_proxy", None)
651
+ return gr.update(value=API_URL), gr.update(value="")
652
+
653
+ def change_api_url(url):
654
+ global API_URL
655
+ API_URL = url
656
+ logging.info(f"更改API地址为{url}")
657
+
658
+ def change_proxy(proxy):
659
+ os.environ["HTTPS_PROXY"] = proxy
660
+ logging.info(f"更改代理为{proxy}")