Spaces:
Build error
Build error
Tuchuanhuhuhu commited on
Commit ·
2c7dccc
1
Parent(s): 76a432f
feat: 从配置文件加载保存的参数
Browse filesFiles changed (4)
498 unmodified lines49950050150250350450550650750850951051151237 unmodified lines55055155255355455555630 unmodified lines58758858959059159259399 unmodified lines69369469569669769869925 unmodified lines72572672772872973073173273373473573673773873974074174274374474574674774835 unmodified lines784785786787788789790498 unmodified linesmodel_name=MODELS[DEFAULT_MODEL], access_key=my_api_key)[0]current_model.set_user_identifier(user_name)if not hide_history_when_not_logged_in or user_name:filename, system_prompt, chatbot = current_model.auto_load()else:system_prompt = gr.update()filename = gr.update()chatbot = gr.Chatbot.update(label=MODELS[DEFAULT_MODEL])return user_info, user_name, current_model, toggle_like_btn_visibility(DEFAULT_MODEL), filename, system_prompt, chatbot, init_history_list(user_name)demo.load(create_greeting, inputs=None, outputs=[user_info, user_name, current_model, like_dislike_area, saveFileName, systemPromptTxt, chatbot, historySelectList], api_name="load")chatgpt_predict_args = dict(fn=predict,inputs=[37 unmodified linesload_history_from_file_args = dict(fn=load_chat_history,inputs=[current_model, historySelectList],outputs=[saveFileName, systemPromptTxt, chatbot])refresh_history_args = dict(30 unmodified linesemptyBtn.click(reset,inputs=[current_model, retain_system_prompt_checkbox],outputs=[chatbot, status_display, historySelectList, systemPromptTxt],show_progress=True,_js='(a,b)=>{return clearChatbot(a,b);}',)99 unmodified lines)historySelectList.input(**load_history_from_file_args)uploadFileBtn.upload(upload_chat_history, [current_model, uploadFileBtn], [saveFileName, systemPromptTxt, chatbot]).then(**refresh_history_args)historyDownloadBtn.click(None, [user_name, historySelectList], None, _js='(a,b)=>{return downloadHistory(a,b,".json");}')historyMarkdownDownloadBtn.click(None, [25 unmodified linescancel_all_jobs, [], [openai_train_status], show_progress=True)# Advancedmax_context_length_slider.change(set_token_upper_limit, [current_model, max_context_length_slider], None)temperature_slider.change(set_temperature, [current_model, temperature_slider], None)top_p_slider.change(set_top_p, [current_model, top_p_slider], None)n_choices_slider.change(set_n_choices, [current_model, n_choices_slider], None)stop_sequence_txt.change(set_stop_sequence, [current_model, stop_sequence_txt], None)max_generation_slider.change(set_max_tokens, [current_model, max_generation_slider], None)presence_penalty_slider.change(set_presence_penalty, [current_model, presence_penalty_slider], None)frequency_penalty_slider.change(set_frequency_penalty, [current_model, frequency_penalty_slider], None)logit_bias_txt.change(set_logit_bias, [current_model, logit_bias_txt], None)user_identifier_txt.change(set_user_identifier, [current_model, user_identifier_txt], None)default_btn.click(35 unmodified lineshistorySelectBtn.click( # This is an experimental feature... Not actually used.fn=load_chat_history,inputs=[current_model, historySelectList],outputs=[saveFileName, systemPromptTxt, chatbot],_js='(a,b)=>{return bgSelectHistory(a,b);}')498 unmodified lines49950050150250350450550650750850951037 unmodified lines54854955055155255355430 unmodified lines58558658758858959059199 unmodified lines69169269369469569669725 unmodified lines72372472572672772872973073173273373473573673773873974074174274374474574635 unmodified lines782783784785786787788498 unmodified linesmodel_name=MODELS[DEFAULT_MODEL], access_key=my_api_key)[0]current_model.set_user_identifier(user_name)if not hide_history_when_not_logged_in or user_name:loaded_stuff = current_model.auto_load()else:loaded_stuff = [gr.update(), gr.update(), gr.Chatbot.update(label=MODELS[DEFAULT_MODEL]), current_model.single_turn, current_model.temperature, current_model.top_p, current_model.n_choices, current_model.stop_sequence, current_model.token_upper_limit, current_model.max_generation_token, current_model.presence_penalty, current_model.frequency_penalty, current_model.logit_bias, current_model.user_identifier]return user_info, user_name, current_model, toggle_like_btn_visibility(DEFAULT_MODEL), *loaded_stuff, init_history_list(user_name)demo.load(create_greeting, inputs=None, outputs=[user_info, user_name, current_model, like_dislike_area, saveFileName, systemPromptTxt, chatbot, single_turn_checkbox, temperature_slider, top_p_slider, n_choices_slider, stop_sequence_txt, max_context_length_slider, max_generation_slider, presence_penalty_slider, frequency_penalty_slider, logit_bias_txt, user_identifier_txt, historySelectList], api_name="load")chatgpt_predict_args = dict(fn=predict,inputs=[37 unmodified linesload_history_from_file_args = dict(fn=load_chat_history,inputs=[current_model, historySelectList],outputs=[saveFileName, systemPromptTxt, chatbot, single_turn_checkbox, temperature_slider, top_p_slider, n_choices_slider, stop_sequence_txt, max_context_length_slider, max_generation_slider, presence_penalty_slider, frequency_penalty_slider, logit_bias_txt, user_identifier_txt],)refresh_history_args = dict(30 unmodified linesemptyBtn.click(reset,inputs=[current_model, retain_system_prompt_checkbox],outputs=[chatbot, status_display, historySelectList, systemPromptTxt, single_turn_checkbox, temperature_slider, top_p_slider, n_choices_slider, stop_sequence_txt, max_context_length_slider, max_generation_slider, presence_penalty_slider, frequency_penalty_slider, logit_bias_txt, user_identifier_txt],show_progress=True,_js='(a,b)=>{return clearChatbot(a,b);}',)99 unmodified lines)historySelectList.input(**load_history_from_file_args)uploadFileBtn.upload(upload_chat_history, [current_model, uploadFileBtn], [saveFileName, systemPromptTxt, chatbot, single_turn_checkbox, temperature_slider, top_p_slider, n_choices_slider, stop_sequence_txt, max_context_length_slider, max_generation_slider, presence_penalty_slider, frequency_penalty_slider, logit_bias_txt, user_identifier_txt]).then(**refresh_history_args)historyDownloadBtn.click(None, [user_name, historySelectList], None, _js='(a,b)=>{return downloadHistory(a,b,".json");}')historyMarkdownDownloadBtn.click(None, [25 unmodified linescancel_all_jobs, [], [openai_train_status], show_progress=True)# Advancedmax_context_length_slider.input(set_token_upper_limit, [current_model, max_context_length_slider], None)temperature_slider.input(set_temperature, [current_model, temperature_slider], None)top_p_slider.input(set_top_p, [current_model, top_p_slider], None)n_choices_slider.input(set_n_choices, [current_model, n_choices_slider], None)stop_sequence_txt.input(set_stop_sequence, [current_model, stop_sequence_txt], None)max_generation_slider.input(set_max_tokens, [current_model, max_generation_slider], None)presence_penalty_slider.input(set_presence_penalty, [current_model, presence_penalty_slider], None)frequency_penalty_slider.input(set_frequency_penalty, [current_model, frequency_penalty_slider], None)logit_bias_txt.input(set_logit_bias, [current_model, logit_bias_txt], None)user_identifier_txt.input(set_user_identifier, [current_model, user_identifier_txt], None)default_btn.click(35 unmodified lineshistorySelectBtn.click( # This is an experimental feature... Not actually used.fn=load_chat_history,inputs=[current_model, historySelectList],outputs=[saveFileName, systemPromptTxt, chatbot, single_turn_checkbox, temperature_slider, top_p_slider, n_choices_slider, stop_sequence_txt, max_context_length_slider, max_generation_slider, presence_penalty_slider, frequency_penalty_slider, logit_bias_txt, user_identifier_txt],_js='(a,b)=>{return bgSelectHistory(a,b);}')
31 unmodified lines32333435363731 unmodified linessystem_prompt=system_prompt,user=user_name)self.api_key = api_keyself.need_api_key = Trueself._refresh_header()31 unmodified lines3233343536373831 unmodified linessystem_prompt=system_prompt,user=user_name)logging.info(f"TEMPERATURE: {self.temperature}")self.api_key = api_keyself.need_api_key = Trueself._refresh_header()
213 unmodified lines21421521621721821910 unmodified lines23023123223323423523623723823911 unmodified lines251252253254255256257491 unmodified lines749750751752753754755756757758759117 unmodified lines8778788798808818828838848858868878888898908918928938948958968978988999009019029039049059063 unmodified lines91091191291391491591691791815 unmodified lines934935936937938939940941942213 unmodified linesfrequency_penalty=0,logit_bias=None,user="",) -> None:self.history = []self.all_token_counts = []10 unmodified linesself.system_prompt = system_promptself.api_key = Noneself.need_api_key = Falseself.single_turn = Falseself.history_file_path = get_first_history_name(user)self.user_name = userself.temperature = temperatureself.top_p = top_pself.n_choices = n_choices11 unmodified linesConversations are stored in self.history, with the most recent question in OpenAI format.Should return a generator that yields the next word (str) in the answer."""logging.warning("Stream prediction is not implemented. Using at once prediction instead.")response, _ = self.get_answer_at_once()yield response491 unmodified lineshistory_name = self.history_file_path[:-5]choices = [history_name] + get_history_names(self.user_name)system_prompt = self.system_prompt if remain_system_prompt else ""return ([],self.token_message([0]),gr.Radio.update(choices=choices, value=history_name),system_prompt,)def delete_first_conversation(self):117 unmodified linespassif len(saved_json["chatbot"]) < len(saved_json["history"]) // 2:logging.info("Trimming corrupted history...")saved_json["history"] = saved_json["history"][-len(saved_json["chatbot"]) :]logging.info(f"Trimmed history: {saved_json['history']}")logging.debug(f"{self.user_name} 加载对话历史完毕")self.history = saved_json["history"]self.single_turn = saved_json.get("single_turn", False)self.temperature = saved_json.get("temperature", 1.0)self.top_p = saved_json.get("top_p", None)self.n_choices = saved_json.get("n_choices", 1)self.stop_sequence = saved_json.get("stop_sequence", None)self.max_generation_token = saved_json.get("max_generation_token", None)self.presence_penalty = saved_json.get("presence_penalty", 0)self.frequency_penalty = saved_json.get("frequency_penalty", 0)self.logit_bias = saved_json.get("logit_bias", None)self.user_identifier = saved_json.get("user_identifier", self.user_name)self.metadata = saved_json.get("metadata", {})return (os.path.basename(self.history_file_path),saved_json["system"],saved_json["chatbot"],)except:# 没有对话历史或者对话历史解析失败logging.info(f"没有找到对话历史记录 {self.history_file_path}")return self.history_file_path, "", []def delete_chat_history(self, filename):if filename == "CANCELED":3 unmodified linesif not filename.endswith(".json"):filename += ".json"if filename == os.path.basename(filename):history_file_path = os.path.join(HISTORY_DIR, self.user_name, filename)else:history_file_path = filenamemd_history_file_path = history_file_path[:-5] + ".md"15 unmodified linesself.history_file_path = new_auto_history_filename(self.user_name)else:self.history_file_path = filepathfilename, system_prompt, chatbot = self.load_chat_history()filename = filename[:-5]return filename, system_prompt, chatbotdef like(self):"""like the last response, implement if needed"""213 unmodified lines21421521621721821922010 unmodified lines23123223323423523623723823924024124224324424524624724824925025111 unmodified lines263264265266267268269270271491 unmodified lines763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796117 unmodified lines9149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799803 unmodified lines98498598698798898999015 unmodified lines1006100710081009101010111012213 unmodified linesfrequency_penalty=0,logit_bias=None,user="",single_turn=False,) -> None:self.history = []self.all_token_counts = []10 unmodified linesself.system_prompt = system_promptself.api_key = Noneself.need_api_key = Falseself.history_file_path = get_first_history_name(user)self.user_name = userself.default_single_turn = single_turnself.default_temperature = temperatureself.default_top_p = top_pself.default_n_choices = n_choicesself.default_stop_sequence = stopself.default_max_generation_token = max_generation_tokenself.default_presence_penalty = presence_penaltyself.default_frequency_penalty = frequency_penaltyself.default_logit_bias = logit_biasself.default_user_identifier = userself.single_turn = single_turnself.temperature = temperatureself.top_p = top_pself.n_choices = n_choices11 unmodified linesConversations are stored in self.history, with the most recent question in OpenAI format.Should return a generator that yields the next word (str) in the answer."""logging.warning("Stream prediction is not implemented. Using at once prediction instead.")response, _ = self.get_answer_at_once()yield response491 unmodified lineshistory_name = self.history_file_path[:-5]choices = [history_name] + get_history_names(self.user_name)system_prompt = self.system_prompt if remain_system_prompt else ""self.single_turn = self.default_single_turnself.temperature = self.default_temperatureself.top_p = self.default_top_pself.n_choices = self.default_n_choicesself.stop_sequence = self.default_stop_sequenceself.max_generation_token = self.default_max_generation_tokenself.presence_penalty = self.default_presence_penaltyself.frequency_penalty = self.default_frequency_penaltyself.logit_bias = self.default_logit_biasself.user_identifier = self.default_user_identifierreturn ([],self.token_message([0]),gr.Radio.update(choices=choices, value=history_name),system_prompt,self.single_turn,self.temperature,self.top_p,self.n_choices,self.stop_sequence,self.token_upper_limit,self.max_generation_token,self.presence_penalty,self.frequency_penalty,self.logit_bias,self.user_identifier,)def delete_first_conversation(self):117 unmodified linespassif len(saved_json["chatbot"]) < len(saved_json["history"]) // 2:logging.info("Trimming corrupted history...")saved_json["history"] = saved_json["history"][-len(saved_json["chatbot"]) :]logging.info(f"Trimmed history: {saved_json['history']}")logging.debug(f"{self.user_name} 加载对话历史完毕")self.history = saved_json["history"]self.single_turn = saved_json.get("single_turn", self.single_turn)self.temperature = saved_json.get("temperature", self.temperature)self.top_p = saved_json.get("top_p", self.top_p)self.n_choices = saved_json.get("n_choices", self.n_choices)self.stop_sequence = saved_json.get("stop_sequence", self.stop_sequence)self.token_upper_limit = saved_json.get("token_upper_limit", self.token_upper_limit)self.max_generation_token = saved_json.get("max_generation_token", self.max_generation_token)self.presence_penalty = saved_json.get("presence_penalty", self.presence_penalty)self.frequency_penalty = saved_json.get("frequency_penalty", self.frequency_penalty)self.logit_bias = saved_json.get("logit_bias", self.logit_bias)self.user_identifier = saved_json.get("user_identifier", self.user_name)self.metadata = saved_json.get("metadata", self.metadata)return (os.path.basename(self.history_file_path)[:-5],saved_json["system"],saved_json["chatbot"],self.single_turn,self.temperature,self.top_p,self.n_choices,self.stop_sequence,self.token_upper_limit,self.max_generation_token,self.presence_penalty,self.frequency_penalty,self.logit_bias,self.user_identifier,)except:# 没有对话历史或者对话历史解析失败logging.info(f"没有找到对话历史记录 {self.history_file_path}")return (os.path.basename(self.history_file_path),"",[],self.single_turn,self.temperature,self.top_p,self.n_choices,self.stop_sequence,self.token_upper_limit,self.max_generation_token,self.presence_penalty,self.frequency_penalty,self.logit_bias,self.user_identifier,)def delete_chat_history(self, filename):if filename == "CANCELED":3 unmodified linesif not filename.endswith(".json"):filename += ".json"if filename == os.path.basename(filename):history_file_path = os.path.join(HISTORY_DIR, self.user_name, filename)else:history_file_path = filenamemd_history_file_path = history_file_path[:-5] + ".md"15 unmodified linesself.history_file_path = new_auto_history_filename(self.user_name)else:self.history_file_path = filepathreturn self.load_chat_history()def like(self):"""like the last response, implement if needed"""
388 unmodified lines389390391392393394388 unmodified lines"top_p": model.top_p,"n_choices": model.n_choices,"stop_sequence": model.stop_sequence,"max_generation_token": model.max_generation_token,"presence_penalty": model.presence_penalty,"frequency_penalty": model.frequency_penalty,388 unmodified lines389390391392393394395388 unmodified lines"top_p": model.top_p,"n_choices": model.n_choices,"stop_sequence": model.stop_sequence,"token_upper_limit": model.token_upper_limit,"max_generation_token": model.max_generation_token,"presence_penalty": model.presence_penalty,"frequency_penalty": model.frequency_penalty,
ChuanhuChatbot.py+18-20
modules/models/OpenAI.py+1
modules/models/base_model.py+91-21
modules/utils.py+1