Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	修复公式重复显示的bug
Browse files- request_llm/bridge_newbing.py +4 -1
- toolbox.py +5 -1
    	
        request_llm/bridge_newbing.py
    CHANGED
    
    | @@ -15,6 +15,7 @@ load_message = "等待NewBing响应。" | |
| 15 | 
             
            import time
         | 
| 16 | 
             
            import json
         | 
| 17 | 
             
            import re
         | 
|  | |
| 18 | 
             
            import asyncio
         | 
| 19 | 
             
            import importlib
         | 
| 20 | 
             
            import threading
         | 
| @@ -26,7 +27,7 @@ def preprocess_newbing_out(s): | |
| 26 | 
             
                sub = lambda m: '\['+m.group(1)+'\]' # 将匹配到的数字作为替换值
         | 
| 27 | 
             
                result = re.sub(pattern, sub, s) # 替换操作
         | 
| 28 | 
             
                if '[1]' in result:
         | 
| 29 | 
            -
                    result += '\n\n | 
| 30 | 
             
                return result
         | 
| 31 |  | 
| 32 | 
             
            def preprocess_newbing_out_simple(result):
         | 
| @@ -247,5 +248,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp | |
| 247 | 
             
                    yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢,尚未完成全部响应,请耐心完成后再提交新问题。")
         | 
| 248 | 
             
                if response == "[Local Message]: 等待NewBing响应中 ...": response = "[Local Message]: NewBing响应异常,请刷新界面重试 ..."
         | 
| 249 | 
             
                history.extend([inputs, response])
         | 
|  | |
|  | |
| 250 | 
             
                yield from update_ui(chatbot=chatbot, history=history, msg="完成全部响应,请提交新问题。")
         | 
| 251 |  | 
|  | |
| 15 | 
             
            import time
         | 
| 16 | 
             
            import json
         | 
| 17 | 
             
            import re
         | 
| 18 | 
            +
            import logging
         | 
| 19 | 
             
            import asyncio
         | 
| 20 | 
             
            import importlib
         | 
| 21 | 
             
            import threading
         | 
|  | |
| 27 | 
             
                sub = lambda m: '\['+m.group(1)+'\]' # 将匹配到的数字作为替换值
         | 
| 28 | 
             
                result = re.sub(pattern, sub, s) # 替换操作
         | 
| 29 | 
             
                if '[1]' in result:
         | 
| 30 | 
            +
                    result += '\n\n<hr style="border-top: dotted 1px #44ac5c;">\n\n' + "\n\n".join(['`'+r+'`' for r in result.split('\n') if r.startswith('[')])
         | 
| 31 | 
             
                return result
         | 
| 32 |  | 
| 33 | 
             
            def preprocess_newbing_out_simple(result):
         | 
|  | |
| 248 | 
             
                    yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢,尚未完成全部响应,请耐心完成后再提交新问题。")
         | 
| 249 | 
             
                if response == "[Local Message]: 等待NewBing响应中 ...": response = "[Local Message]: NewBing响应异常,请刷新界面重试 ..."
         | 
| 250 | 
             
                history.extend([inputs, response])
         | 
| 251 | 
            +
                logging.info(f'[raw_input] {inputs}')
         | 
| 252 | 
            +
                logging.info(f'[response] {response}')
         | 
| 253 | 
             
                yield from update_ui(chatbot=chatbot, history=history, msg="完成全部响应,请提交新问题。")
         | 
| 254 |  | 
    	
        toolbox.py
    CHANGED
    
    | @@ -217,13 +217,17 @@ def text_divide_paragraph(text): | |
| 217 | 
             
                    text = "</br>".join(lines)
         | 
| 218 | 
             
                    return text
         | 
| 219 |  | 
| 220 | 
            -
             | 
| 221 | 
             
            def markdown_convertion(txt):
         | 
| 222 | 
             
                """
         | 
| 223 | 
             
                将Markdown格式的文本转换为HTML格式。如果包含数学公式,则先将公式转换为HTML格式。
         | 
| 224 | 
             
                """
         | 
| 225 | 
             
                pre = '<div class="markdown-body">'
         | 
| 226 | 
             
                suf = '</div>'
         | 
|  | |
|  | |
|  | |
|  | |
| 227 | 
             
                markdown_extension_configs = {
         | 
| 228 | 
             
                    'mdx_math': {
         | 
| 229 | 
             
                        'enable_dollar_delimiter': True,
         | 
|  | |
| 217 | 
             
                    text = "</br>".join(lines)
         | 
| 218 | 
             
                    return text
         | 
| 219 |  | 
| 220 | 
            +
            @lru_cache(maxsize=128) # 使用 lru缓存 加快转换速度
         | 
| 221 | 
             
            def markdown_convertion(txt):
         | 
| 222 | 
             
                """
         | 
| 223 | 
             
                将Markdown格式的文本转换为HTML格式。如果包含数学公式,则先将公式转换为HTML格式。
         | 
| 224 | 
             
                """
         | 
| 225 | 
             
                pre = '<div class="markdown-body">'
         | 
| 226 | 
             
                suf = '</div>'
         | 
| 227 | 
            +
                if txt.startswith(pre) and txt.endswith(suf):
         | 
| 228 | 
            +
                    # print('警告,输入了已经经过转化的字符串,二次转化可能出问题')
         | 
| 229 | 
            +
                    return txt # 已经被转化过,不需要再次转化
         | 
| 230 | 
            +
                
         | 
| 231 | 
             
                markdown_extension_configs = {
         | 
| 232 | 
             
                    'mdx_math': {
         | 
| 233 | 
             
                        'enable_dollar_delimiter': True,
         |