diff --git a/crazy_functions/SourceCode_Analyse.py b/crazy_functions/SourceCode_Analyse.py index 53814df2..ea071ed3 100644 --- a/crazy_functions/SourceCode_Analyse.py +++ b/crazy_functions/SourceCode_Analyse.py @@ -23,7 +23,7 @@ def 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, file_content = f.read() prefix = "接下来请你逐文件分析下面的工程" if index==0 else "" i_say = prefix + f'请对下面的程序文件做一个概述文件名是{os.path.relpath(fp, project_folder)},文件代码是 ```{file_content}```' - i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {fp}' + i_say_show_user = prefix + f'[{index+1}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {fp}' # 装载请求内容 inputs_array.append(i_say) inputs_show_user_array.append(i_say_show_user) diff --git a/crazy_functions/SourceCode_Comment.py b/crazy_functions/SourceCode_Comment.py index b0d9378b..e61f14d5 100644 --- a/crazy_functions/SourceCode_Comment.py +++ b/crazy_functions/SourceCode_Comment.py @@ -6,6 +6,7 @@ from crazy_functions.crazy_utils import request_gpt_model_multi_threads_with_ver from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from crazy_functions.agent_fns.python_comment_agent import PythonCodeComment from crazy_functions.diagram_fns.file_tree import FileNode +from shared_utils.advanced_markdown_format import markdown_convertion_for_file def 注释源代码(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt): @@ -29,7 +30,7 @@ def 注释源代码(file_manifest, project_folder, llm_kwargs, plugin_kwargs, ch file_content = f.read() prefix = "" i_say = prefix + f'Please conclude the following source code at {os.path.relpath(fp, project_folder)} with only one sentence, the code is:\n```{file_content}```' - i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请用一句话对下面的程序文件做一个整体概述: {fp}' + i_say_show_user = prefix + f'[{index+1}/{len(file_manifest)}] 请用一句话对下面的程序文件做一个整体概述: {fp}' # 装载请求内容 MAX_TOKEN_SINGLE_FILE = 2560 i_say, _ = input_clipping(inputs=i_say, history=[], max_token_limit=MAX_TOKEN_SINGLE_FILE) @@ -63,13 +64,16 @@ def 注释源代码(file_manifest, project_folder, llm_kwargs, plugin_kwargs, ch # <生成对比html> with open("crazy_functions/agent_fns/python_comment_compare.html", 'r', encoding='utf-8') as f: html_template = f.read() - html_template = html_template.replace("REPLACE_CODE_FILE_LEFT", pcc.original_content) - html_template = html_template.replace("REPLACE_CODE_FILE_RIGHT", revised_content) + warp = lambda x: "```python\n\n" + x + "\n\n```" + from themes.theme import advanced_css + html_template = html_template.replace("ADVANCED_CSS", advanced_css) + html_template = html_template.replace("REPLACE_CODE_FILE_LEFT", pcc.get_markdown_block_in_html(markdown_convertion_for_file(warp(pcc.original_content)))) + html_template = html_template.replace("REPLACE_CODE_FILE_RIGHT", pcc.get_markdown_block_in_html(markdown_convertion_for_file(warp(revised_content)))) compare_html_path = fp + '.compare.html' file_tree_struct.manifest[fp].compare_html = compare_html_path with open(compare_html_path, 'w', encoding='utf-8') as f: f.write(html_template) - + print('done 1') chatbot.append([None, f"正在处理:"]) futures = [] diff --git a/crazy_functions/agent_fns/python_comment_agent.py b/crazy_functions/agent_fns/python_comment_agent.py index 9a394a57..66fa5c38 100644 --- a/crazy_functions/agent_fns/python_comment_agent.py +++ b/crazy_functions/agent_fns/python_comment_agent.py @@ -285,6 +285,17 @@ class PythonCodeComment(): return code_block else: return code + + def get_markdown_block_in_html(self, html): + from bs4 import BeautifulSoup + soup = BeautifulSoup(html, 'lxml') + found_list = soup.find_all("div", class_="markdown-body") + if found_list: + res = found_list[0] + return res.prettify() + else: + return None + def sync_and_patch(self, original, revised): """Ensure the number of pre-string empty lines in revised matches those in original.""" diff --git a/crazy_functions/agent_fns/python_comment_compare.html b/crazy_functions/agent_fns/python_comment_compare.html index d5ca926e..047d9c0e 100644 --- a/crazy_functions/agent_fns/python_comment_compare.html +++ b/crazy_functions/agent_fns/python_comment_compare.html @@ -1,6 +1,7 @@
+