MZhaovo commited on
Commit
29d1af8
1 Parent(s): 9911cfb

修复 #606:新增变量隐式记录api-key

Browse files
Files changed (2) hide show
  1. ChuanhuChatbot.py +5 -4
  2. modules/base_model.py +1 -1
ChuanhuChatbot.py CHANGED
@@ -25,6 +25,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
25
  user_name = gr.State("")
26
  promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
27
  user_question = gr.State("")
 
28
  current_model = gr.State(create_new_model)
29
 
30
  topic = gr.State("未命名对话历史记录")
@@ -71,7 +72,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
71
  keyTxt = gr.Textbox(
72
  show_label=True,
73
  placeholder=f"OpenAI API-key...",
74
- value=hide_middle_chars(my_api_key),
75
  type="password",
76
  visible=not HIDE_MY_KEY,
77
  label="API-Key",
@@ -359,11 +360,11 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
359
  two_column.change(update_doc_config, [two_column], None)
360
 
361
  # LLM Models
362
- keyTxt.change(set_key, [current_model, keyTxt], [status_display]).then(**get_usage_args)
363
  keyTxt.submit(**get_usage_args)
364
  single_turn_checkbox.change(set_single_turn, [current_model, single_turn_checkbox], None)
365
- model_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, keyTxt, temperature_slider, top_p_slider, systemPromptTxt], [current_model, status_display, lora_select_dropdown], show_progress=True)
366
- lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, keyTxt, temperature_slider, top_p_slider, systemPromptTxt], [current_model, status_display], show_progress=True)
367
 
368
  # Template
369
  systemPromptTxt.change(set_system_prompt, [current_model, systemPromptTxt], None)
 
25
  user_name = gr.State("")
26
  promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
27
  user_question = gr.State("")
28
+ user_api_key = gr.State(my_api_key)
29
  current_model = gr.State(create_new_model)
30
 
31
  topic = gr.State("未命名对话历史记录")
 
72
  keyTxt = gr.Textbox(
73
  show_label=True,
74
  placeholder=f"OpenAI API-key...",
75
+ value=hide_middle_chars(user_api_key.value),
76
  type="password",
77
  visible=not HIDE_MY_KEY,
78
  label="API-Key",
 
360
  two_column.change(update_doc_config, [two_column], None)
361
 
362
  # LLM Models
363
+ keyTxt.change(set_key, [current_model, keyTxt], [user_api_key, status_display]).then(**get_usage_args)
364
  keyTxt.submit(**get_usage_args)
365
  single_turn_checkbox.change(set_single_turn, [current_model, single_turn_checkbox], None)
366
+ model_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, top_p_slider, systemPromptTxt], [current_model, status_display, lora_select_dropdown], show_progress=True)
367
+ lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, top_p_slider, systemPromptTxt], [current_model, status_display], show_progress=True)
368
 
369
  # Template
370
  systemPromptTxt.change(set_system_prompt, [current_model, systemPromptTxt], None)
modules/base_model.py CHANGED
@@ -443,7 +443,7 @@ class BaseLLMModel:
443
  self.api_key = new_access_key.strip()
444
  msg = f"API密钥更改为了{hide_middle_chars(self.api_key)}"
445
  logging.info(msg)
446
- return msg
447
 
448
  def set_single_turn(self, new_single_turn):
449
  self.single_turn = new_single_turn
 
443
  self.api_key = new_access_key.strip()
444
  msg = f"API密钥更改为了{hide_middle_chars(self.api_key)}"
445
  logging.info(msg)
446
+ return new_access_key, msg
447
 
448
  def set_single_turn(self, new_single_turn):
449
  self.single_turn = new_single_turn