JunchuanYu commited on
Commit
0f0c6c1
1 Parent(s): 4bd0f1d

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +46 -34
utils.py CHANGED
@@ -18,9 +18,51 @@ from pygments import highlight
18
  from pygments.lexers import get_lexer_by_name
19
  from pygments.formatters import HtmlFormatter
20
 
21
- from presets import *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- # logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] %(message)s")
24
 
25
  if TYPE_CHECKING:
26
  from typing import TypedDict
@@ -115,8 +157,6 @@ def convert_mdtext(md_text):
115
  else:
116
  result.append(mdtex2html.convert(non_code, extensions=["tables"]))
117
  if code.strip():
118
- # _, code = detect_language(code) # 暂时去除代码高亮功能,因为在大段代码的情况下会出现问题
119
- # code = code.replace("\n\n", "\n") # 暂时去除代码中的空行,因为在大段代码的情况下会出现问题
120
  code = f"```{code}\n\n```"
121
  code = markdown_to_html_with_syntax_highlight(code)
122
  result.append(code)
@@ -209,32 +249,6 @@ def load_chat_history(filename, system, history, chatbot):
209
  return filename, system, history, chatbot
210
 
211
 
212
- def sorted_by_pinyin(list):
213
- return sorted(list, key=lambda char: lazy_pinyin(char)[0][0])
214
-
215
-
216
- def get_file_names(dir, plain=False, filetypes=[".json"]):
217
- # logging.info(f"获取文件名列表,目录为{dir},文件类型为{filetypes},是否为纯文本列表{plain}")
218
- files = []
219
- try:
220
- for type in filetypes:
221
- files += [f for f in os.listdir(dir) if f.endswith(type)]
222
- except FileNotFoundError:
223
- files = []
224
- files = sorted_by_pinyin(files)
225
- if files == []:
226
- files = [""]
227
- if plain:
228
- return files
229
- else:
230
- return gr.Dropdown.update(choices=files)
231
-
232
-
233
- def get_history_names(plain=False):
234
- # logging.info("获取历史记录文件名列表")
235
- return get_file_names(HISTORY_DIR, plain)
236
-
237
-
238
  def load_template(filename, mode=0):
239
  # logging.info(f"加载模板文件{filename},模式为{mode}(0为返回字典和下拉菜单,1为返回下拉菜单,2为返回字典)")
240
  lines = []
@@ -259,10 +273,8 @@ def load_template(filename, mode=0):
259
  return {row[0]: row[1] for row in lines}, gr.Dropdown.update(
260
  choices=choices, value=choices[0])
261
 
262
-
263
- def get_template_names(plain=False):
264
- # logging.info("获取模板文件名列表")
265
- return get_file_names(TEMPLATES_DIR, plain, filetypes=[".csv", "json"])
266
 
267
 
268
  def get_template_content(templates, selection, original_system_prompt):
 
18
  from pygments.lexers import get_lexer_by_name
19
  from pygments.formatters import HtmlFormatter
20
 
21
+ use_websearch_checkbox=False
22
+ use_streaming_checkbox=True
23
+ model_select_dropdown="gpt-3.5-turbo"
24
+ # top_p=1
25
+ dockerflag = True
26
+ authflag = False
27
+
28
+ # ChatGPT 设置
29
+ initial_prompt = "You are a helpful assistant."
30
+ API_URL = "https://api.openai.com/v1/chat/completions"
31
+ HISTORY_DIR = "history"
32
+ TEMPLATES_DIR = "./"
33
+
34
+ # 错误信息
35
+ standard_error_msg = "Error:" # 错误信息的标准前缀
36
+ error_retrieve_prompt = "Please check the network connection and the API-Key" # 获取对话时发生错误
37
+ connection_timeout_prompt = "Time out" # 连接超时
38
+ read_timeout_prompt = "Time out" # 读取超时
39
+ proxy_error_prompt = "Proxy error" # 代理错误
40
+ ssl_error_prompt = "SSL error" # SSL 错误
41
+ no_apikey_msg = "please check whether the input is correct" # API key 长度不足 51 位
42
+
43
+ max_token_streaming = 3500 # 流式对话时的最大 token 数
44
+ timeout_streaming = 5 # 流式对话时的超时时间
45
+ max_token_all = 3500 # 非流式对话时的最大 token 数
46
+ timeout_all = 200 # 非流式对话时的超时时间
47
+ enable_streaming_option = True # 是否启用选择选择是否实时显示回答的勾选框
48
+ HIDE_MY_KEY = True # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True
49
+
50
+ SIM_K = 5
51
+ INDEX_QUERY_TEMPRATURE = 1.0
52
+ title= """\
53
+ # <p align="center">Sydney-AI 2.0<b>"""
54
+
55
+ description = """\
56
+ <p>
57
+ <p>
58
+ 本应用是一款基于最新OpenAI API“gpt-3.5-turbo”开发的智能在线聊天应用。 该应用程序的运营成本由“45 Degrees Research Fellows”赞助。 目前,token 限制为 3500。如果你想取消这个限制,你可以输入你自己的 OpenAI API 密钥。 <p>
59
+ App默认角色为ChatGPT原版助手,但您也可以从模板提供的角色中进行选择。 如果您对自定义Prompt有好的建议,请联系我们!<p>
60
+ This app is an intelligent online chat app developed based on the newly released OpenAI API "gpt-3.5-turbo". The app's operating costs are sponsored by "45度科研人". Currently, the tokens is limited to 3500. If you want to remove this restriction, you can input your own OpenAI API key.<p>
61
+ The default model role of the app is the original assistant of ChatGPT, but you can also choose from the provided roles. If you have good suggestions for customizing Prompt, please contact us!<p>
62
+ """
63
+
64
+ MODELS = ["gpt-3.5-turbo", "gpt-3.5-turbo-0301",]
65
 
 
66
 
67
  if TYPE_CHECKING:
68
  from typing import TypedDict
 
157
  else:
158
  result.append(mdtex2html.convert(non_code, extensions=["tables"]))
159
  if code.strip():
 
 
160
  code = f"```{code}\n\n```"
161
  code = markdown_to_html_with_syntax_highlight(code)
162
  result.append(code)
 
249
  return filename, system, history, chatbot
250
 
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  def load_template(filename, mode=0):
253
  # logging.info(f"加载模板文件{filename},模式为{mode}(0为返回字典和下拉菜单,1为返回下拉菜单,2为返回字典)")
254
  lines = []
 
273
  return {row[0]: row[1] for row in lines}, gr.Dropdown.update(
274
  choices=choices, value=choices[0])
275
 
276
+ def sorted_by_pinyin(list):
277
+ return sorted(list, key=lambda char: lazy_pinyin(char)[0][0])
 
 
278
 
279
 
280
  def get_template_content(templates, selection, original_system_prompt):