Tuchuanhuhuhu commited on
Commit
64889e9
1 Parent(s): d82d8f9

重新加入在UI中设置API-Key的功能

Browse files
Files changed (2) hide show
  1. ChuanhuChatbot.py +1 -2
  2. modules/base_model.py +7 -0
ChuanhuChatbot.py CHANGED
@@ -21,7 +21,6 @@ with open("assets/custom.css", "r", encoding="utf-8") as f:
21
  with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
22
  user_name = gr.State("")
23
  promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
24
- user_api_key = gr.State(my_api_key)
25
  user_question = gr.State("")
26
  current_model = gr.State(get_model(MODELS[0], my_api_key)[0])
27
 
@@ -288,7 +287,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
288
  two_column.change(update_doc_config, [two_column], None)
289
 
290
  # LLM Models
291
- keyTxt.change(submit_key, keyTxt, [user_api_key, status_display]).then(**get_usage_args)
292
  keyTxt.submit(**get_usage_args)
293
  model_select_dropdown.change(get_model, [model_select_dropdown, keyTxt, temperature_slider, top_p_slider, systemPromptTxt], [current_model, status_display], show_progress=True)
294
 
 
21
  with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
22
  user_name = gr.State("")
23
  promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
 
24
  user_question = gr.State("")
25
  current_model = gr.State(get_model(MODELS[0], my_api_key)[0])
26
 
 
287
  two_column.change(update_doc_config, [two_column], None)
288
 
289
  # LLM Models
290
+ keyTxt.change(current_model.value.set_key, keyTxt, [status_display]).then(**get_usage_args)
291
  keyTxt.submit(**get_usage_args)
292
  model_select_dropdown.change(get_model, [model_select_dropdown, keyTxt, temperature_slider, top_p_slider, systemPromptTxt], [current_model, status_display], show_progress=True)
293
 
modules/base_model.py CHANGED
@@ -52,6 +52,7 @@ class BaseLLMModel:
52
  self.temperature = temperature
53
  self.top_p = top_p
54
  self.system_prompt = system_prompt
 
55
 
56
 
57
  def get_answer_stream_iter(self):
@@ -349,6 +350,12 @@ class BaseLLMModel:
349
  def set_system_prompt(self, new_system_prompt):
350
  self.system_prompt = new_system_prompt
351
 
 
 
 
 
 
 
352
  def reset(self):
353
  self.history = []
354
  self.all_token_counts = []
 
52
  self.temperature = temperature
53
  self.top_p = top_p
54
  self.system_prompt = system_prompt
55
+ self.api_key = None
56
 
57
 
58
  def get_answer_stream_iter(self):
 
350
  def set_system_prompt(self, new_system_prompt):
351
  self.system_prompt = new_system_prompt
352
 
353
+ def set_key(self, new_access_key):
354
+ self.api_key = new_access_key.strip()
355
+ msg = f"API密钥更改为了{hide_middle_chars(self.api_key)}"
356
+ logging.info(msg)
357
+ return msg
358
+
359
  def reset(self):
360
  self.history = []
361
  self.all_token_counts = []