Skip to content

Commit

Permalink
Merge branch 'GaiZhenbiao:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
xingfanxia committed Nov 29, 2023
2 parents d6dbc46 + 48d2f65 commit 400a0b5
Show file tree
Hide file tree
Showing 20 changed files with 631 additions and 265 deletions.
77 changes: 37 additions & 40 deletions ChuanhuChatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def create_new_model():
with gr.Row(elem_id="chuanhu-header"):
gr.HTML(get_html("header_title.html").format(
app_title=CHUANHU_TITLE), elem_id="app-title")
status_display = gr.Markdown(get_geoip(), elem_id="status-display")
status_display = gr.Markdown(get_geoip, elem_id="status-display")
with gr.Row(elem_id="float-display"):
user_info = gr.Markdown(
value="getting user info...", elem_id="user-info")
Expand Down Expand Up @@ -329,7 +329,7 @@ def create_new_model():
user_identifier_txt = gr.Textbox(
show_label=True,
placeholder=i18n("用于定位滥用行为"),
label=i18n("用户名"),
label=i18n("用户标识符"),
value=user_name.value,
lines=1,
)
Expand Down Expand Up @@ -496,17 +496,14 @@ def create_greeting(request: gr.Request):
user_info, user_name = gr.Markdown.update(
value=f"", visible=False), ""
current_model = get_model(
model_name=MODELS[DEFAULT_MODEL], access_key=my_api_key)[0]
current_model.set_user_identifier(user_name)
model_name=MODELS[DEFAULT_MODEL], access_key=my_api_key, user_name=user_name)[0]
if not hide_history_when_not_logged_in or user_name:
filename, system_prompt, chatbot = current_model.auto_load()
loaded_stuff = 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)
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, historySelectList], api_name="load")
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=[
Expand Down Expand Up @@ -549,8 +546,8 @@ def create_greeting(request: gr.Request):

load_history_from_file_args = dict(
fn=load_chat_history,
inputs=[current_model, historySelectList, user_name],
outputs=[saveFileName, systemPromptTxt, chatbot]
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(
Expand All @@ -559,7 +556,7 @@ def create_greeting(request: gr.Request):

auto_name_chat_history_args = dict(
fn=auto_name_chat_history,
inputs=[current_model, name_chat_method, user_question, chatbot, user_name, single_turn_checkbox],
inputs=[current_model, name_chat_method, user_question, chatbot, single_turn_checkbox],
outputs=[historySelectList],
show_progress=False,
)
Expand Down Expand Up @@ -587,7 +584,7 @@ def create_greeting(request: gr.Request):
emptyBtn.click(
reset,
inputs=[current_model, retain_system_prompt_checkbox],
outputs=[chatbot, status_display, historySelectList, systemPromptTxt],
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);}',
)
Expand Down Expand Up @@ -641,7 +638,7 @@ def create_greeting(request: gr.Request):
user_api_key, status_display], api_name="set_key").then(**get_usage_args)
keyTxt.submit(**get_usage_args)
single_turn_checkbox.change(
set_single_turn, [current_model, single_turn_checkbox], None)
set_single_turn, [current_model, single_turn_checkbox], None, show_progress=False)
model_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, top_p_slider, systemPromptTxt, user_name, current_model], [
current_model, status_display, chatbot, lora_select_dropdown, user_api_key, keyTxt], show_progress=True, api_name="get_model")
model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [
Expand All @@ -652,7 +649,7 @@ def create_greeting(request: gr.Request):
top_p_slider, systemPromptTxt, user_name, current_model], [current_model, status_display, chatbot], show_progress=True)

# Template
systemPromptTxt.change(set_system_prompt, [
systemPromptTxt.input(set_system_prompt, [
current_model, systemPromptTxt], None)
templateRefreshBtn.click(get_template_dropdown, None, [
templateFileSelectDropdown])
Expand All @@ -679,21 +676,21 @@ def create_greeting(request: gr.Request):
)
exportMarkdownBtn.click(
export_markdown,
[current_model, saveFileName, chatbot, user_name],
[current_model, saveFileName, chatbot],
[],
show_progress=True,
)
historyRefreshBtn.click(**refresh_history_args)
historyDeleteBtn.click(delete_chat_history, [current_model, historySelectList, user_name], [status_display, historySelectList, chatbot], _js='(a,b,c)=>{return showConfirmationDialog(a, b, c);}').then(
historyDeleteBtn.click(delete_chat_history, [current_model, historySelectList], [status_display, historySelectList, chatbot], _js='(a,b,c)=>{return showConfirmationDialog(a, b, c);}').then(
reset,
inputs=[current_model, retain_system_prompt_checkbox],
outputs=[chatbot, status_display, historySelectList, systemPromptTxt],
show_progress=True,
_js='(a,b)=>{return clearChatbot(a,b);}',
)
historySelectList.input(**load_history_from_file_args)
uploadFileBtn.upload(upload_chat_history, [current_model, uploadFileBtn, user_name], [
saveFileName, systemPromptTxt, chatbot]).then(**refresh_history_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, [
Expand Down Expand Up @@ -725,25 +722,25 @@ def create_greeting(request: gr.Request):
cancel_all_jobs, [], [openai_train_status], show_progress=True)

# Advanced
max_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)
temperature_slider.input(
set_temperature, [current_model, temperature_slider], None, show_progress=False)
top_p_slider.input(set_top_p, [current_model, top_p_slider], None, show_progress=False)
n_choices_slider.input(
set_n_choices, [current_model, n_choices_slider], None, show_progress=False)
stop_sequence_txt.input(
set_stop_sequence, [current_model, stop_sequence_txt], None, show_progress=False)
max_context_length_slider.input(
set_token_upper_limit, [current_model, max_context_length_slider], None, show_progress=False)
max_generation_slider.input(
set_max_tokens, [current_model, max_generation_slider], None, show_progress=False)
presence_penalty_slider.input(
set_presence_penalty, [current_model, presence_penalty_slider], None, show_progress=False)
frequency_penalty_slider.input(
set_frequency_penalty, [current_model, frequency_penalty_slider], None, show_progress=False)
logit_bias_txt.input(
set_logit_bias, [current_model, logit_bias_txt], None, show_progress=False)
user_identifier_txt.input(set_user_identifier, [
current_model, user_identifier_txt], None, show_progress=False)

default_btn.click(
reset_default, [], [apihostTxt, proxyTxt, status_display], show_progress=True
Expand Down Expand Up @@ -784,7 +781,7 @@ def create_greeting(request: gr.Request):
historySelectBtn.click( # This is an experimental feature... Not actually used.
fn=load_chat_history,
inputs=[current_model, historySelectList],
outputs=[saveFileName, systemPromptTxt, chatbot],
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);}'
)

Expand Down
1 change: 1 addition & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
//== 高级配置 ==
// 是否多个API Key轮换使用
"multi_api_key": false,
"hide_my_key": false, // 如果你想在UI中隐藏 API 密钥输入框,将此值设置为 true
// "available_models": ["GPT3.5 Turbo", "GPT4 Turbo", "GPT4 Vision"], // 可用的模型列表,将覆盖默认的可用模型列表
// "extra_models": ["模型名称3", "模型名称4", ...], // 额外的模型,将添加到可用的模型列表之后
// "api_key_list": [
Expand Down
5 changes: 3 additions & 2 deletions locale/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"状态": "Status",
"生成内容总结中……": "Generating content summary...",
"用于定位滥用行为": "Used to locate abuse",
"用户名": "Username",
"用户标识符": "User identifier",
"由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536)、[明昭MZhao](https://space.bilibili.com/24807452) 和 [Keldos](https://github.com/Keldos-Li) 开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本": "Developed by Bilibili [土川虎虎虎](https://space.bilibili.com/29125536), [明昭MZhao](https://space.bilibili.com/24807452) and [Keldos](https://github.com/Keldos-Li)\n\nDownload latest code from [GitHub](https://github.com/GaiZhenbiao/ChuanhuChatGPT)",
"知识库": "Knowledge base",
"知识库文件": "Knowledge base files",
Expand Down Expand Up @@ -137,5 +137,6 @@
"🔙 恢复默认网络设置": "🔙 Reset Network Settings",
"🗑️ 删除最新对话": "🗑️ Delete latest dialog",
"🗑️ 删除最旧对话": "🗑️ Delete oldest dialog",
"🧹 新的对话": "🧹 New Dialogue"
"🧹 新的对话": "🧹 New Dialogue",
"正在获取IP地址信息,请稍候...": "Getting IP address information, please wait...",
}
5 changes: 3 additions & 2 deletions locale/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"状态": "ステータス",
"生成内容总结中……": "コンテンツ概要を生成しています...",
"用于定位滥用行为": "不正行為を特定するために使用されます",
"用户名": "ユーザー名",
"用户标识符": "ユーザー識別子",
"由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536)、[明昭MZhao](https://space.bilibili.com/24807452) 和 [Keldos](https://github.com/Keldos-Li) 开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本": "開発:Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) と [明昭MZhao](https://space.bilibili.com/24807452) と [Keldos](https://github.com/Keldos-Li)\n\n最新コードは川虎Chatのサイトへ [GitHubプロジェクト](https://github.com/GaiZhenbiao/ChuanhuChatGPT)",
"知识库": "ナレッジベース",
"知识库文件": "ナレッジベースファイル",
Expand Down Expand Up @@ -137,5 +137,6 @@
"🔙 恢复默认网络设置": "🔙 ネットワーク設定のリセット",
"🗑️ 删除最新对话": "🗑️ 最新の会話削除",
"🗑️ 删除最旧对话": "🗑️ 最古の会話削除",
"🧹 新的对话": "🧹 新しい会話"
"🧹 新的对话": "🧹 新しい会話",
"正在获取IP地址信息,请稍候...": "IPアドレス情報を取得しています、しばらくお待ちください...",
}
5 changes: 3 additions & 2 deletions locale/ko_KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"状态": "상태",
"生成内容总结中……": "콘텐츠 요약 생성중...",
"用于定位滥用行为": "악용 사례 파악에 활용됨",
"用户名": "사용자 이름",
"用户标识符": "사용자 식별자",
"由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536)、[明昭MZhao](https://space.bilibili.com/24807452) 和 [Keldos](https://github.com/Keldos-Li) 开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本": "제작: Bilibili [土川虎虎虎](https://space.bilibili.com/29125536), [明昭MZhao](https://space.bilibili.com/24807452), [Keldos](https://github.com/Keldos-Li)\n\n최신 코드 다운로드: [GitHub](https://github.com/GaiZhenbiao/ChuanhuChatGPT)",
"知识库": "지식 라이브러리",
"知识库文件": "지식 라이브러리 파일",
Expand Down Expand Up @@ -137,5 +137,6 @@
"🔙 恢复默认网络设置": "🔙 네트워크 설정 초기화",
"🗑️ 删除最新对话": "🗑️ 최신 대화 삭제",
"🗑️ 删除最旧对话": "🗑️ 가장 오래된 대화 삭제",
"🧹 新的对话": "🧹 새로운 대화"
"🧹 新的对话": "🧹 새로운 대화",
"正在获取IP地址信息,请稍候...": "IP 주소 정보를 가져오는 중입니다. 잠시만 기다려주세요...",
}
5 changes: 3 additions & 2 deletions locale/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"状态": "Статус",
"生成内容总结中……": "Создание сводки контента...",
"用于定位滥用行为": "Используется для выявления злоупотреблений",
"用户名": "Имя пользователя",
"用户标识符": "Идентификатор пользователя",
"由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536)、[明昭MZhao](https://space.bilibili.com/24807452) 和 [Keldos](https://github.com/Keldos-Li) 开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本": "Разработано [土川虎虎虎](https://space.bilibili.com/29125536), [明昭MZhao](https://space.bilibili.com/24807452) и [Keldos](https://github.com/Keldos-Li).<br />посетите [GitHub Project](https://github.com/GaiZhenbiao/ChuanhuChatGPT) чата Chuanhu, чтобы загрузить последнюю версию скрипта",
"知识库": "База знаний",
"知识库文件": "Файл базы знаний",
Expand Down Expand Up @@ -137,5 +137,6 @@
"🔙 恢复默认网络设置": "🔙 Восстановить настройки сети по умолчанию",
"🗑️ 删除最新对话": "🗑️ Удалить последний диалог",
"🗑️ 删除最旧对话": "🗑️ Удалить старейший диалог",
"🧹 新的对话": "🧹 Новый диалог"
"🧹 新的对话": "🧹 Новый диалог",
"正在获取IP地址信息,请稍候...": "Получение информации об IP-адресе, пожалуйста, подождите...",
}
5 changes: 3 additions & 2 deletions locale/sv_SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"状态": "Status",
"生成内容总结中……": "Genererar innehållssammanfattning...",
"用于定位滥用行为": "Används för att lokalisera missbruk",
"用户名": "Användarnamn",
"用户标识符": "Användar-ID",
"由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536)、[明昭MZhao](https://space.bilibili.com/24807452) 和 [Keldos](https://github.com/Keldos-Li) 开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本": "Utvecklad av Bilibili [土川虎虎虎](https://space.bilibili.com/29125536), [明昭MZhao](https://space.bilibili.com/24807452) och [Keldos](https://github.com/Keldos-Li)\n\nLadda ner senaste koden från [GitHub](https://github.com/GaiZhenbiao/ChuanhuChatGPT)",
"知识库": "kunskapsbank",
"知识库文件": "kunskapsbankfil",
Expand Down Expand Up @@ -137,5 +137,6 @@
"🔙 恢复默认网络设置": "🔙 Återställ standardnätverksinställningar+",
"🗑️ 删除最新对话": "🗑️ Ta bort senaste dialogen",
"🗑️ 删除最旧对话": "🗑️ Ta bort äldsta dialogen",
"🧹 新的对话": "🧹 Ny Dialog"
"🧹 新的对话": "🧹 Ny Dialog",
"正在获取IP地址信息,请稍候...": "Hämtar IP-adressinformation, vänta...",
}
Loading

0 comments on commit 400a0b5

Please sign in to comment.