Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	
		mrhblfx
		
	commited on
		
		
					Commit 
							
							·
						
						2f9a4e1
	
1
								Parent(s):
							
							f0fbc65
								
Add parsing arbitrary code items
Browse files- crazy_functional.py +10 -2
- crazy_functions/解析项目源代码.py +40 -9
- main.py +23 -4
- toolbox.py +11 -10
    	
        crazy_functional.py
    CHANGED
    
    | @@ -162,7 +162,7 @@ def get_crazy_functions(): | |
| 162 | 
             
                        "AsButton": False,  # 加入下拉菜单中
         | 
| 163 | 
             
                        "Function": HotReload(Markdown英译中)
         | 
| 164 | 
             
                    },
         | 
| 165 | 
            -
             | 
| 166 | 
             
                })
         | 
| 167 |  | 
| 168 | 
             
                ###################### 第三组插件 ###########################
         | 
| @@ -179,8 +179,16 @@ def get_crazy_functions(): | |
| 179 |  | 
| 180 | 
             
                except Exception as err:
         | 
| 181 | 
             
                    print(f'[下载arxiv论文并翻译摘要] 插件导入失败 {str(err)}')
         | 
| 182 | 
            -
                    
         | 
| 183 |  | 
| 184 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 185 | 
             
                ###################### 第n组插件 ###########################
         | 
| 186 | 
             
                return function_plugins
         | 
|  | |
| 162 | 
             
                        "AsButton": False,  # 加入下拉菜单中
         | 
| 163 | 
             
                        "Function": HotReload(Markdown英译中)
         | 
| 164 | 
             
                    },
         | 
| 165 | 
            +
             | 
| 166 | 
             
                })
         | 
| 167 |  | 
| 168 | 
             
                ###################### 第三组插件 ###########################
         | 
|  | |
| 179 |  | 
| 180 | 
             
                except Exception as err:
         | 
| 181 | 
             
                    print(f'[下载arxiv论文并翻译摘要] 插件导入失败 {str(err)}')
         | 
|  | |
| 182 |  | 
| 183 |  | 
| 184 | 
            +
                from crazy_functions.解析项目源代码 import 解析任意code项目
         | 
| 185 | 
            +
                function_plugins.update({
         | 
| 186 | 
            +
                    "解析任意code项目": {
         | 
| 187 | 
            +
                        "Color": "stop",
         | 
| 188 | 
            +
                        "AsButton": False,
         | 
| 189 | 
            +
                        "Function": HotReload(解析任意code项目)
         | 
| 190 | 
            +
                    },
         | 
| 191 | 
            +
                })
         | 
| 192 | 
            +
             | 
| 193 | 
             
                ###################### 第n组插件 ###########################
         | 
| 194 | 
             
                return function_plugins
         | 
    	
        crazy_functions/解析项目源代码.py
    CHANGED
    
    | @@ -11,7 +11,7 @@ def 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, | |
| 11 | 
             
                history_array = []
         | 
| 12 | 
             
                sys_prompt_array = []
         | 
| 13 | 
             
                report_part_1 = []
         | 
| 14 | 
            -
             | 
| 15 | 
             
                assert len(file_manifest) <= 1024, "源文件太多(超过1024个), 请缩减输入文件的数量。或者,您也可以选择删除此行警告,并修改代码拆分file_manifest列表,从而实现分批次处理。"
         | 
| 16 | 
             
                ############################## <第一步,逐个文件分析,多线程> ##################################
         | 
| 17 | 
             
                for index, fp in enumerate(file_manifest):
         | 
| @@ -63,10 +63,10 @@ def 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, | |
| 63 | 
             
                    current_iteration_focus = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(this_iteration_file_manifest)])
         | 
| 64 | 
             
                    i_say = f'根据以上分析,对程序的整体功能和构架重新做出概括。然后用一张markdown表格整理每个文件的功能(包括{previous_iteration_files_string})。'
         | 
| 65 | 
             
                    inputs_show_user = f'根据以上分析,对程序的整体功能和构架重新做出概括,由于输入长度限制,可能需要分组处理,本组文件为 {current_iteration_focus} + 已经汇总的文件组。'
         | 
| 66 | 
            -
                    this_iteration_history = copy.deepcopy(this_iteration_gpt_response_collection) | 
| 67 | 
             
                    this_iteration_history.append(last_iteration_result)
         | 
| 68 | 
             
                    result = yield from request_gpt_model_in_new_thread_with_ui_alive(
         | 
| 69 | 
            -
                        inputs=i_say, inputs_show_user=inputs_show_user, llm_kwargs=llm_kwargs, chatbot=chatbot, | 
| 70 | 
             
                        history=this_iteration_history,   # 迭代之前的分析
         | 
| 71 | 
             
                        sys_prompt="你是一个程序架构分析师,正在分析一个项目的源代码。")
         | 
| 72 | 
             
                    report_part_2.extend([i_say, result])
         | 
| @@ -222,8 +222,8 @@ def 解析一个Golang项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s | |
| 222 | 
             
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
         | 
| 223 | 
             
                    return
         | 
| 224 | 
             
                yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
         | 
| 225 | 
            -
             | 
| 226 | 
            -
             | 
| 227 | 
             
            @CatchException
         | 
| 228 | 
             
            def 解析一个Lua项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
         | 
| 229 | 
             
                history = []    # 清空历史,以免输入溢出
         | 
| @@ -243,9 +243,9 @@ def 解析一个Lua项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst | |
| 243 | 
             
                    report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何lua文件: {txt}")
         | 
| 244 | 
             
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
         | 
| 245 | 
             
                    return
         | 
| 246 | 
            -
                yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) | 
| 247 | 
            -
             | 
| 248 | 
            -
             | 
| 249 | 
             
            @CatchException
         | 
| 250 | 
             
            def 解析一个CSharp项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
         | 
| 251 | 
             
                history = []    # 清空历史,以免输入溢出
         | 
| @@ -263,4 +263,35 @@ def 解析一个CSharp项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s | |
| 263 | 
             
                    report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何CSharp文件: {txt}")
         | 
| 264 | 
             
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
         | 
| 265 | 
             
                    return
         | 
| 266 | 
            -
                yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 11 | 
             
                history_array = []
         | 
| 12 | 
             
                sys_prompt_array = []
         | 
| 13 | 
             
                report_part_1 = []
         | 
| 14 | 
            +
             | 
| 15 | 
             
                assert len(file_manifest) <= 1024, "源文件太多(超过1024个), 请缩减输入文件的数量。或者,您也可以选择删除此行警告,并修改代码拆分file_manifest列表,从而实现分批次处理。"
         | 
| 16 | 
             
                ############################## <第一步,逐个文件分析,多线程> ##################################
         | 
| 17 | 
             
                for index, fp in enumerate(file_manifest):
         | 
|  | |
| 63 | 
             
                    current_iteration_focus = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(this_iteration_file_manifest)])
         | 
| 64 | 
             
                    i_say = f'根据以上分析,对程序的整体功能和构架重新做出概括。然后用一张markdown表格整理每个文件的功能(包括{previous_iteration_files_string})。'
         | 
| 65 | 
             
                    inputs_show_user = f'根据以上分析,对程序的整体功能和构架重新做出概括,由于输入长度限制,可能需要分组处理,本组文件为 {current_iteration_focus} + 已经汇总的文件组。'
         | 
| 66 | 
            +
                    this_iteration_history = copy.deepcopy(this_iteration_gpt_response_collection)
         | 
| 67 | 
             
                    this_iteration_history.append(last_iteration_result)
         | 
| 68 | 
             
                    result = yield from request_gpt_model_in_new_thread_with_ui_alive(
         | 
| 69 | 
            +
                        inputs=i_say, inputs_show_user=inputs_show_user, llm_kwargs=llm_kwargs, chatbot=chatbot,
         | 
| 70 | 
             
                        history=this_iteration_history,   # 迭代之前的分析
         | 
| 71 | 
             
                        sys_prompt="你是一个程序架构分析师,正在分析一个项目的源代码。")
         | 
| 72 | 
             
                    report_part_2.extend([i_say, result])
         | 
|  | |
| 222 | 
             
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
         | 
| 223 | 
             
                    return
         | 
| 224 | 
             
                yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
         | 
| 225 | 
            +
             | 
| 226 | 
            +
             | 
| 227 | 
             
            @CatchException
         | 
| 228 | 
             
            def 解析一个Lua项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
         | 
| 229 | 
             
                history = []    # 清空历史,以免输入溢出
         | 
|  | |
| 243 | 
             
                    report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何lua文件: {txt}")
         | 
| 244 | 
             
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
         | 
| 245 | 
             
                    return
         | 
| 246 | 
            +
                yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
         | 
| 247 | 
            +
             | 
| 248 | 
            +
             | 
| 249 | 
             
            @CatchException
         | 
| 250 | 
             
            def 解析一个CSharp项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
         | 
| 251 | 
             
                history = []    # 清空历史,以免输入溢出
         | 
|  | |
| 263 | 
             
                    report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何CSharp文件: {txt}")
         | 
| 264 | 
             
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
         | 
| 265 | 
             
                    return
         | 
| 266 | 
            +
                yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
         | 
| 267 | 
            +
             | 
| 268 | 
            +
             | 
| 269 | 
            +
            @CatchException
         | 
| 270 | 
            +
            def 解析任意code项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
         | 
| 271 | 
            +
                txt_include = plugin_kwargs.get("txt_include")
         | 
| 272 | 
            +
                txt_except = plugin_kwargs.get("txt_except")
         | 
| 273 | 
            +
                # 将要匹配的后缀
         | 
| 274 | 
            +
                pattern_include = [_.lstrip(" .,,").rstrip(" ,,") for _ in txt_include.split(" ") if _ != ""]
         | 
| 275 | 
            +
                pattern_include = [_.lstrip(" .,,").rstrip(" ,,") for __ in pattern_include for _ in __.split(",") if _ != ""]
         | 
| 276 | 
            +
                pattern_include = [_.lstrip(" .,,").rstrip(" ,,") for __ in pattern_include for _ in __.split(",") if _ != ""]
         | 
| 277 | 
            +
                # 将要忽略匹配的后缀
         | 
| 278 | 
            +
                pattern_except = [_.lstrip(" .,,").rstrip(" ,,") for _ in txt_except.split(" ") if _ != ""]
         | 
| 279 | 
            +
                pattern_except = [_.lstrip(" .,,").rstrip(" ,,") for __ in pattern_except for _ in __.split(",") if _ != ""]
         | 
| 280 | 
            +
                pattern_except = [_.lstrip(" .,,").rstrip(" ,,") for __ in pattern_except for _ in __.split(",") if _ != ""]
         | 
| 281 | 
            +
                pattern_except += ['zip', 'rar', '7z', 'tar', 'gz'] # 避免解析上传的压缩文件
         | 
| 282 | 
            +
                history = []    # 清空历史,以免输入溢出
         | 
| 283 | 
            +
                import glob, os
         | 
| 284 | 
            +
                if os.path.exists(txt):
         | 
| 285 | 
            +
                    project_folder = txt
         | 
| 286 | 
            +
                else:
         | 
| 287 | 
            +
                    if txt == "": txt = '空空如也的输入栏'
         | 
| 288 | 
            +
                    report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
         | 
| 289 | 
            +
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
         | 
| 290 | 
            +
                    return
         | 
| 291 | 
            +
                file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.*', recursive=True) if os.path.isfile(f) and \
         | 
| 292 | 
            +
                                 ([] == pattern_include or f.split(".")[-1] in pattern_include) and f.split(".")[-1] not in pattern_except]
         | 
| 293 | 
            +
                if len(file_manifest) == 0:
         | 
| 294 | 
            +
                    report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何文件: {txt}")
         | 
| 295 | 
            +
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
         | 
| 296 | 
            +
                    return
         | 
| 297 | 
            +
                yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
         | 
    	
        main.py
    CHANGED
    
    | @@ -44,7 +44,7 @@ proxy_info = check_proxy(proxies) | |
| 44 |  | 
| 45 | 
             
            gr_L1 = lambda: gr.Row().style()
         | 
| 46 | 
             
            gr_L2 = lambda scale: gr.Column(scale=scale)
         | 
| 47 | 
            -
            if LAYOUT == "TOP-DOWN": | 
| 48 | 
             
                gr_L1 = lambda: DummyWith()
         | 
| 49 | 
             
                gr_L2 = lambda scale: gr.Row()
         | 
| 50 | 
             
                CHATBOT_HEIGHT /= 2
         | 
| @@ -83,9 +83,23 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled= | |
| 83 | 
             
                                    variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary"
         | 
| 84 | 
             
                                    crazy_fns[k]["Button"] = gr.Button(k, variant=variant)
         | 
| 85 | 
             
                                    crazy_fns[k]["Button"].style(size="sm")
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 86 | 
             
                            with gr.Row():
         | 
| 87 | 
             
                                with gr.Accordion("更多函数插件", open=True):
         | 
| 88 | 
             
                                    dropdown_fn_list = [k for k in crazy_fns.keys() if not crazy_fns[k].get("AsButton", True)]
         | 
|  | |
| 89 | 
             
                                    with gr.Column(scale=1):
         | 
| 90 | 
             
                                        dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="").style(container=False)
         | 
| 91 | 
             
                                    with gr.Column(scale=1):
         | 
| @@ -118,7 +132,8 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled= | |
| 118 | 
             
                    return ret
         | 
| 119 | 
             
                checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2] )
         | 
| 120 | 
             
                # 整理反复出现的控件句柄组合
         | 
| 121 | 
            -
                 | 
|  | |
| 122 | 
             
                output_combo = [cookies, chatbot, history, status]
         | 
| 123 | 
             
                predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=input_combo, outputs=output_combo)
         | 
| 124 | 
             
                # 提交按钮、重置按钮
         | 
| @@ -140,6 +155,10 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled= | |
| 140 | 
             
                    click_handle = crazy_fns[k]["Button"].click(ArgsGeneralWrapper(crazy_fns[k]["Function"]), [*input_combo, gr.State(PORT)], output_combo)
         | 
| 141 | 
             
                    click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
         | 
| 142 | 
             
                    cancel_handles.append(click_handle)
         | 
|  | |
|  | |
|  | |
|  | |
| 143 | 
             
                # 函数插件-下拉菜单与随变按钮的互动
         | 
| 144 | 
             
                def on_dropdown_changed(k):
         | 
| 145 | 
             
                    variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary"
         | 
| @@ -147,7 +166,7 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled= | |
| 147 | 
             
                dropdown.select(on_dropdown_changed, [dropdown], [switchy_bt] )
         | 
| 148 | 
             
                # 随变按钮的回调函数注册
         | 
| 149 | 
             
                def route(k, *args, **kwargs):
         | 
| 150 | 
            -
                    if k in [r"打开插件列表", r"请先从插件列表中选择"]: return | 
| 151 | 
             
                    yield from ArgsGeneralWrapper(crazy_fns[k]["Function"])(*args, **kwargs)
         | 
| 152 | 
             
                click_handle = switchy_bt.click(route,[switchy_bt, *input_combo, gr.State(PORT)], output_combo)
         | 
| 153 | 
             
                click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
         | 
| @@ -164,7 +183,7 @@ def auto_opentab_delay(): | |
| 164 | 
             
                print(f"如果浏览器没有自动打开,请复制并转到以下URL:")
         | 
| 165 | 
             
                print(f"\t(亮色主题): http://localhost:{PORT}")
         | 
| 166 | 
             
                print(f"\t(暗色主题): http://localhost:{PORT}/?__dark-theme=true")
         | 
| 167 | 
            -
                def open(): | 
| 168 | 
             
                    time.sleep(2)       # 打开浏览器
         | 
| 169 | 
             
                    webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true")
         | 
| 170 | 
             
                threading.Thread(target=open, name="open-browser", daemon=True).start()
         | 
|  | |
| 44 |  | 
| 45 | 
             
            gr_L1 = lambda: gr.Row().style()
         | 
| 46 | 
             
            gr_L2 = lambda scale: gr.Column(scale=scale)
         | 
| 47 | 
            +
            if LAYOUT == "TOP-DOWN":
         | 
| 48 | 
             
                gr_L1 = lambda: DummyWith()
         | 
| 49 | 
             
                gr_L2 = lambda scale: gr.Row()
         | 
| 50 | 
             
                CHATBOT_HEIGHT /= 2
         | 
|  | |
| 83 | 
             
                                    variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary"
         | 
| 84 | 
             
                                    crazy_fns[k]["Button"] = gr.Button(k, variant=variant)
         | 
| 85 | 
             
                                    crazy_fns[k]["Button"].style(size="sm")
         | 
| 86 | 
            +
                            with gr.Row():
         | 
| 87 | 
            +
                                with gr.Accordion("解析任意code项目", open=True):
         | 
| 88 | 
            +
                                    gr.Markdown("输入的文件后缀用空格或逗号隔开, 可混合使用空格逗号")
         | 
| 89 | 
            +
                                    with gr.Row():
         | 
| 90 | 
            +
                                        gr.Markdown("将要匹配文件的后缀, 不输入则代表解析所有文件")
         | 
| 91 | 
            +
                                        txt_pattern_include = gr.Textbox(show_label=False, placeholder="例如: .c .cpp .py").style(container=False)
         | 
| 92 | 
            +
                                    with gr.Row():
         | 
| 93 | 
            +
                                        gr.Markdown("将要忽略匹配文件的后缀")
         | 
| 94 | 
            +
                                        txt_pattern_except = gr.Textbox(show_label=False, placeholder="例如: .png, .jpg wav flac").style(container=False)
         | 
| 95 | 
            +
                                    code_plugin_name = "解析任意code项目"
         | 
| 96 | 
            +
                                    variant = crazy_fns[code_plugin_name]["Color"] if "Color" in crazy_fns[code_plugin_name] else "secondary"
         | 
| 97 | 
            +
                                    crazy_fns[code_plugin_name]["Button"] = gr.Button(code_plugin_name, variant=variant)
         | 
| 98 | 
            +
                                    crazy_fns[code_plugin_name]["Button"].style(size="sm")
         | 
| 99 | 
             
                            with gr.Row():
         | 
| 100 | 
             
                                with gr.Accordion("更多函数插件", open=True):
         | 
| 101 | 
             
                                    dropdown_fn_list = [k for k in crazy_fns.keys() if not crazy_fns[k].get("AsButton", True)]
         | 
| 102 | 
            +
                                    dropdown_fn_list.remove(code_plugin_name)
         | 
| 103 | 
             
                                    with gr.Column(scale=1):
         | 
| 104 | 
             
                                        dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="").style(container=False)
         | 
| 105 | 
             
                                    with gr.Column(scale=1):
         | 
|  | |
| 132 | 
             
                    return ret
         | 
| 133 | 
             
                checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2] )
         | 
| 134 | 
             
                # 整理反复出现的控件句柄组合
         | 
| 135 | 
            +
                add_input_combo = (txt_pattern_include, txt_pattern_except)
         | 
| 136 | 
            +
                input_combo = [cookies, txt, txt2, top_p, temperature, chatbot, history, system_prompt, *add_input_combo]
         | 
| 137 | 
             
                output_combo = [cookies, chatbot, history, status]
         | 
| 138 | 
             
                predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=input_combo, outputs=output_combo)
         | 
| 139 | 
             
                # 提交按钮、重置按钮
         | 
|  | |
| 155 | 
             
                    click_handle = crazy_fns[k]["Button"].click(ArgsGeneralWrapper(crazy_fns[k]["Function"]), [*input_combo, gr.State(PORT)], output_combo)
         | 
| 156 | 
             
                    click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
         | 
| 157 | 
             
                    cancel_handles.append(click_handle)
         | 
| 158 | 
            +
                # 函数插件-解析任意code项目
         | 
| 159 | 
            +
                click_handle = crazy_fns[code_plugin_name]["Button"].click(ArgsGeneralWrapper(crazy_fns[code_plugin_name]["Function"]), [*input_combo, gr.State(PORT)], output_combo)
         | 
| 160 | 
            +
                click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
         | 
| 161 | 
            +
                cancel_handles.append(click_handle)
         | 
| 162 | 
             
                # 函数插件-下拉菜单与随变按钮的互动
         | 
| 163 | 
             
                def on_dropdown_changed(k):
         | 
| 164 | 
             
                    variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary"
         | 
|  | |
| 166 | 
             
                dropdown.select(on_dropdown_changed, [dropdown], [switchy_bt] )
         | 
| 167 | 
             
                # 随变按钮的回调函数注册
         | 
| 168 | 
             
                def route(k, *args, **kwargs):
         | 
| 169 | 
            +
                    if k in [r"打开插件列表", r"请先从插件列表中选择"]: return
         | 
| 170 | 
             
                    yield from ArgsGeneralWrapper(crazy_fns[k]["Function"])(*args, **kwargs)
         | 
| 171 | 
             
                click_handle = switchy_bt.click(route,[switchy_bt, *input_combo, gr.State(PORT)], output_combo)
         | 
| 172 | 
             
                click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
         | 
|  | |
| 183 | 
             
                print(f"如果浏览器没有自动打开,请复制并转到以下URL:")
         | 
| 184 | 
             
                print(f"\t(亮色主题): http://localhost:{PORT}")
         | 
| 185 | 
             
                print(f"\t(暗色主题): http://localhost:{PORT}/?__dark-theme=true")
         | 
| 186 | 
            +
                def open():
         | 
| 187 | 
             
                    time.sleep(2)       # 打开浏览器
         | 
| 188 | 
             
                    webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true")
         | 
| 189 | 
             
                threading.Thread(target=open, name="open-browser", daemon=True).start()
         | 
    	
        toolbox.py
    CHANGED
    
    | @@ -27,23 +27,24 @@ def ArgsGeneralWrapper(f): | |
| 27 | 
             
                """
         | 
| 28 | 
             
                    装饰器函数,用于重组输入参数,改变输入参数的顺序与结构。
         | 
| 29 | 
             
                """
         | 
| 30 | 
            -
                def decorated(cookies, txt, txt2, top_p, temperature, chatbot, history, system_prompt, *args):
         | 
| 31 | 
             
                    txt_passon = txt
         | 
| 32 | 
             
                    if txt == "" and txt2 != "": txt_passon = txt2
         | 
| 33 | 
             
                    # 引入一个有cookie的chatbot
         | 
| 34 | 
             
                    cookies.update({
         | 
| 35 | 
            -
                        'top_p':top_p, | 
| 36 | 
             
                        'temperature':temperature,
         | 
| 37 | 
             
                    })
         | 
| 38 | 
             
                    llm_kwargs = {
         | 
| 39 | 
             
                        'api_key': cookies['api_key'],
         | 
| 40 | 
             
                        'llm_model': cookies['llm_model'],
         | 
| 41 | 
            -
                        'top_p':top_p, | 
| 42 | 
             
                        'temperature':temperature,
         | 
| 43 | 
             
                    }
         | 
| 44 | 
            -
                    plugin_kwargs = {
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                    }
         | 
|  | |
| 47 | 
             
                    chatbot_with_cookie = ChatBotWithCookies(cookies)
         | 
| 48 | 
             
                    chatbot_with_cookie.write_list(chatbot)
         | 
| 49 | 
             
                    yield from f(txt_passon, llm_kwargs, plugin_kwargs, chatbot_with_cookie, history, system_prompt, *args)
         | 
| @@ -279,7 +280,7 @@ def markdown_convertion(txt): | |
| 279 | 
             
                        return content
         | 
| 280 | 
             
                    else:
         | 
| 281 | 
             
                        return tex2mathml_catch_exception(content)
         | 
| 282 | 
            -
             | 
| 283 | 
             
                def markdown_bug_hunt(content):
         | 
| 284 | 
             
                    """
         | 
| 285 | 
             
                    解决一个mdx_math的bug(单$包裹begin命令时多余<script>)
         | 
| @@ -287,7 +288,7 @@ def markdown_convertion(txt): | |
| 287 | 
             
                    content = content.replace('<script type="math/tex">\n<script type="math/tex; mode=display">', '<script type="math/tex; mode=display">')
         | 
| 288 | 
             
                    content = content.replace('</script>\n</script>', '</script>')
         | 
| 289 | 
             
                    return content
         | 
| 290 | 
            -
             | 
| 291 |  | 
| 292 | 
             
                if ('$' in txt) and ('```' not in txt):  # 有$标识的公式符号,且没有代码段```的标识
         | 
| 293 | 
             
                    # convert everything to html format
         | 
| @@ -308,7 +309,7 @@ def markdown_convertion(txt): | |
| 308 | 
             
            def close_up_code_segment_during_stream(gpt_reply):
         | 
| 309 | 
             
                """
         | 
| 310 | 
             
                在gpt输出代码的中途(输出了前面的```,但还没输出完后面的```),补上后面的```
         | 
| 311 | 
            -
             | 
| 312 | 
             
                Args:
         | 
| 313 | 
             
                    gpt_reply (str): GPT模型返回的回复字符串。
         | 
| 314 |  | 
| @@ -518,7 +519,7 @@ class DummyWith(): | |
| 518 | 
             
                它的作用是……额……没用,即在代码结构不变得情况下取代其他的上下文管理器。
         | 
| 519 | 
             
                上下文管理器是一种Python对象,用于与with语句一起使用,
         | 
| 520 | 
             
                以确保一些资源在代码块执行期间得到正确的初始化和清理。
         | 
| 521 | 
            -
                上下文管理器必须实现两个方法,分别为 __enter__()和 __exit__()。 | 
| 522 | 
             
                在上下文执行开始的情况下,__enter__()方法会在代码块被执行前被调用,
         | 
| 523 | 
             
                而在上下文执行结束时,__exit__()方法则会被调用。
         | 
| 524 | 
             
                """
         | 
|  | |
| 27 | 
             
                """
         | 
| 28 | 
             
                    装饰器函数,用于重组输入参数,改变输入参数的顺序与结构。
         | 
| 29 | 
             
                """
         | 
| 30 | 
            +
                def decorated(cookies, txt, txt2, top_p, temperature, chatbot, history, system_prompt, txt_include, txt_except, *args):
         | 
| 31 | 
             
                    txt_passon = txt
         | 
| 32 | 
             
                    if txt == "" and txt2 != "": txt_passon = txt2
         | 
| 33 | 
             
                    # 引入一个有cookie的chatbot
         | 
| 34 | 
             
                    cookies.update({
         | 
| 35 | 
            +
                        'top_p':top_p,
         | 
| 36 | 
             
                        'temperature':temperature,
         | 
| 37 | 
             
                    })
         | 
| 38 | 
             
                    llm_kwargs = {
         | 
| 39 | 
             
                        'api_key': cookies['api_key'],
         | 
| 40 | 
             
                        'llm_model': cookies['llm_model'],
         | 
| 41 | 
            +
                        'top_p':top_p,
         | 
| 42 | 
             
                        'temperature':temperature,
         | 
| 43 | 
             
                    }
         | 
| 44 | 
            +
                    # plugin_kwargs = {
         | 
| 45 | 
            +
                    #     # 目前还没有
         | 
| 46 | 
            +
                    # }
         | 
| 47 | 
            +
                    plugin_kwargs = dict(txt_include = txt_include, txt_except = txt_except)
         | 
| 48 | 
             
                    chatbot_with_cookie = ChatBotWithCookies(cookies)
         | 
| 49 | 
             
                    chatbot_with_cookie.write_list(chatbot)
         | 
| 50 | 
             
                    yield from f(txt_passon, llm_kwargs, plugin_kwargs, chatbot_with_cookie, history, system_prompt, *args)
         | 
|  | |
| 280 | 
             
                        return content
         | 
| 281 | 
             
                    else:
         | 
| 282 | 
             
                        return tex2mathml_catch_exception(content)
         | 
| 283 | 
            +
             | 
| 284 | 
             
                def markdown_bug_hunt(content):
         | 
| 285 | 
             
                    """
         | 
| 286 | 
             
                    解决一个mdx_math的bug(单$包裹begin命令时多余<script>)
         | 
|  | |
| 288 | 
             
                    content = content.replace('<script type="math/tex">\n<script type="math/tex; mode=display">', '<script type="math/tex; mode=display">')
         | 
| 289 | 
             
                    content = content.replace('</script>\n</script>', '</script>')
         | 
| 290 | 
             
                    return content
         | 
| 291 | 
            +
             | 
| 292 |  | 
| 293 | 
             
                if ('$' in txt) and ('```' not in txt):  # 有$标识的公式符号,且没有代码段```的标识
         | 
| 294 | 
             
                    # convert everything to html format
         | 
|  | |
| 309 | 
             
            def close_up_code_segment_during_stream(gpt_reply):
         | 
| 310 | 
             
                """
         | 
| 311 | 
             
                在gpt输出代码的中途(输出了前面的```,但还没输出完后面的```),补上后面的```
         | 
| 312 | 
            +
             | 
| 313 | 
             
                Args:
         | 
| 314 | 
             
                    gpt_reply (str): GPT模型返回的回复字符串。
         | 
| 315 |  | 
|  | |
| 519 | 
             
                它的作用是……额……没用,即在代码结构不变得情况下取代其他的上下文管理器。
         | 
| 520 | 
             
                上下文管理器是一种Python对象,用于与with语句一起使用,
         | 
| 521 | 
             
                以确保一些资源在代码块执行期间得到正确的初始化和清理。
         | 
| 522 | 
            +
                上下文管理器必须实现两个方法,分别为 __enter__()和 __exit__()。
         | 
| 523 | 
             
                在上下文执行开始的情况下,__enter__()方法会在代码块被执行前被调用,
         | 
| 524 | 
             
                而在上下文执行结束时,__exit__()方法则会被调用。
         | 
| 525 | 
             
                """
         |