Keldos commited on
Commit
73d2fd7
·
1 Parent(s): b996b77

feat: 加入latex渲染参数

Browse files
ChuanhuChatbot.py CHANGED
@@ -50,7 +50,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
50
  with gr.Row().style(equal_height=True):
51
  with gr.Column(scale=5):
52
  with gr.Row():
53
- chatbot = gr.Chatbot(label="Chuanhu Chat", 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(
 
50
  with gr.Row().style(equal_height=True):
51
  with gr.Column(scale=5):
52
  with gr.Row():
53
+ chatbot = gr.Chatbot(label="Chuanhu Chat", elem_id="chuanhu_chatbot", latex_delimiters=latex_delimiters_set).style(height="100%")
54
  with gr.Row():
55
  with gr.Column(min_width=225, scale=12):
56
  user_input = gr.Textbox(
config_example.json CHANGED
@@ -28,6 +28,7 @@
28
  "WOLFRAM_ALPHA_APPID": "", //Wolfram Alpha API Key,用于川虎助理Pro模式,获取方式请看 https://products.wolframalpha.com/api/
29
  "SERPAPI_API_KEY": "", //SerpAPI API Key,用于川虎助理Pro模式,获取方式请看 https://serpapi.com/
30
 
 
31
  "advance_docs": {
32
  "pdf": {
33
  // 是否认为PDF是双栏的
 
28
  "WOLFRAM_ALPHA_APPID": "", //Wolfram Alpha API Key,用于川虎助理Pro模式,获取方式请看 https://products.wolframalpha.com/api/
29
  "SERPAPI_API_KEY": "", //SerpAPI API Key,用于川虎助理Pro模式,获取方式请看 https://serpapi.com/
30
 
31
+ "latex_option": "default", // latex 公式显示方式,可选"default", "strict", "all"或者"disabled"
32
  "advance_docs": {
33
  "pdf": {
34
  // 是否认为PDF是双栏的
modules/config.py CHANGED
@@ -24,6 +24,7 @@ __all__ = [
24
  "server_port",
25
  "share",
26
  "check_update",
 
27
  "hide_history_when_not_logged_in",
28
  "default_chuanhu_assistant_model"
29
  ]
@@ -158,6 +159,42 @@ def retrieve_proxy(proxy=None):
158
  # return old proxy
159
  os.environ["HTTP_PROXY"], os.environ["HTTPS_PROXY"] = old_var
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  ## 处理advance docs
163
  advance_docs = defaultdict(lambda: defaultdict(dict))
 
24
  "server_port",
25
  "share",
26
  "check_update",
27
+ "latex_delimiters_set",
28
  "hide_history_when_not_logged_in",
29
  "default_chuanhu_assistant_model"
30
  ]
 
159
  # return old proxy
160
  os.environ["HTTP_PROXY"], os.environ["HTTPS_PROXY"] = old_var
161
 
162
+ ## 处理latex options
163
+ user_latex_option = config.get("latex_option", "default")
164
+ if user_latex_option == "default":
165
+ latex_delimiters_set = [
166
+ {"left": "$$", "right": "$$", "display": True},
167
+ {"left": "$", "right": "$", "display": False},
168
+ {"left": "\\(", "right": "\\)", "display": False},
169
+ {"left": "\\[", "right": "\\]", "display": True},
170
+ ]
171
+ elif user_latex_option == "strict":
172
+ latex_delimiters_set = [
173
+ {"left": "$$", "right": "$$", "display": True},
174
+ {"left": "\\(", "right": "\\)", "display": False},
175
+ {"left": "\\[", "right": "\\]", "display": True},
176
+ ]
177
+ elif user_latex_option == "all":
178
+ latex_delimiters_set = [
179
+ {"left": "$$", "right": "$$", "display": True},
180
+ {"left": "$", "right": "$", "display": False},
181
+ {"left": "\\(", "right": "\\)", "display": False},
182
+ {"left": "\\[", "right": "\\]", "display": True},
183
+ {"left": "\\begin{equation}", "right": "\\end{equation}", "display": True},
184
+ {"left": "\\begin{align}", "right": "\\end{align}", "display": True},
185
+ {"left": "\\begin{alignat}", "right": "\\end{alignat}", "display": True},
186
+ {"left": "\\begin{gather}", "right": "\\end{gather}", "display": True},
187
+ {"left": "\\begin{CD}", "right": "\\end{CD}", "display": True},
188
+ ]
189
+ elif user_latex_option == "disabled":
190
+ latex_delimiters_set = []
191
+ else:
192
+ latex_delimiters_set = [
193
+ {"left": "$$", "right": "$$", "display": True},
194
+ {"left": "$", "right": "$", "display": False},
195
+ {"left": "\\(", "right": "\\)", "display": False},
196
+ {"left": "\\[", "right": "\\]", "display": True},
197
+ ]
198
 
199
  ## 处理advance docs
200
  advance_docs = defaultdict(lambda: defaultdict(dict))
modules/utils.py CHANGED
@@ -261,6 +261,7 @@ def escape_markdown(text):
261
  '>': '>',
262
  '<': '&#60;',
263
  '|': '&#124;',
 
264
  ':': '&#58;',
265
  }
266
  return ''.join(escape_chars.get(c, c) for c in text)
 
261
  '>': '&#62;',
262
  '<': '&#60;',
263
  '|': '&#124;',
264
+ '$': '&#36;',
265
  ':': '&#58;',
266
  }
267
  return ''.join(escape_chars.get(c, c) for c in text)