JohnSmith9982 commited on
Commit
8ba98ee
·
1 Parent(s): a97e5c1

Upload 38 files

Browse files
CITATION.cff ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cff-version: 1.2.0
2
+ title: ChuanhuChatGPT
3
+ message: >-
4
+ If you use this software, please cite it using these
5
+ metadata.
6
+ type: software
7
+ authors:
8
+ - given-names: Chuanhu
9
+ orcid: https://orcid.org/0000-0001-8954-8598
10
+ - given-names: MZhao
11
+ orcid: https://orcid.org/0000-0003-2298-6213
12
+ - given-names: Keldos
13
+ orcid: https://orcid.org/0009-0005-0357-272X
14
+ repository-code: 'https://github.com/GaiZhenbiao/ChuanhuChatGPT'
15
+ url: 'https://github.com/GaiZhenbiao/ChuanhuChatGPT'
16
+ abstract: Provided a light and easy to use interface for ChatGPT API
17
+ license: GPL-3.0
18
+ commit: bd0034c37e5af6a90bd9c2f7dd073f6cd27c61af
19
+ version: '20230405'
20
+ date-released: '2023-04-05'
ChuanhuChatbot.py CHANGED
@@ -10,31 +10,33 @@ from modules.config import *
10
  from modules.utils import *
11
  from modules.presets import *
12
  from modules.overwrites import *
13
- from modules.chat_func import *
14
- from modules.openai_func import get_usage
15
 
 
 
16
  gr.Chatbot.postprocess = postprocess
17
  PromptHelper.compact_text_chunks = compact_text_chunks
18
 
19
  with open("assets/custom.css", "r", encoding="utf-8") as f:
20
  customCSS = f.read()
21
 
 
 
 
22
  with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
23
  user_name = gr.State("")
24
- history = gr.State([])
25
- token_count = gr.State([])
26
  promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
27
- user_api_key = gr.State(my_api_key)
28
  user_question = gr.State("")
29
- outputing = gr.State(False)
30
- topic = gr.State("未命名对话历史记录")
 
 
31
 
32
  with gr.Row():
33
- with gr.Column():
34
- gr.HTML(title)
35
- user_info = gr.Markdown(value="", elem_id="user_info")
36
- gr.HTML('<center><a href="https://huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a></center>')
37
  status_display = gr.Markdown(get_geoip(), elem_id="status_display")
 
 
38
 
39
  # https://github.com/gradio-app/gradio/pull/3296
40
  def create_greeting(request: gr.Request):
@@ -50,176 +52,235 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
50
  with gr.Row():
51
  chatbot = gr.Chatbot(elem_id="chuanhu_chatbot").style(height="100%")
52
  with gr.Row():
53
- with gr.Column(scale=12):
54
  user_input = gr.Textbox(
55
  elem_id="user_input_tb",
56
- show_label=False, placeholder="在这里输入"
57
  ).style(container=False)
58
- with gr.Column(min_width=70, scale=1):
59
- submitBtn = gr.Button("发送", variant="primary")
60
- cancelBtn = gr.Button("取消", variant="secondary", visible=False)
61
  with gr.Row():
62
  emptyBtn = gr.Button(
63
- "🧹 新的对话",
64
  )
65
- retryBtn = gr.Button("🔄 重新生成")
66
- delFirstBtn = gr.Button("🗑️ 删除最旧对话")
67
- delLastBtn = gr.Button("🗑️ 删除最新对话")
68
- reduceTokenBtn = gr.Button("♻️ 总结对话")
69
 
70
  with gr.Column():
71
  with gr.Column(min_width=50, scale=1):
72
- with gr.Tab(label="ChatGPT"):
73
  keyTxt = gr.Textbox(
74
  show_label=True,
75
  placeholder=f"OpenAI API-key...",
76
- value=hide_middle_chars(my_api_key),
77
  type="password",
78
  visible=not HIDE_MY_KEY,
79
  label="API-Key",
80
  )
81
  if multi_api_key:
82
- usageTxt = gr.Markdown("多账号模式已开启,无需输入key,可直接开始对话", elem_id="usage_display")
83
  else:
84
- usageTxt = gr.Markdown("**发送消息** 或 **提交key** 以显示额度", elem_id="usage_display")
85
  model_select_dropdown = gr.Dropdown(
86
- label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0]
87
  )
88
- use_streaming_checkbox = gr.Checkbox(
89
- label="实时传输回答", value=True, visible=enable_streaming_option
90
  )
91
- use_websearch_checkbox = gr.Checkbox(label="使用在线搜索", value=False)
 
 
 
 
 
92
  language_select_dropdown = gr.Dropdown(
93
- label="选择回复语言(针对搜索&索引功能)",
94
  choices=REPLY_LANGUAGES,
95
  multiselect=False,
96
  value=REPLY_LANGUAGES[0],
97
  )
98
- index_files = gr.Files(label="上传索引文件", type="file", multiple=True)
99
- two_column = gr.Checkbox(label="双栏pdf", value=advance_docs["pdf"].get("two_column", False))
100
  # TODO: 公式ocr
101
- # formula_ocr = gr.Checkbox(label="识别公式", value=advance_docs["pdf"].get("formula_ocr", False))
102
 
103
  with gr.Tab(label="Prompt"):
104
  systemPromptTxt = gr.Textbox(
105
  show_label=True,
106
- placeholder=f"在这里输入System Prompt...",
107
  label="System prompt",
108
- value=initial_prompt,
109
  lines=10,
110
  ).style(container=False)
111
- with gr.Accordion(label="加载Prompt模板", open=True):
112
  with gr.Column():
113
  with gr.Row():
114
  with gr.Column(scale=6):
115
  templateFileSelectDropdown = gr.Dropdown(
116
- label="选择Prompt模板集合文件",
117
  choices=get_template_names(plain=True),
118
  multiselect=False,
119
  value=get_template_names(plain=True)[0],
120
  ).style(container=False)
121
  with gr.Column(scale=1):
122
- templateRefreshBtn = gr.Button("🔄 刷新")
123
  with gr.Row():
124
  with gr.Column():
125
  templateSelectDropdown = gr.Dropdown(
126
- label="从Prompt模板中加载",
127
  choices=load_template(
128
  get_template_names(plain=True)[0], mode=1
129
  ),
130
  multiselect=False,
131
  ).style(container=False)
132
 
133
- with gr.Tab(label="保存/加载"):
134
- with gr.Accordion(label="保存/加载对话历史记录", open=True):
135
  with gr.Column():
136
  with gr.Row():
137
  with gr.Column(scale=6):
138
  historyFileSelectDropdown = gr.Dropdown(
139
- label="从列表中加载对话",
140
  choices=get_history_names(plain=True),
141
  multiselect=False,
142
  value=get_history_names(plain=True)[0],
143
  )
144
  with gr.Column(scale=1):
145
- historyRefreshBtn = gr.Button("🔄 刷新")
146
  with gr.Row():
147
  with gr.Column(scale=6):
148
  saveFileName = gr.Textbox(
149
  show_label=True,
150
- placeholder=f"设置文件名: 默认为.json,可选为.md",
151
- label="设置保存文件名",
152
- value="对话历史记录",
153
  ).style(container=True)
154
  with gr.Column(scale=1):
155
- saveHistoryBtn = gr.Button("💾 保存对话")
156
- exportMarkdownBtn = gr.Button("📝 导出为Markdown")
157
- gr.Markdown("默认保存于history文件夹")
158
  with gr.Row():
159
  with gr.Column():
160
  downloadFile = gr.File(interactive=True)
161
 
162
- with gr.Tab(label="高级"):
163
- gr.Markdown("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置")
164
- default_btn = gr.Button("🔙 恢复默认设置")
165
-
166
- with gr.Accordion("参数", open=False):
167
- top_p = gr.Slider(
 
 
 
 
 
 
 
168
  minimum=-0,
169
  maximum=1.0,
170
  value=1.0,
171
  step=0.05,
172
  interactive=True,
173
- label="Top-p",
174
  )
175
- temperature = gr.Slider(
176
- minimum=-0,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  maximum=2.0,
178
- value=1.0,
179
- step=0.1,
 
 
 
 
 
 
 
 
180
  interactive=True,
181
- label="Temperature",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  )
183
 
184
- with gr.Accordion("网络设置", open=False, visible=False):
185
  # 优先展示自定义的api_host
186
  apihostTxt = gr.Textbox(
187
  show_label=True,
188
- placeholder=f"在这里输入API-Host...",
189
  label="API-Host",
190
  value=config.api_host or shared.API_HOST,
191
  lines=1,
192
  )
193
- changeAPIURLBtn = gr.Button("🔄 切换API地址")
194
  proxyTxt = gr.Textbox(
195
  show_label=True,
196
- placeholder=f"在这里输入代理地址...",
197
- label="代理地址(示例:http://127.0.0.1:10809)",
198
  value="",
199
  lines=2,
200
  )
201
- changeProxyBtn = gr.Button("🔄 设置代理地址")
 
202
 
203
- gr.Markdown(description)
204
- gr.HTML(footer.format(versions=versions_html()), elem_id="footer")
205
  chatgpt_predict_args = dict(
206
  fn=predict,
207
  inputs=[
208
- user_api_key,
209
- systemPromptTxt,
210
- history,
211
  user_question,
212
  chatbot,
213
- token_count,
214
- top_p,
215
- temperature,
216
  use_streaming_checkbox,
217
- model_select_dropdown,
218
  use_websearch_checkbox,
219
  index_files,
220
  language_select_dropdown,
221
  ],
222
- outputs=[chatbot, history, status_display, token_count],
223
  show_progress=True,
224
  )
225
 
@@ -243,12 +304,18 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
243
  )
244
 
245
  get_usage_args = dict(
246
- fn=get_usage, inputs=[user_api_key], outputs=[usageTxt], show_progress=False
 
 
 
 
 
 
247
  )
248
 
249
 
250
  # Chatbot
251
- cancelBtn.click(cancel_outputing, [], [])
252
 
253
  user_input.submit(**transfer_input_args).then(**chatgpt_predict_args).then(**end_outputing_args)
254
  user_input.submit(**get_usage_args)
@@ -256,9 +323,12 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
256
  submitBtn.click(**transfer_input_args).then(**chatgpt_predict_args).then(**end_outputing_args)
257
  submitBtn.click(**get_usage_args)
258
 
 
 
259
  emptyBtn.click(
260
- reset_state,
261
- outputs=[chatbot, history, token_count, status_display],
 
262
  show_progress=True,
263
  )
264
  emptyBtn.click(**reset_textbox_args)
@@ -266,61 +336,42 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
266
  retryBtn.click(**start_outputing_args).then(
267
  retry,
268
  [
269
- user_api_key,
270
- systemPromptTxt,
271
- history,
272
  chatbot,
273
- token_count,
274
- top_p,
275
- temperature,
276
  use_streaming_checkbox,
277
- model_select_dropdown,
 
278
  language_select_dropdown,
279
  ],
280
- [chatbot, history, status_display, token_count],
281
  show_progress=True,
282
  ).then(**end_outputing_args)
283
  retryBtn.click(**get_usage_args)
284
 
285
  delFirstBtn.click(
286
  delete_first_conversation,
287
- [history, token_count],
288
- [history, token_count, status_display],
289
  )
290
 
291
  delLastBtn.click(
292
  delete_last_conversation,
293
- [chatbot, history, token_count],
294
- [chatbot, history, token_count, status_display],
295
- show_progress=True,
296
- )
297
-
298
- reduceTokenBtn.click(
299
- reduce_token_size,
300
- [
301
- user_api_key,
302
- systemPromptTxt,
303
- history,
304
- chatbot,
305
- token_count,
306
- top_p,
307
- temperature,
308
- gr.State(sum(token_count.value[-4:])),
309
- model_select_dropdown,
310
- language_select_dropdown,
311
- ],
312
- [chatbot, history, status_display, token_count],
313
- show_progress=True,
314
  )
315
- reduceTokenBtn.click(**get_usage_args)
316
 
317
  two_column.change(update_doc_config, [two_column], None)
318
 
319
- # ChatGPT
320
- keyTxt.change(submit_key, keyTxt, [user_api_key, status_display]).then(**get_usage_args)
321
  keyTxt.submit(**get_usage_args)
 
 
 
322
 
323
  # Template
 
324
  templateRefreshBtn.click(get_template_names, None, [templateFileSelectDropdown])
325
  templateFileSelectDropdown.change(
326
  load_template,
@@ -338,31 +389,33 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
338
  # S&L
339
  saveHistoryBtn.click(
340
  save_chat_history,
341
- [saveFileName, systemPromptTxt, history, chatbot, user_name],
342
  downloadFile,
343
  show_progress=True,
344
  )
345
  saveHistoryBtn.click(get_history_names, [gr.State(False), user_name], [historyFileSelectDropdown])
346
  exportMarkdownBtn.click(
347
  export_markdown,
348
- [saveFileName, systemPromptTxt, history, chatbot, user_name],
349
  downloadFile,
350
  show_progress=True,
351
  )
352
  historyRefreshBtn.click(get_history_names, [gr.State(False), user_name], [historyFileSelectDropdown])
353
- historyFileSelectDropdown.change(
354
- load_chat_history,
355
- [historyFileSelectDropdown, systemPromptTxt, history, chatbot, user_name],
356
- [saveFileName, systemPromptTxt, history, chatbot],
357
- show_progress=True,
358
- )
359
- downloadFile.change(
360
- load_chat_history,
361
- [downloadFile, systemPromptTxt, history, chatbot, user_name],
362
- [saveFileName, systemPromptTxt, history, chatbot],
363
- )
364
 
365
  # Advanced
 
 
 
 
 
 
 
 
 
 
 
366
  default_btn.click(
367
  reset_default, [], [apihostTxt, proxyTxt, status_display], show_progress=True
368
  )
@@ -385,39 +438,15 @@ logging.info(
385
  + colorama.Style.RESET_ALL
386
  )
387
  # 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
388
- demo.title = "川虎ChatGPT 🚀"
389
 
390
  if __name__ == "__main__":
391
  reload_javascript()
392
- # if running in Docker
393
- if dockerflag:
394
- if authflag:
395
- demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
396
- server_name="0.0.0.0",
397
- server_port=7860,
398
- auth=auth_list,
399
- favicon_path="./assets/favicon.ico",
400
- )
401
- else:
402
- demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
403
- server_name="0.0.0.0",
404
- server_port=7860,
405
- share=False,
406
- favicon_path="./assets/favicon.ico",
407
- )
408
- # if not running in Docker
409
- else:
410
- if authflag:
411
- demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
412
- share=False,
413
- auth=auth_list,
414
- favicon_path="./assets/favicon.ico",
415
- inbrowser=True,
416
- )
417
- else:
418
- demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
419
- share=False, favicon_path="./assets/favicon.ico", inbrowser=True
420
- ) # 改为 share=True 可以创建公开分享链接
421
- # demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口
422
- # demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860,auth=("在这里填写用户名", "在这里填写密码")) # 可设置用户名与密码
423
- # demo.queue(concurrency_count=CONCURRENT_COUNT).launch(auth=("在这里填写用户名", "在这里填写密码")) # 适合Nginx反向代理
 
10
  from modules.utils import *
11
  from modules.presets import *
12
  from modules.overwrites import *
13
+ from modules.models import get_model
 
14
 
15
+
16
+ gr.Chatbot._postprocess_chat_messages = postprocess_chat_messages
17
  gr.Chatbot.postprocess = postprocess
18
  PromptHelper.compact_text_chunks = compact_text_chunks
19
 
20
  with open("assets/custom.css", "r", encoding="utf-8") as f:
21
  customCSS = f.read()
22
 
23
+ def create_new_model():
24
+ return get_model(model_name = MODELS[DEFAULT_MODEL], access_key = my_api_key)[0]
25
+
26
  with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
27
  user_name = gr.State("")
 
 
28
  promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
 
29
  user_question = gr.State("")
30
+ user_api_key = gr.State(my_api_key)
31
+ current_model = gr.State(create_new_model)
32
+
33
+ topic = gr.State(i18n("未命名对话历史记录"))
34
 
35
  with gr.Row():
36
+ gr.HTML(CHUANHU_TITLE, elem_id="app_title")
 
 
 
37
  status_display = gr.Markdown(get_geoip(), elem_id="status_display")
38
+ with gr.Row(elem_id="float_display"):
39
+ user_info = gr.Markdown(value="getting user info...", elem_id="user_info")
40
 
41
  # https://github.com/gradio-app/gradio/pull/3296
42
  def create_greeting(request: gr.Request):
 
52
  with gr.Row():
53
  chatbot = gr.Chatbot(elem_id="chuanhu_chatbot").style(height="100%")
54
  with gr.Row():
55
+ with gr.Column(min_width=225, scale=12):
56
  user_input = gr.Textbox(
57
  elem_id="user_input_tb",
58
+ show_label=False, placeholder=i18n("在这里输入")
59
  ).style(container=False)
60
+ with gr.Column(min_width=42, scale=1):
61
+ submitBtn = gr.Button(value="", variant="primary", elem_id="submit_btn")
62
+ cancelBtn = gr.Button(value="", variant="secondary", visible=False, elem_id="cancel_btn")
63
  with gr.Row():
64
  emptyBtn = gr.Button(
65
+ i18n("🧹 新的对话"),
66
  )
67
+ retryBtn = gr.Button(i18n("🔄 重新生成"))
68
+ delFirstBtn = gr.Button(i18n("🗑️ 删除最旧对话"))
69
+ delLastBtn = gr.Button(i18n("🗑️ 删除最新对话"))
 
70
 
71
  with gr.Column():
72
  with gr.Column(min_width=50, scale=1):
73
+ with gr.Tab(label=i18n("模型")):
74
  keyTxt = gr.Textbox(
75
  show_label=True,
76
  placeholder=f"OpenAI API-key...",
77
+ value=hide_middle_chars(user_api_key.value),
78
  type="password",
79
  visible=not HIDE_MY_KEY,
80
  label="API-Key",
81
  )
82
  if multi_api_key:
83
+ usageTxt = gr.Markdown(i18n("多账号模式已开启,无需输入key,可直接开始对话"), elem_id="usage_display", elem_classes="insert_block")
84
  else:
85
+ usageTxt = gr.Markdown(i18n("**发送消息** 或 **提交key** 以显示额度"), elem_id="usage_display", elem_classes="insert_block")
86
  model_select_dropdown = gr.Dropdown(
87
+ label=i18n("选择模型"), choices=MODELS, multiselect=False, value=MODELS[DEFAULT_MODEL], interactive=True
88
  )
89
+ lora_select_dropdown = gr.Dropdown(
90
+ label=i18n("选择LoRA模型"), choices=[], multiselect=False, interactive=True, visible=False
91
  )
92
+ with gr.Row():
93
+ use_streaming_checkbox = gr.Checkbox(
94
+ label=i18n("实时传输回答"), value=True, visible=ENABLE_STREAMING_OPTION
95
+ )
96
+ single_turn_checkbox = gr.Checkbox(label=i18n("单轮对话"), value=False)
97
+ use_websearch_checkbox = gr.Checkbox(label=i18n("使用在线搜索"), value=False)
98
  language_select_dropdown = gr.Dropdown(
99
+ label=i18n("选择回复语言(针对搜索&索引功能)"),
100
  choices=REPLY_LANGUAGES,
101
  multiselect=False,
102
  value=REPLY_LANGUAGES[0],
103
  )
104
+ index_files = gr.Files(label=i18n("上传索引文件"), type="file")
105
+ two_column = gr.Checkbox(label=i18n("双栏pdf"), value=advance_docs["pdf"].get("two_column", False))
106
  # TODO: 公式ocr
107
+ # formula_ocr = gr.Checkbox(label=i18n("识别公式"), value=advance_docs["pdf"].get("formula_ocr", False))
108
 
109
  with gr.Tab(label="Prompt"):
110
  systemPromptTxt = gr.Textbox(
111
  show_label=True,
112
+ placeholder=i18n("在这里输入System Prompt..."),
113
  label="System prompt",
114
+ value=INITIAL_SYSTEM_PROMPT,
115
  lines=10,
116
  ).style(container=False)
117
+ with gr.Accordion(label=i18n("加载Prompt模板"), open=True):
118
  with gr.Column():
119
  with gr.Row():
120
  with gr.Column(scale=6):
121
  templateFileSelectDropdown = gr.Dropdown(
122
+ label=i18n("选择Prompt模板集合文件"),
123
  choices=get_template_names(plain=True),
124
  multiselect=False,
125
  value=get_template_names(plain=True)[0],
126
  ).style(container=False)
127
  with gr.Column(scale=1):
128
+ templateRefreshBtn = gr.Button(i18n("🔄 刷新"))
129
  with gr.Row():
130
  with gr.Column():
131
  templateSelectDropdown = gr.Dropdown(
132
+ label=i18n("从Prompt模板中加载"),
133
  choices=load_template(
134
  get_template_names(plain=True)[0], mode=1
135
  ),
136
  multiselect=False,
137
  ).style(container=False)
138
 
139
+ with gr.Tab(label=i18n("保存/加载")):
140
+ with gr.Accordion(label=i18n("保存/加载对话历史记录"), open=True):
141
  with gr.Column():
142
  with gr.Row():
143
  with gr.Column(scale=6):
144
  historyFileSelectDropdown = gr.Dropdown(
145
+ label=i18n("从列表中加载对话"),
146
  choices=get_history_names(plain=True),
147
  multiselect=False,
148
  value=get_history_names(plain=True)[0],
149
  )
150
  with gr.Column(scale=1):
151
+ historyRefreshBtn = gr.Button(i18n("🔄 刷新"))
152
  with gr.Row():
153
  with gr.Column(scale=6):
154
  saveFileName = gr.Textbox(
155
  show_label=True,
156
+ placeholder=i18n("设置文件名: 默认为.json,可选为.md"),
157
+ label=i18n("设置保存文件名"),
158
+ value=i18n("对话历史记录"),
159
  ).style(container=True)
160
  with gr.Column(scale=1):
161
+ saveHistoryBtn = gr.Button(i18n("💾 保存对话"))
162
+ exportMarkdownBtn = gr.Button(i18n("📝 导出为Markdown"))
163
+ gr.Markdown(i18n("默认保存于history文件夹"))
164
  with gr.Row():
165
  with gr.Column():
166
  downloadFile = gr.File(interactive=True)
167
 
168
+ with gr.Tab(label=i18n("高级")):
169
+ gr.Markdown(i18n("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置"))
170
+ gr.HTML(APPEARANCE_SWITCHER, elem_classes="insert_block")
171
+ with gr.Accordion(i18n("参数"), open=False):
172
+ temperature_slider = gr.Slider(
173
+ minimum=-0,
174
+ maximum=2.0,
175
+ value=1.0,
176
+ step=0.1,
177
+ interactive=True,
178
+ label="temperature",
179
+ )
180
+ top_p_slider = gr.Slider(
181
  minimum=-0,
182
  maximum=1.0,
183
  value=1.0,
184
  step=0.05,
185
  interactive=True,
186
+ label="top-p",
187
  )
188
+ n_choices_slider = gr.Slider(
189
+ minimum=1,
190
+ maximum=10,
191
+ value=1,
192
+ step=1,
193
+ interactive=True,
194
+ label="n choices",
195
+ )
196
+ stop_sequence_txt = gr.Textbox(
197
+ show_label=True,
198
+ placeholder=i18n("在这里输入停止符,用英文逗号隔开..."),
199
+ label="stop",
200
+ value="",
201
+ lines=1,
202
+ )
203
+ max_context_length_slider = gr.Slider(
204
+ minimum=1,
205
+ maximum=32768,
206
+ value=2000,
207
+ step=1,
208
+ interactive=True,
209
+ label="max context",
210
+ )
211
+ max_generation_slider = gr.Slider(
212
+ minimum=1,
213
+ maximum=32768,
214
+ value=1000,
215
+ step=1,
216
+ interactive=True,
217
+ label="max generations",
218
+ )
219
+ presence_penalty_slider = gr.Slider(
220
+ minimum=-2.0,
221
  maximum=2.0,
222
+ value=0.0,
223
+ step=0.01,
224
+ interactive=True,
225
+ label="presence penalty",
226
+ )
227
+ frequency_penalty_slider = gr.Slider(
228
+ minimum=-2.0,
229
+ maximum=2.0,
230
+ value=0.0,
231
+ step=0.01,
232
  interactive=True,
233
+ label="frequency penalty",
234
+ )
235
+ logit_bias_txt = gr.Textbox(
236
+ show_label=True,
237
+ placeholder=f"word:likelihood",
238
+ label="logit bias",
239
+ value="",
240
+ lines=1,
241
+ )
242
+ user_identifier_txt = gr.Textbox(
243
+ show_label=True,
244
+ placeholder=i18n("用于定位滥用行为"),
245
+ label=i18n("用户名"),
246
+ value=user_name.value,
247
+ lines=1,
248
  )
249
 
250
+ with gr.Accordion(i18n("网络设置"), open=False):
251
  # 优先展示自定义的api_host
252
  apihostTxt = gr.Textbox(
253
  show_label=True,
254
+ placeholder=i18n("在这里输入API-Host..."),
255
  label="API-Host",
256
  value=config.api_host or shared.API_HOST,
257
  lines=1,
258
  )
259
+ changeAPIURLBtn = gr.Button(i18n("🔄 切换API地址"))
260
  proxyTxt = gr.Textbox(
261
  show_label=True,
262
+ placeholder=i18n("在这里输入代理地址..."),
263
+ label=i18n("代理地址(示例:http://127.0.0.1:10809)"),
264
  value="",
265
  lines=2,
266
  )
267
+ changeProxyBtn = gr.Button(i18n("🔄 设置代理地址"))
268
+ default_btn = gr.Button(i18n("🔙 恢复默认设置"))
269
 
270
+ gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
271
+ gr.HTML(FOOTER.format(versions=versions_html()), elem_id="footer")
272
  chatgpt_predict_args = dict(
273
  fn=predict,
274
  inputs=[
275
+ current_model,
 
 
276
  user_question,
277
  chatbot,
 
 
 
278
  use_streaming_checkbox,
 
279
  use_websearch_checkbox,
280
  index_files,
281
  language_select_dropdown,
282
  ],
283
+ outputs=[chatbot, status_display],
284
  show_progress=True,
285
  )
286
 
 
304
  )
305
 
306
  get_usage_args = dict(
307
+ fn=billing_info, inputs=[current_model], outputs=[usageTxt], show_progress=False
308
+ )
309
+
310
+ load_history_from_file_args = dict(
311
+ fn=load_chat_history,
312
+ inputs=[current_model, historyFileSelectDropdown, chatbot, user_name],
313
+ outputs=[saveFileName, systemPromptTxt, chatbot]
314
  )
315
 
316
 
317
  # Chatbot
318
+ cancelBtn.click(interrupt, [current_model], [])
319
 
320
  user_input.submit(**transfer_input_args).then(**chatgpt_predict_args).then(**end_outputing_args)
321
  user_input.submit(**get_usage_args)
 
323
  submitBtn.click(**transfer_input_args).then(**chatgpt_predict_args).then(**end_outputing_args)
324
  submitBtn.click(**get_usage_args)
325
 
326
+ index_files.change(handle_file_upload, [current_model, index_files, chatbot], [index_files, chatbot, status_display])
327
+
328
  emptyBtn.click(
329
+ reset,
330
+ inputs=[current_model],
331
+ outputs=[chatbot, status_display],
332
  show_progress=True,
333
  )
334
  emptyBtn.click(**reset_textbox_args)
 
336
  retryBtn.click(**start_outputing_args).then(
337
  retry,
338
  [
339
+ current_model,
 
 
340
  chatbot,
 
 
 
341
  use_streaming_checkbox,
342
+ use_websearch_checkbox,
343
+ index_files,
344
  language_select_dropdown,
345
  ],
346
+ [chatbot, status_display],
347
  show_progress=True,
348
  ).then(**end_outputing_args)
349
  retryBtn.click(**get_usage_args)
350
 
351
  delFirstBtn.click(
352
  delete_first_conversation,
353
+ [current_model],
354
+ [status_display],
355
  )
356
 
357
  delLastBtn.click(
358
  delete_last_conversation,
359
+ [current_model, chatbot],
360
+ [chatbot, status_display],
361
+ show_progress=False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  )
 
363
 
364
  two_column.change(update_doc_config, [two_column], None)
365
 
366
+ # LLM Models
367
+ keyTxt.change(set_key, [current_model, keyTxt], [user_api_key, status_display]).then(**get_usage_args)
368
  keyTxt.submit(**get_usage_args)
369
+ single_turn_checkbox.change(set_single_turn, [current_model, single_turn_checkbox], None)
370
+ 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)
371
+ 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)
372
 
373
  # Template
374
+ systemPromptTxt.change(set_system_prompt, [current_model, systemPromptTxt], None)
375
  templateRefreshBtn.click(get_template_names, None, [templateFileSelectDropdown])
376
  templateFileSelectDropdown.change(
377
  load_template,
 
389
  # S&L
390
  saveHistoryBtn.click(
391
  save_chat_history,
392
+ [current_model, saveFileName, chatbot, user_name],
393
  downloadFile,
394
  show_progress=True,
395
  )
396
  saveHistoryBtn.click(get_history_names, [gr.State(False), user_name], [historyFileSelectDropdown])
397
  exportMarkdownBtn.click(
398
  export_markdown,
399
+ [current_model, saveFileName, chatbot, user_name],
400
  downloadFile,
401
  show_progress=True,
402
  )
403
  historyRefreshBtn.click(get_history_names, [gr.State(False), user_name], [historyFileSelectDropdown])
404
+ historyFileSelectDropdown.change(**load_history_from_file_args)
405
+ downloadFile.change(**load_history_from_file_args)
 
 
 
 
 
 
 
 
 
406
 
407
  # Advanced
408
+ max_context_length_slider.change(set_token_upper_limit, [current_model, max_context_length_slider], None)
409
+ temperature_slider.change(set_temperature, [current_model, temperature_slider], None)
410
+ top_p_slider.change(set_top_p, [current_model, top_p_slider], None)
411
+ n_choices_slider.change(set_n_choices, [current_model, n_choices_slider], None)
412
+ stop_sequence_txt.change(set_stop_sequence, [current_model, stop_sequence_txt], None)
413
+ max_generation_slider.change(set_max_tokens, [current_model, max_generation_slider], None)
414
+ presence_penalty_slider.change(set_presence_penalty, [current_model, presence_penalty_slider], None)
415
+ frequency_penalty_slider.change(set_frequency_penalty, [current_model, frequency_penalty_slider], None)
416
+ logit_bias_txt.change(set_logit_bias, [current_model, logit_bias_txt], None)
417
+ user_identifier_txt.change(set_user_identifier, [current_model, user_identifier_txt], None)
418
+
419
  default_btn.click(
420
  reset_default, [], [apihostTxt, proxyTxt, status_display], show_progress=True
421
  )
 
438
  + colorama.Style.RESET_ALL
439
  )
440
  # 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
441
+ demo.title = i18n("川虎Chat 🚀")
442
 
443
  if __name__ == "__main__":
444
  reload_javascript()
445
+ demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
446
+ auth=auth_list if authflag else None,
447
+ favicon_path="./assets/favicon.ico",
448
+ inbrowser=not dockerflag, # 禁止在docker下开启inbrowser
449
+ )
450
+ # demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口
451
+ # demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860,auth=("在这里填写用户名", "在这里填写密码")) # 可设置用户名与密码
452
+ # demo.queue(concurrency_count=CONCURRENT_COUNT).launch(auth=("在这里填写用户名", "在这里填写密码")) # 适合Nginx反向代理
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Dockerfile CHANGED
@@ -1,7 +1,9 @@
1
  FROM python:3.9 as builder
2
  RUN apt-get update && apt-get install -y build-essential
3
  COPY requirements.txt .
 
4
  RUN pip install --user -r requirements.txt
 
5
 
6
  FROM python:3.9
7
  MAINTAINER iskoldt
@@ -9,6 +11,5 @@ COPY --from=builder /root/.local /root/.local
9
  ENV PATH=/root/.local/bin:$PATH
10
  COPY . /app
11
  WORKDIR /app
12
- ENV my_api_key empty
13
  ENV dockerrun yes
14
  CMD ["python3", "-u", "ChuanhuChatbot.py", "2>&1", "|", "tee", "/var/log/application.log"]
 
1
  FROM python:3.9 as builder
2
  RUN apt-get update && apt-get install -y build-essential
3
  COPY requirements.txt .
4
+ COPY requirements_advanced.txt .
5
  RUN pip install --user -r requirements.txt
6
+ # RUN pip install --user -r requirements_advanced.txt
7
 
8
  FROM python:3.9
9
  MAINTAINER iskoldt
 
11
  ENV PATH=/root/.local/bin:$PATH
12
  COPY . /app
13
  WORKDIR /app
 
14
  ENV dockerrun yes
15
  CMD ["python3", "-u", "ChuanhuChatbot.py", "2>&1", "|", "tee", "/var/log/application.log"]
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🐯
4
  colorFrom: green
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 3.24.1
8
  app_file: ChuanhuChatbot.py
9
  pinned: false
10
  license: gpl-3.0
 
4
  colorFrom: green
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 3.25.0
8
  app_file: ChuanhuChatbot.py
9
  pinned: false
10
  license: gpl-3.0
assets/custom.css CHANGED
@@ -3,14 +3,27 @@
3
  --chatbot-color-dark: #121111;
4
  }
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  /* 覆盖gradio的页脚信息QAQ */
7
- footer {
8
  display: none !important;
9
- }
10
- #footer{
11
  text-align: center;
12
  }
13
- #footer div{
14
  display: inline-block;
15
  }
16
  #footer .versions{
@@ -18,16 +31,34 @@ footer {
18
  opacity: 0.85;
19
  }
20
 
 
 
 
 
21
  /* user_info */
22
  #user_info {
23
  white-space: nowrap;
24
- margin-top: -1.3em !important;
25
- padding-left: 112px !important;
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
  #user_info p {
28
- font-size: .85em;
29
- font-family: monospace;
30
- color: var(--body-text-color-subdued);
 
 
 
31
  }
32
 
33
  /* status_display */
@@ -43,14 +74,18 @@ footer {
43
  color: var(--body-text-color-subdued);
44
  }
45
 
46
- #chuanhu_chatbot, #status_display {
47
  transition: all 0.6s;
48
  }
 
 
 
49
 
50
  /* usage_display */
51
- #usage_display {
52
  position: relative;
53
  margin: 0;
 
54
  box-shadow: var(--block-shadow);
55
  border-width: var(--block-border-width);
56
  border-color: var(--block-border-color);
@@ -62,7 +97,6 @@ footer {
62
  }
63
  #usage_display p, #usage_display span {
64
  margin: 0;
65
- padding: .5em 1em;
66
  font-size: .85em;
67
  color: var(--body-text-color-subdued);
68
  }
@@ -74,7 +108,7 @@ footer {
74
  overflow: hidden;
75
  }
76
  .progress {
77
- background-color: var(--block-title-background-fill);;
78
  height: 100%;
79
  border-radius: 10px;
80
  text-align: right;
@@ -88,38 +122,107 @@ footer {
88
  padding-right: 10px;
89
  line-height: 20px;
90
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  /* list */
92
  ol:not(.options), ul:not(.options) {
93
  padding-inline-start: 2em !important;
94
  }
95
 
96
- /* 亮色 */
97
- @media (prefers-color-scheme: light) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  #chuanhu_chatbot {
99
- background-color: var(--chatbot-color-light) !important;
100
- color: #000000 !important;
101
  }
102
- [data-testid = "bot"] {
103
- background-color: #FFFFFF !important;
104
- }
105
- [data-testid = "user"] {
106
- background-color: #95EC69 !important;
107
  }
108
  }
109
- /* 暗色 */
110
- @media (prefers-color-scheme: dark) {
111
  #chuanhu_chatbot {
112
- background-color: var(--chatbot-color-dark) !important;
113
- color: #FFFFFF !important;
114
  }
115
- [data-testid = "bot"] {
116
- background-color: #2C2C2C !important;
117
  }
118
- [data-testid = "user"] {
119
- background-color: #26B561 !important;
120
  }
121
- body {
122
- background-color: var(--neutral-950) !important;
123
  }
124
  }
125
  /* 对话气泡 */
 
3
  --chatbot-color-dark: #121111;
4
  }
5
 
6
+ #app_title {
7
+ font-weight: var(--prose-header-text-weight);
8
+ font-size: var(--text-xxl);
9
+ line-height: 1.3;
10
+ text-align: left;
11
+ margin-top: 6px;
12
+ white-space: nowrap;
13
+ }
14
+ #description {
15
+ text-align: center;
16
+ margin:16px 0
17
+ }
18
+
19
  /* 覆盖gradio的页脚信息QAQ */
20
+ /* footer {
21
  display: none !important;
22
+ } */
23
+ #footer {
24
  text-align: center;
25
  }
26
+ #footer div {
27
  display: inline-block;
28
  }
29
  #footer .versions{
 
31
  opacity: 0.85;
32
  }
33
 
34
+ #float_display {
35
+ position: absolute;
36
+ max-height: 30px;
37
+ }
38
  /* user_info */
39
  #user_info {
40
  white-space: nowrap;
41
+ position: absolute; left: 8em; top: .2em;
42
+ z-index: var(--layer-2);
43
+ box-shadow: var(--block-shadow);
44
+ border: none; border-radius: var(--block-label-radius);
45
+ background: var(--color-accent);
46
+ padding: var(--block-label-padding);
47
+ font-size: var(--block-label-text-size); line-height: var(--line-sm);
48
+ width: auto; min-height: 30px!important;
49
+ opacity: 1;
50
+ transition: opacity 0.3s ease-in-out;
51
+ }
52
+ #user_info .wrap {
53
+ opacity: 0;
54
  }
55
  #user_info p {
56
+ color: white;
57
+ font-weight: var(--block-label-text-weight);
58
+ }
59
+ #user_info.hideK {
60
+ opacity: 0;
61
+ transition: opacity 1s ease-in-out;
62
  }
63
 
64
  /* status_display */
 
74
  color: var(--body-text-color-subdued);
75
  }
76
 
77
+ #status_display {
78
  transition: all 0.6s;
79
  }
80
+ #chuanhu_chatbot {
81
+ transition: height 0.3s ease;
82
+ }
83
 
84
  /* usage_display */
85
+ .insert_block {
86
  position: relative;
87
  margin: 0;
88
+ padding: .5em 1em;
89
  box-shadow: var(--block-shadow);
90
  border-width: var(--block-border-width);
91
  border-color: var(--block-border-color);
 
97
  }
98
  #usage_display p, #usage_display span {
99
  margin: 0;
 
100
  font-size: .85em;
101
  color: var(--body-text-color-subdued);
102
  }
 
108
  overflow: hidden;
109
  }
110
  .progress {
111
+ background-color: var(--block-title-background-fill);
112
  height: 100%;
113
  border-radius: 10px;
114
  text-align: right;
 
122
  padding-right: 10px;
123
  line-height: 20px;
124
  }
125
+
126
+ .apSwitch {
127
+ top: 2px;
128
+ display: inline-block;
129
+ height: 24px;
130
+ position: relative;
131
+ width: 48px;
132
+ border-radius: 12px;
133
+ }
134
+ .apSwitch input {
135
+ display: none !important;
136
+ }
137
+ .apSlider {
138
+ background-color: var(--block-label-background-fill);
139
+ bottom: 0;
140
+ cursor: pointer;
141
+ left: 0;
142
+ position: absolute;
143
+ right: 0;
144
+ top: 0;
145
+ transition: .4s;
146
+ font-size: 18px;
147
+ border-radius: 12px;
148
+ }
149
+ .apSlider::before {
150
+ bottom: -1.5px;
151
+ left: 1px;
152
+ position: absolute;
153
+ transition: .4s;
154
+ content: "🌞";
155
+ }
156
+ input:checked + .apSlider {
157
+ background-color: var(--block-label-background-fill);
158
+ }
159
+ input:checked + .apSlider::before {
160
+ transform: translateX(23px);
161
+ content:"🌚";
162
+ }
163
+
164
+ #submit_btn, #cancel_btn {
165
+ height: 42px !important;
166
+ }
167
+ #submit_btn::before {
168
+ content: url("data:image/svg+xml, %3Csvg width='21px' height='20px' viewBox='0 0 21 20' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E %3Cg id='page' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E %3Cg id='send' transform='translate(0.435849, 0.088463)' fill='%23FFFFFF' fill-rule='nonzero'%3E %3Cpath d='M0.579148261,0.0428666046 C0.301105539,-0.0961547561 -0.036517765,0.122307382 0.0032026237,0.420210298 L1.4927172,18.1553639 C1.5125774,18.4334066 1.79062012,18.5922882 2.04880264,18.4929872 L8.24518329,15.8913017 L11.6412765,19.7441794 C11.8597387,19.9825018 12.2370824,19.8832008 12.3165231,19.5852979 L13.9450591,13.4882182 L19.7839562,11.0255541 C20.0619989,10.8865327 20.0818591,10.4694687 19.7839562,10.3105871 L0.579148261,0.0428666046 Z M11.6138902,17.0883151 L9.85385903,14.7195502 L0.718169621,0.618812241 L12.69945,12.9346347 L11.6138902,17.0883151 Z' id='shape'%3E%3C/path%3E %3C/g%3E %3C/g%3E %3C/svg%3E");
169
+ height: 21px;
170
+ }
171
+ #cancel_btn::before {
172
+ content: url("data:image/svg+xml,%3Csvg width='21px' height='21px' viewBox='0 0 21 21' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E %3Cg id='pg' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E %3Cpath d='M10.2072007,20.088463 C11.5727865,20.088463 12.8594566,19.8259823 14.067211,19.3010209 C15.2749653,18.7760595 16.3386126,18.0538087 17.2581528,17.1342685 C18.177693,16.2147282 18.8982283,15.1527965 19.4197586,13.9484733 C19.9412889,12.7441501 20.202054,11.4557644 20.202054,10.0833163 C20.202054,8.71773046 19.9395733,7.43106036 19.4146119,6.22330603 C18.8896505,5.01555169 18.1673997,3.95018885 17.2478595,3.0272175 C16.3283192,2.10424615 15.2646719,1.3837109 14.0569176,0.865611739 C12.8491633,0.34751258 11.5624932,0.088463 10.1969073,0.088463 C8.83132146,0.088463 7.54636692,0.34751258 6.34204371,0.865611739 C5.1377205,1.3837109 4.07407321,2.10424615 3.15110186,3.0272175 C2.22813051,3.95018885 1.5058797,5.01555169 0.984349419,6.22330603 C0.46281914,7.43106036 0.202054,8.71773046 0.202054,10.0833163 C0.202054,11.4557644 0.4645347,12.7441501 0.9894961,13.9484733 C1.5144575,15.1527965 2.23670831,16.2147282 3.15624854,17.1342685 C4.07578877,18.0538087 5.1377205,18.7760595 6.34204371,19.3010209 C7.54636692,19.8259823 8.83475258,20.088463 10.2072007,20.088463 Z M10.2072007,18.2562448 C9.07493099,18.2562448 8.01471483,18.0452309 7.0265522,17.6232031 C6.03838956,17.2011753 5.17031614,16.6161693 4.42233192,15.8681851 C3.6743477,15.1202009 3.09105726,14.2521274 2.67246059,13.2639648 C2.25386392,12.2758022 2.04456558,11.215586 2.04456558,10.0833163 C2.04456558,8.95104663 2.25386392,7.89083047 2.67246059,6.90266784 C3.09105726,5.9145052 3.6743477,5.04643178 4.42233192,4.29844756 C5.17031614,3.55046334 6.036674,2.9671729 7.02140552,2.54857623 C8.00613703,2.12997956 9.06463763,1.92068122 10.1969073,1.92068122 C11.329177,1.92068122 12.3911087,2.12997956 13.3827025,2.54857623 C14.3742962,2.9671729 15.2440852,3.55046334 15.9920694,4.29844756 C16.7400537,5.04643178 17.3233441,5.9145052 17.7419408,6.90266784 C18.1605374,7.89083047 18.3698358,8.95104663 18.3698358,10.0833163 C18.3698358,11.215586 18.1605374,12.2758022 17.7419408,13.2639648 C17.3233441,14.2521274 16.7400537,15.1202009 15.9920694,15.8681851 C15.2440852,16.6161693 14.3760118,17.2011753 13.3878492,17.6232031 C12.3996865,18.0452309 11.3394704,18.2562448 10.2072007,18.2562448 Z M7.65444721,13.6242324 L12.7496608,13.6242324 C13.0584616,13.6242324 13.3003556,13.5384544 13.4753427,13.3668984 C13.6503299,13.1953424 13.7378234,12.9585951 13.7378234,12.6566565 L13.7378234,7.49968276 C13.7378234,7.19774418 13.6503299,6.96099688 13.4753427,6.78944087 C13.3003556,6.61788486 13.0584616,6.53210685 12.7496608,6.53210685 L7.65444721,6.53210685 C7.33878414,6.53210685 7.09345904,6.61788486 6.91847191,6.78944087 C6.74348478,6.96099688 6.65599121,7.19774418 6.65599121,7.49968276 L6.65599121,12.6566565 C6.65599121,12.9585951 6.74348478,13.1953424 6.91847191,13.3668984 C7.09345904,13.5384544 7.33878414,13.6242324 7.65444721,13.6242324 Z' id='shape' fill='%23FF3B30' fill-rule='nonzero'%3E%3C/path%3E %3C/g%3E %3C/svg%3E");
173
+ height: 21px;
174
+ }
175
  /* list */
176
  ol:not(.options), ul:not(.options) {
177
  padding-inline-start: 2em !important;
178
  }
179
 
180
+ /* 亮色(默认) */
181
+ #chuanhu_chatbot {
182
+ background-color: var(--chatbot-color-light) !important;
183
+ color: #000000 !important;
184
+ }
185
+ [data-testid = "bot"] {
186
+ background-color: #FFFFFF !important;
187
+ }
188
+ [data-testid = "user"] {
189
+ background-color: #95EC69 !important;
190
+ }
191
+ /* 暗色 */
192
+ .dark #chuanhu_chatbot {
193
+ background-color: var(--chatbot-color-dark) !important;
194
+ color: #FFFFFF !important;
195
+ }
196
+ .dark [data-testid = "bot"] {
197
+ background-color: #2C2C2C !important;
198
+ }
199
+ .dark [data-testid = "user"] {
200
+ background-color: #26B561 !important;
201
+ }
202
+
203
+ /* 屏幕宽度大于等于500px的设备 */
204
+ /* update on 2023.4.8: 高度的细致调整已写入JavaScript */
205
+ @media screen and (min-width: 500px) {
206
  #chuanhu_chatbot {
207
+ height: calc(100vh - 200px);
 
208
  }
209
+ #chuanhu_chatbot .wrap {
210
+ max-height: calc(100vh - 200px - var(--line-sm)*1rem - 2*var(--block-label-margin) );
 
 
 
211
  }
212
  }
213
+ /* 屏幕宽度小于500px的设备 */
214
+ @media screen and (max-width: 499px) {
215
  #chuanhu_chatbot {
216
+ height: calc(100vh - 140px);
 
217
  }
218
+ #chuanhu_chatbot .wrap {
219
+ max-height: calc(100vh - 140px - var(--line-sm)*1rem - 2*var(--block-label-margin) );
220
  }
221
+ [data-testid = "bot"] {
222
+ max-width: 98% !important;
223
  }
224
+ #app_title h1{
225
+ letter-spacing: -1px; font-size: 22px;
226
  }
227
  }
228
  /* 对话气泡 */
assets/custom.js CHANGED
@@ -1,70 +1,224 @@
 
1
  // custom javascript here
 
2
  const MAX_HISTORY_LENGTH = 32;
3
 
4
  var key_down_history = [];
5
  var currentIndex = -1;
6
  var user_input_ta;
7
 
 
 
 
 
 
 
 
 
8
  var ga = document.getElementsByTagName("gradio-app");
9
  var targetNode = ga[0];
10
- var observer = new MutationObserver(function(mutations) {
 
 
 
11
  for (var i = 0; i < mutations.length; i++) {
12
- if (mutations[i].addedNodes.length) {
13
- var user_input_tb = document.getElementById('user_input_tb');
14
- if (user_input_tb) {
15
- // 监听到user_input_tb被添加到DOM树中
16
- // 这里可以编写元素加载完成后需要执行的代码
17
- user_input_ta = user_input_tb.querySelector("textarea");
18
- if (user_input_ta){
19
- observer.disconnect(); // 停止监听
20
- // textarea 上监听 keydown 事件
21
- user_input_ta.addEventListener("keydown", function (event) {
22
- var value = user_input_ta.value.trim();
23
- // 判断按下的是否为方向键
24
- if (event.code === 'ArrowUp' || event.code === 'ArrowDown') {
25
- // 如果按下的是方向键,且输入框中有内容,且历史记录中没有该内容,则不执行操作
26
- if(value && key_down_history.indexOf(value) === -1)
27
- return;
28
- // 对于需要响应的动作,阻止默认行为。
29
- event.preventDefault();
30
- var length = key_down_history.length;
31
- if(length === 0) {
32
- currentIndex = -1; // 如果历史记录为空,直接将当前选中的记录重置
33
- return;
34
- }
35
- if (currentIndex === -1) {
36
- currentIndex = length;
37
- }
38
- if (event.code === 'ArrowUp' && currentIndex > 0) {
39
- currentIndex--;
40
- user_input_ta.value = key_down_history[currentIndex];
41
- } else if (event.code === 'ArrowDown' && currentIndex < length - 1) {
42
- currentIndex++;
43
- user_input_ta.value = key_down_history[currentIndex];
44
- }
45
- user_input_ta.selectionStart = user_input_ta.value.length;
46
- user_input_ta.selectionEnd = user_input_ta.value.length;
47
- const input_event = new InputEvent("input", {bubbles: true, cancelable: true});
48
- user_input_ta.dispatchEvent(input_event);
49
- }else if(event.code === "Enter") {
50
- if (value) {
51
- currentIndex = -1;
52
- if(key_down_history.indexOf(value) === -1){
53
- key_down_history.push(value);
54
- if (key_down_history.length > MAX_HISTORY_LENGTH) {
55
- key_down_history.shift();
56
- }
57
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  }
59
  }
60
- });
61
- break;
62
  }
63
- }
 
 
 
 
 
 
 
 
 
64
  }
65
- }
66
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- // 监听目标节点的子节点列表是否发生变化
69
- observer.observe(targetNode, { childList: true , subtree: true });
 
 
 
 
 
 
 
 
 
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
  // custom javascript here
3
+
4
  const MAX_HISTORY_LENGTH = 32;
5
 
6
  var key_down_history = [];
7
  var currentIndex = -1;
8
  var user_input_ta;
9
 
10
+ var gradioContainer = null;
11
+ var user_input_ta = null;
12
+ var user_input_tb = null;
13
+ var userInfoDiv = null;
14
+ var appTitleDiv = null;
15
+ var chatbot = null;
16
+ var apSwitch = null;
17
+
18
  var ga = document.getElementsByTagName("gradio-app");
19
  var targetNode = ga[0];
20
+ var isInIframe = (window.self !== window.top);
21
+
22
+ // gradio 页面加载好了么??? 我能动你的元素了么??
23
+ function gradioLoaded(mutations) {
24
  for (var i = 0; i < mutations.length; i++) {
25
+ if (mutations[i].addedNodes.length) {
26
+ gradioContainer = document.querySelector(".gradio-container");
27
+ user_input_tb = document.getElementById('user_input_tb');
28
+ userInfoDiv = document.getElementById("user_info");
29
+ appTitleDiv = document.getElementById("app_title");
30
+ chatbot = document.querySelector('#chuanhu_chatbot');
31
+ apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
32
+
33
+ if (gradioContainer && apSwitch) { // gradioCainter 加载出来了没?
34
+ adjustDarkMode();
35
+ }
36
+ if (user_input_tb) { // user_input_tb 加载出来了没?
37
+ selectHistory();
38
+ }
39
+ if (userInfoDiv && appTitleDiv) { // userInfoDiv 和 appTitleDiv 加载出来了没?
40
+ setTimeout(showOrHideUserInfo(), 2000);
41
+ }
42
+ if (chatbot) { // chatbot 加载出来了没?
43
+ setChatbotHeight()
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ function selectHistory() {
50
+ user_input_ta = user_input_tb.querySelector("textarea");
51
+ if (user_input_ta) {
52
+ observer.disconnect(); // 停止监听
53
+ // textarea 上监听 keydown 事件
54
+ user_input_ta.addEventListener("keydown", function (event) {
55
+ var value = user_input_ta.value.trim();
56
+ // 判断按下的是否为方向键
57
+ if (event.code === 'ArrowUp' || event.code === 'ArrowDown') {
58
+ // ���果按下的是方向键,且输入框中有内容,且历史记录中没有该内容,则不执行操作
59
+ if (value && key_down_history.indexOf(value) === -1)
60
+ return;
61
+ // 对于需要响应的动作,阻止默认行为。
62
+ event.preventDefault();
63
+ var length = key_down_history.length;
64
+ if (length === 0) {
65
+ currentIndex = -1; // 如果历史记录为空,直接将当前选中的记录重置
66
+ return;
67
+ }
68
+ if (currentIndex === -1) {
69
+ currentIndex = length;
70
+ }
71
+ if (event.code === 'ArrowUp' && currentIndex > 0) {
72
+ currentIndex--;
73
+ user_input_ta.value = key_down_history[currentIndex];
74
+ } else if (event.code === 'ArrowDown' && currentIndex < length - 1) {
75
+ currentIndex++;
76
+ user_input_ta.value = key_down_history[currentIndex];
77
+ }
78
+ user_input_ta.selectionStart = user_input_ta.value.length;
79
+ user_input_ta.selectionEnd = user_input_ta.value.length;
80
+ const input_event = new InputEvent("input", { bubbles: true, cancelable: true });
81
+ user_input_ta.dispatchEvent(input_event);
82
+ } else if (event.code === "Enter") {
83
+ if (value) {
84
+ currentIndex = -1;
85
+ if (key_down_history.indexOf(value) === -1) {
86
+ key_down_history.push(value);
87
+ if (key_down_history.length > MAX_HISTORY_LENGTH) {
88
+ key_down_history.shift();
89
  }
90
  }
91
+ }
 
92
  }
93
+ });
94
+ }
95
+ }
96
+
97
+ function toggleUserInfoVisibility(shouldHide) {
98
+ if (userInfoDiv) {
99
+ if (shouldHide) {
100
+ userInfoDiv.classList.add("hideK");
101
+ } else {
102
+ userInfoDiv.classList.remove("hideK");
103
  }
104
+ }
105
+ }
106
+ function showOrHideUserInfo() {
107
+ var sendBtn = document.getElementById("submit_btn");
108
+
109
+ // Bind mouse/touch events to show/hide user info
110
+ appTitleDiv.addEventListener("mouseenter", function () {
111
+ toggleUserInfoVisibility(false);
112
+ });
113
+ userInfoDiv.addEventListener("mouseenter", function () {
114
+ toggleUserInfoVisibility(false);
115
+ });
116
+ sendBtn.addEventListener("mouseenter", function () {
117
+ toggleUserInfoVisibility(false);
118
+ });
119
+
120
+ appTitleDiv.addEventListener("mouseleave", function () {
121
+ toggleUserInfoVisibility(true);
122
+ });
123
+ userInfoDiv.addEventListener("mouseleave", function () {
124
+ toggleUserInfoVisibility(true);
125
+ });
126
+ sendBtn.addEventListener("mouseleave", function () {
127
+ toggleUserInfoVisibility(true);
128
+ });
129
+
130
+ appTitleDiv.ontouchstart = function () {
131
+ toggleUserInfoVisibility(false);
132
+ };
133
+ userInfoDiv.ontouchstart = function () {
134
+ toggleUserInfoVisibility(false);
135
+ };
136
+ sendBtn.ontouchstart = function () {
137
+ toggleUserInfoVisibility(false);
138
+ };
139
+
140
+ appTitleDiv.ontouchend = function () {
141
+ setTimeout(function () {
142
+ toggleUserInfoVisibility(true);
143
+ }, 3000);
144
+ };
145
+ userInfoDiv.ontouchend = function () {
146
+ setTimeout(function () {
147
+ toggleUserInfoVisibility(true);
148
+ }, 3000);
149
+ };
150
+ sendBtn.ontouchend = function () {
151
+ setTimeout(function () {
152
+ toggleUserInfoVisibility(true);
153
+ }, 3000); // Delay 1 second to hide user info
154
+ };
155
+
156
+ // Hide user info after 2 second
157
+ setTimeout(function () {
158
+ toggleUserInfoVisibility(true);
159
+ }, 2000);
160
+ }
161
 
162
+ function toggleDarkMode(isEnabled) {
163
+ if (isEnabled) {
164
+ gradioContainer.classList.add("dark");
165
+ document.body.style.setProperty("background-color", "var(--neutral-950)", "important");
166
+ } else {
167
+ gradioContainer.classList.remove("dark");
168
+ document.body.style.backgroundColor = "";
169
+ }
170
+ }
171
+ function adjustDarkMode() {
172
+ const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
173
 
174
+ // 根据当前颜色模式设置初始状态
175
+ apSwitch.checked = darkModeQuery.matches;
176
+ toggleDarkMode(darkModeQuery.matches);
177
+ // 监听颜色模式变化
178
+ darkModeQuery.addEventListener("change", (e) => {
179
+ apSwitch.checked = e.matches;
180
+ toggleDarkMode(e.matches);
181
+ });
182
+ // apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
183
+ apSwitch.addEventListener("change", (e) => {
184
+ toggleDarkMode(e.target.checked);
185
+ });
186
+ }
187
+
188
+ function setChatbotHeight() {
189
+ const screenWidth = window.innerWidth;
190
+ const statusDisplay = document.querySelector('#status_display');
191
+ const statusDisplayHeight = statusDisplay ? statusDisplay.offsetHeight : 0;
192
+ const wrap = chatbot.querySelector('.wrap');
193
+ const vh = window.innerHeight * 0.01;
194
+ document.documentElement.style.setProperty('--vh', `${vh}px`);
195
+ if (isInIframe) {
196
+ chatbot.style.height = `700px`;
197
+ wrap.style.maxHeight = `calc(700px - var(--line-sm) * 1rem - 2 * var(--block-label-margin))`
198
+ } else {
199
+ if (screenWidth <= 320) {
200
+ chatbot.style.height = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 150}px)`;
201
+ wrap.style.maxHeight = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 150}px - var(--line-sm) * 1rem - 2 * var(--block-label-margin))`;
202
+ } else if (screenWidth <= 499) {
203
+ chatbot.style.height = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 100}px)`;
204
+ wrap.style.maxHeight = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 100}px - var(--line-sm) * 1rem - 2 * var(--block-label-margin))`;
205
+ } else {
206
+ chatbot.style.height = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 160}px)`;
207
+ wrap.style.maxHeight = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 160}px - var(--line-sm) * 1rem - 2 * var(--block-label-margin))`;
208
+ }
209
+ }
210
+ }
211
+
212
+ // 监视页面内部 DOM 变动
213
+ var observer = new MutationObserver(function (mutations) {
214
+ gradioLoaded(mutations);
215
+ });
216
+ observer.observe(targetNode, { childList: true, subtree: true });
217
+
218
+ // 监视页面变化
219
+ window.addEventListener("DOMContentLoaded", function () {
220
+ isInIframe = (window.self !== window.top);
221
+ });
222
+ window.addEventListener('resize', setChatbotHeight);
223
+ window.addEventListener('scroll', setChatbotHeight);
224
+ window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", adjustDarkMode);
config_example.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ // 你的OpenAI API Key,一般必填,
3
+ // 若缺省填为 "openai_api_key": "" 则必须再在图形界面中填入API Key
4
+ "openai_api_key": "",
5
+ "language": "auto",
6
+ // 如果使用代理,请取消注释下面的两行,并替换代理URL
7
+ // "https_proxy": "http://127.0.0.1:1079",
8
+ // "http_proxy": "http://127.0.0.1:1079",
9
+ "users": [], // 用户列表,[[用户名1, 密码1], [用户名2, 密码2], ...]
10
+ "local_embedding": false, //是否在本地编制索引
11
+ "default_model": "gpt-3.5-turbo", // 默认模型
12
+ "advance_docs": {
13
+ "pdf": {
14
+ // 是否认为PDF是双栏的
15
+ "two_column": false,
16
+ // 是否使用OCR识别PDF中的公式
17
+ "formula_ocr": true
18
+ }
19
+ },
20
+ // 是否多个API Key轮换使用
21
+ "multi_api_key": false,
22
+ "api_key_list": [
23
+ "sk-xxxxxxxxxxxxxxxxxxxxxxxx1",
24
+ "sk-xxxxxxxxxxxxxxxxxxxxxxxx2",
25
+ "sk-xxxxxxxxxxxxxxxxxxxxxxxx3"
26
+ ],
27
+ // 如果使用自定义端口、自定义ip,请取消注释并替换对应内容
28
+ // "server_name": "0.0.0.0",
29
+ // "server_port": 7860,
30
+ // 如果要share到gradio,设置为true
31
+ // "share": false,
32
+ }
configs/ds_config_chatbot.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fp16": {
3
+ "enabled": false
4
+ },
5
+ "bf16": {
6
+ "enabled": true
7
+ },
8
+ "comms_logger": {
9
+ "enabled": false,
10
+ "verbose": false,
11
+ "prof_all": false,
12
+ "debug": false
13
+ },
14
+ "steps_per_print": 20000000000000000,
15
+ "train_micro_batch_size_per_gpu": 1,
16
+ "wall_clock_breakdown": false
17
+ }
locale/en_US.json ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "未命名对话历史记录": "Unnamed Dialog History",
3
+ "在这里输入": "Type in here",
4
+ "🧹 新的对话": "🧹 New Dialogue",
5
+ "🔄 重新生成": "🔄 Regeneration",
6
+ "🗑️ 删除最旧对话": "🗑️ Delete oldest dialog",
7
+ "🗑️ 删除最新对话": "🗑️ Delete latest dialog",
8
+ "模型": "Model",
9
+ "多账号模式已开启,无需输入key,可直接开始对话": "Multi-account mode is enabled, no need to enter key, you can start the dialogue directly",
10
+ "**发送消息** 或 **提交key** 以显示额度": "**Send message** or **Submit key** to display credit",
11
+ "选择模型": "Select Model",
12
+ "选择LoRA模型": "Select LoRA Model",
13
+ "实时传输回答": "Stream output",
14
+ "单轮对话": "Single-turn dialogue",
15
+ "使用在线搜索": "Use online search",
16
+ "选择回复语言(针对搜索&索引功能)": "Select reply language (for search & index)",
17
+ "上传索引文件": "Upload index file",
18
+ "双栏pdf": "Two-column pdf",
19
+ "识别公式": "formula OCR",
20
+ "在这里输入System Prompt...": "Type in System Prompt here...",
21
+ "加载Prompt模板": "Load Prompt Template",
22
+ "选择Prompt模板集合文件": "Select Prompt Template Collection File",
23
+ "🔄 刷新": "🔄 Refresh",
24
+ "从Prompt模板中加载": "Load from Prompt Template",
25
+ "保存/加载": "Save/Load",
26
+ "保存/加载对话历史记录": "Save/Load Dialog History",
27
+ "从列表中加载对话": "Load dialog from list",
28
+ "设置文件名: 默认为.json,可选为.md": "Set file name: default is .json, optional is .md",
29
+ "设置保存文件名": "Set save file name",
30
+ "对话历史记录": "Dialog History",
31
+ "💾 保存对话": "💾 Save Dialog",
32
+ "📝 导出为Markdown": "📝 Export as Markdown",
33
+ "默认保存于history文件夹": "Default save in history folder",
34
+ "高级": "Advanced",
35
+ "# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置": "# ⚠️ Caution: Changes require care. ⚠️\n\nIf unable to use, restore default settings.",
36
+ "参数": "Parameters",
37
+ "在这里输入停止符,用英文逗号隔开...": "Type in stop token here, separated by comma...",
38
+ "用于定位滥用行为": "Used to locate abuse",
39
+ "用户名": "Username",
40
+ "网络设置": "Network Settings",
41
+ "在这里输入API-Host...": "Type in API-Host here...",
42
+ "🔄 切换API地址": "🔄 Switch API Address",
43
+ "在这里输入代理地址...": "Type in proxy address here...",
44
+ "代理地址(示例:http://127.0.0.1:10809)": "Proxy address (example: http://127.0.0.1:10809)",
45
+ "🔄 设置代理地址": "🔄 Set Proxy Address",
46
+ "🔙 恢复默认设置": "🔙 Restore Default Settings",
47
+ "川虎Chat 🚀": "Chuanhu Chat 🚀",
48
+ "开始实时传输回答……": "Start streaming output...",
49
+ "Token 计数: ": "Token Count: ",
50
+ ",本次对话累计消耗了 ": ",Total cost for this dialogue is ",
51
+ "**获取API使用情况失败**": "**Failed to get API usage**",
52
+ "**本月使用金额** ": "**Monthly usage** ",
53
+ "获取API使用情况失败:": "Failed to get API usage:",
54
+ "API密钥更改为了": "The API key is changed to",
55
+ "JSON解析错误,收到的内容: ": "JSON parsing error, received content: ",
56
+ "模型设置为了:": "Model is set to: ",
57
+ "☹️发生了错误:": "☹️Error: ",
58
+ "获取对话时发生错误,请查看后台日志": "Error occurred when getting dialogue, check the background log",
59
+ "请检查网络连接,或者API-Key是否有效。": "Check the network connection or whether the API-Key is valid.",
60
+ "连接超时,无法获取对话。": "Connection timed out, unable to get dialogue.",
61
+ "读取超时,无法获取对话。": "Read timed out, unable to get dialogue.",
62
+ "代理错误,无法获取对话。": "Proxy error, unable to get dialogue.",
63
+ "SSL错误,无法获取对话。": "SSL error, unable to get dialogue.",
64
+ "API key为空,请检查是否输入正确。": "API key is empty, check whether it is entered correctly.",
65
+ "请输入对话内容。": "Enter the content of the conversation.",
66
+ "账单信息不适用": "Billing information is not applicable",
67
+ "由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本": "developor: Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) and [明昭MZhao](https://space.bilibili.com/24807452)\n\nDownload latest code from [GitHub](https://github.com/GaiZhenbiao/ChuanhuChatGPT)",
68
+ "切换亮暗色主题": "Switch light/dark theme",
69
+ "您的IP区域:未知。": "Your IP region: Unknown.",
70
+ "获取IP地理位置失败。原因:": "Failed to get IP location. Reason: ",
71
+ "。你仍然可以使用聊天功能。": ". You can still use the chat function.",
72
+ "您的IP区域:": "Your IP region: "
73
+ }
locale/extract_locale.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import re
4
+
5
+ # Define regular expression patterns
6
+ pattern = r'i18n\((\"{3}.*?\"{3}|\".*?\")\)'
7
+
8
+ # Load the .py file
9
+ with open('ChuanhuChatbot.py', 'r', encoding='utf-8') as f:
10
+ contents = f.read()
11
+
12
+ # Load the .py files in the modules folder
13
+ for filename in os.listdir("modules"):
14
+ if filename.endswith(".py"):
15
+ with open(os.path.join("modules", filename), "r", encoding="utf-8") as f:
16
+ contents += f.read()
17
+
18
+ # Matching with regular expressions
19
+ matches = re.findall(pattern, contents, re.DOTALL)
20
+
21
+ # Convert to key/value pairs
22
+ data = {match.strip('()"'): '' for match in matches}
23
+
24
+ # Save as a JSON file
25
+ with open('labels.json', 'w', encoding='utf-8') as f:
26
+ json.dump(data, f, ensure_ascii=False, indent=4)
locale/ja_JP.json ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "未命名对话历史记录": "名無しの会話履歴",
3
+ "在这里输入": "ここに入力",
4
+ "🧹 新的对话": "🧹 新しい会話",
5
+ "🔄 重新生成": "🔄 再生成",
6
+ "🗑️ 删除最旧对话": "🗑️ 最古の会話削除",
7
+ "🗑️ 删除最新对话": "🗑️ 最新の会話削除",
8
+ "模型": "LLMモデル",
9
+ "多账号模式已开启,无需输入key,可直接开始对话": "複数アカウントモードがオンになっています。キーを入力する必要はありません。会話を開始できます",
10
+ "**发送消息** 或 **提交key** 以显示额度": "**メッセージを送信** または **キーを送信** して、クレジットを表示します",
11
+ "选择模型": "LLMモデルを選択",
12
+ "选择LoRA模型": "LoRAモデルを選択",
13
+ "实时传输回答": "ストリーム出力",
14
+ "单轮对话": "単発会話",
15
+ "使用在线搜索": "オンライン検索を使用",
16
+ "选择回复语言(针对搜索&索引功能)": "回答言語を選択(検索とインデックス機能に対して)",
17
+ "上传索引文件": "インデックスファイルをアップロード",
18
+ "双栏pdf": "2カラムpdf",
19
+ "识别公式": "formula OCR",
20
+ "在这里输入System Prompt...": "System Promptを入力してください...",
21
+ "加载Prompt模板": "Promptテンプレートを読込",
22
+ "选择Prompt模板集合文件": "Promptテンプレートコレクションを選択",
23
+ "🔄 刷新": "🔄 更新",
24
+ "从Prompt模板中加载": "Promptテンプレートから読込",
25
+ "保存/加载": "保存/読込",
26
+ "保存/加载对话历史记录": "会話履歴を保存/読込",
27
+ "从列表中加载对话": "リストから会話を読込",
28
+ "设置文件名: 默认为.json,可选为.md": "ファイル名を設定: デフォルトは.json、.mdを選択できます",
29
+ "设置保存文件名": "保存ファイル名を設定",
30
+ "对话历史记录": "会話履歴",
31
+ "💾 保存对话": "💾 会話を保存",
32
+ "📝 导出为Markdown": "📝 Markdownでエクスポート",
33
+ "默认保存于history文件夹": "デフォルトでhistoryフォルダに保存されます",
34
+ "高级": "Advanced",
35
+ "# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置": "# ⚠️ 変更には慎重に ⚠️\n\nもし動作しない場合は、デフォルト設定に戻してください。",
36
+ "参数": "パラメータ",
37
+ "在这里输入停止符,用英文逗号隔开...": "ここにストップ文字を英語のカンマで区切って入力してください...",
38
+ "用于定位滥用行为": "不正行為を特定するために使用されます",
39
+ "用户名": "ユーザー名",
40
+ "网络设置": "ネットワーク設定",
41
+ "在这里输入API-Host...": "API-Hostを入力してください...",
42
+ "🔄 切换API地址": "🔄 APIアドレスを切り替え",
43
+ "在这里输入代理地址...": "プロキシアドレスを入力してください...",
44
+ "代理地址(示例:http://127.0.0.1:10809)": "プロキシアドレス(例:http://127.0.0.1:10809)",
45
+ "🔄 设置代理地址": "🔄 プロキシアドレスを設定",
46
+ "🔙 恢复默认设置": "🔙 デフォルト設定に戻す",
47
+ "川虎Chat 🚀": "川虎Chat 🚀",
48
+ "开始实时传输回答……": "ストリーム出力開始……",
49
+ "Token 计数: ": "Token数: ",
50
+ ",本次对话累计消耗了 ": ", 今の会話で消費合計 ",
51
+ "**获取API使用情况失败**": "**API使用状況の取得に失敗しました**",
52
+ "**本月使用金额** ": "**今月の使用料金** ",
53
+ "获取API使用情况失败:": "API使用状況の取得に失敗しました:",
54
+ "API密钥更改为了": "APIキーが変更されました",
55
+ "JSON解析错误,收到的内容: ": "JSON解析エラー、受信内容: ",
56
+ "模型设置为了:": "LLMモデルを設定しました: ",
57
+ "☹️发生了错误:": "エラーが発生しました: ",
58
+ "获取对话时发生错误,请查看后台日志": "会話取得時にエラー発生、あとのログを確認してください",
59
+ "请检查网络连接,或者API-Key是否有效。": "ネットワーク接続を確認するか、APIキーが有効かどうかを確認してください。",
60
+ "连接超时,无法获取对话。": "接続タイムアウト、会話を取得できません。",
61
+ "读取超时,无法获取对话。": "読み込みタイムアウト、会話を取得できません。",
62
+ "代理错误,无法获取对话。": "プロキシエラー、会話を取得できません。",
63
+ "SSL错误,无法获取对话。": "SSLエラー、会話を取得できません。",
64
+ "API key为空,请检查是否输入正确。": "APIキーが入力されていません。正しく入力されているか確認してください。",
65
+ "请输入对话内容。": "会話内容を入力してください。",
66
+ "账单信息不适用": "課金情報は対象外です",
67
+ "由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本": "開発:Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) と [明昭MZhao](https://space.bilibili.com/24807452)\n\n最新コードは川虎Chatのサイトへ [GitHubプロジェクト](https://github.com/GaiZhenbiao/ChuanhuChatGPT)",
68
+ "切换亮暗色主题": "テーマの明暗切替",
69
+ "您的IP区域:未知。": "あなたのIPアドレス地域:不明",
70
+ "获取IP地理位置失败。原因:": "IPアドレス地域の取得に失敗しました。理由:",
71
+ "。你仍然可以使用聊天功能。": "。あなたはまだチャット機能を使用できます。",
72
+ "您的IP区域:": "あなたのIPアドレス地域:"
73
+ }
modules/__init__.py ADDED
File without changes
modules/base_model.py ADDED
@@ -0,0 +1,550 @@