镜像自地址
https://github.com/binary-husky/gpt_academic.git
已同步 2025-12-06 22:46:48 +00:00
up
这个提交包含在:
@@ -112,6 +112,7 @@ def get_crazy_functions():
|
|||||||
"Group": "学术",
|
"Group": "学术",
|
||||||
"Color": "stop",
|
"Color": "stop",
|
||||||
"AsButton": False,
|
"AsButton": False,
|
||||||
|
"AdvancedArgs": True,
|
||||||
"Info": "批量总结word文档 | 输入参数为路径",
|
"Info": "批量总结word文档 | 输入参数为路径",
|
||||||
"Function": HotReload(总结文件),
|
"Function": HotReload(总结文件),
|
||||||
},
|
},
|
||||||
@@ -347,18 +348,6 @@ def get_crazy_functions():
|
|||||||
"Function": HotReload(Latex翻译中文并重新编译PDF), # 当注册Class后,Function旧接口仅会在“虚空终端”中起作用
|
"Function": HotReload(Latex翻译中文并重新编译PDF), # 当注册Class后,Function旧接口仅会在“虚空终端”中起作用
|
||||||
"Class": Arxiv_Localize, # 新一代插件需要注册Class
|
"Class": Arxiv_Localize, # 新一代插件需要注册Class
|
||||||
},
|
},
|
||||||
"📚Arxiv论文交互对话(输入arxivID)": {
|
|
||||||
"Group": "学术",
|
|
||||||
"Color": "stop",
|
|
||||||
"AsButton": False,
|
|
||||||
"AdvancedArgs": True,
|
|
||||||
"ArgsReminder": r"如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 "
|
|
||||||
r"例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: "
|
|
||||||
r'If the term "agent" is used in this section, it should be translated to "智能体". ',
|
|
||||||
"Info": "Arixv论文精细翻译 | 输入参数arxiv论文的ID,比如1812.10695",
|
|
||||||
"Function": HotReload(Arxiv_论文对话), # 当注册Class后,Function旧接口仅会在“虚空终端”中起作用
|
|
||||||
"Class": Arxiv_Localize, # 新一代插件需要注册Class
|
|
||||||
},
|
|
||||||
"📚本地Latex论文精细翻译(上传Latex项目)[需Latex]": {
|
"📚本地Latex论文精细翻译(上传Latex项目)[需Latex]": {
|
||||||
"Group": "学术",
|
"Group": "学术",
|
||||||
"Color": "stop",
|
"Color": "stop",
|
||||||
|
|||||||
@@ -1,22 +1,56 @@
|
|||||||
import os
|
import os
|
||||||
from llama_index.core import SimpleDirectoryReader
|
from llama_index.core import SimpleDirectoryReader
|
||||||
|
|
||||||
supports_format = ['.csv', '.docx', '.epub', '.ipynb', '.mbox', '.md', '.pdf', '.txt', '.ppt',
|
supports_format = ['.csv', '.docx','.doc', '.epub', '.ipynb', '.mbox', '.md', '.pdf', '.txt', '.ppt',
|
||||||
'.pptm', '.pptx']
|
'.pptm', '.pptx','.py', '.xls', '.xlsx', '.html', '.json', '.xml', '.yaml', '.yml' ,'.m']
|
||||||
|
|
||||||
|
def read_docx_doc(file_path):
|
||||||
|
if file_path.split(".")[-1] == "docx":
|
||||||
|
from docx import Document
|
||||||
|
doc = Document(file_path)
|
||||||
|
file_content = "\n".join([para.text for para in doc.paragraphs])
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
import win32com.client
|
||||||
|
word = win32com.client.Dispatch("Word.Application")
|
||||||
|
word.visible = False
|
||||||
|
# 打开文件
|
||||||
|
doc = word.Documents.Open(os.getcwd() + '/' + file_path)
|
||||||
|
# file_content = doc.Content.Text
|
||||||
|
doc = word.ActiveDocument
|
||||||
|
file_content = doc.Range().Text
|
||||||
|
doc.Close()
|
||||||
|
word.Quit()
|
||||||
|
except:
|
||||||
|
raise RuntimeError('请先将.doc文档转换为.docx文档。')
|
||||||
|
return file_content
|
||||||
|
|
||||||
# 修改后的 extract_text 函数,结合 SimpleDirectoryReader 和自定义解析逻辑
|
# 修改后的 extract_text 函数,结合 SimpleDirectoryReader 和自定义解析逻辑
|
||||||
|
import os
|
||||||
|
|
||||||
def extract_text(file_path):
|
def extract_text(file_path):
|
||||||
_, ext = os.path.splitext(file_path.lower())
|
_, ext = os.path.splitext(file_path.lower())
|
||||||
|
|
||||||
# 使用 SimpleDirectoryReader 处理它支持的文件格式
|
# 使用 SimpleDirectoryReader 处理它支持的文件格式
|
||||||
if ext in supports_format:
|
if ext in ['.docx', '.doc']:
|
||||||
|
return read_docx_doc(file_path)
|
||||||
|
else:
|
||||||
|
# 尝试读取文件为纯文本
|
||||||
try:
|
try:
|
||||||
reader = SimpleDirectoryReader(input_files=[file_path])
|
with open(file_path, 'r', encoding='utf-8') as f:
|
||||||
documents = reader.load_data()
|
return f.read()
|
||||||
if len(documents) > 0:
|
except UnicodeDecodeError:
|
||||||
return documents[0].text
|
# 如果遇到解码错误,说明文件不是纯文本
|
||||||
|
print(f"Error: {file_path} is not a valid text file.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
# 捕获其他可能的异常
|
||||||
|
print(f"Error reading file {file_path}: {e}")
|
||||||
|
try:
|
||||||
|
reader = SimpleDirectoryReader(input_files=[file_path])
|
||||||
|
documents = reader.load_data()
|
||||||
|
if len(documents) > 0:
|
||||||
|
return documents[0].text
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ def 文档总结(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatb
|
|||||||
for index, fp in enumerate(file_manifest):
|
for index, fp in enumerate(file_manifest):
|
||||||
file_content = extract_text(fp)
|
file_content = extract_text(fp)
|
||||||
# private_upload里面的文件名在解压zip后容易出现乱码(rar和7z格式正常),故可以只分析文章内容,不输入文件名
|
# private_upload里面的文件名在解压zip后容易出现乱码(rar和7z格式正常),故可以只分析文章内容,不输入文件名
|
||||||
|
if file_content==None:
|
||||||
|
continue
|
||||||
from crazy_functions.pdf_fns.breakdown_txt import breakdown_text_to_satisfy_token_limit
|
from crazy_functions.pdf_fns.breakdown_txt import breakdown_text_to_satisfy_token_limit
|
||||||
from request_llms.bridge_all import model_info
|
from request_llms.bridge_all import model_info
|
||||||
max_token = model_info[llm_kwargs['llm_model']]['max_token']
|
max_token = model_info[llm_kwargs['llm_model']]['max_token']
|
||||||
@@ -21,8 +23,8 @@ def 文档总结(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatb
|
|||||||
paper_fragments = breakdown_text_to_satisfy_token_limit(txt=file_content, limit=TOKEN_LIMIT_PER_FRAGMENT, llm_model=llm_kwargs['llm_model'])
|
paper_fragments = breakdown_text_to_satisfy_token_limit(txt=file_content, limit=TOKEN_LIMIT_PER_FRAGMENT, llm_model=llm_kwargs['llm_model'])
|
||||||
this_paper_history = []
|
this_paper_history = []
|
||||||
for i, paper_frag in enumerate(paper_fragments):
|
for i, paper_frag in enumerate(paper_fragments):
|
||||||
i_say = f'请对下面的内容用中文做概述,文件名是{os.path.relpath(fp, project_folder)},内容是 ```{paper_frag}```'
|
i_say = f'请对下面的内容用中文做概述,文件名是{os.path.relpath(fp, project_folder)},做概述时请注意以下要求:{plugin_kwargs['advanced_arg']}:内容是 ```{paper_frag}```'
|
||||||
i_say_show_user = f'请对下面的内容片段做概述: {os.path.abspath(fp)}的第{i+1}/{len(paper_fragments)}个片段。'
|
i_say_show_user = f'请对下面的内容片段做概述,做概述时请注意以下要求:{plugin_kwargs['advanced_arg']}: {os.path.abspath(fp)}的第{i+1}/{len(paper_fragments)}个片段。'
|
||||||
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
||||||
inputs=i_say,
|
inputs=i_say,
|
||||||
inputs_show_user=i_say_show_user,
|
inputs_show_user=i_say_show_user,
|
||||||
@@ -38,7 +40,7 @@ def 文档总结(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatb
|
|||||||
|
|
||||||
# 已经对该文章的所有片段总结完毕,如果文章被切分了,
|
# 已经对该文章的所有片段总结完毕,如果文章被切分了,
|
||||||
if len(paper_fragments) > 1:
|
if len(paper_fragments) > 1:
|
||||||
i_say = f"根据以上的对话,总结文件{os.path.abspath(fp)}的主要内容。"
|
i_say = f"根据以上的对话,总结时请注意以下要求:{plugin_kwargs['advanced_arg']},总结文件{os.path.abspath(fp)}的主要内容。"
|
||||||
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
||||||
inputs=i_say,
|
inputs=i_say,
|
||||||
inputs_show_user=i_say,
|
inputs_show_user=i_say,
|
||||||
@@ -67,7 +69,6 @@ def 总结文件(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt
|
|||||||
import glob, os
|
import glob, os
|
||||||
|
|
||||||
# 基本信息:功能、贡献者
|
# 基本信息:功能、贡献者
|
||||||
supports_format = ["pdf", "docx", "txt", "md"] # 假设支持的文件格式
|
|
||||||
chatbot.append([
|
chatbot.append([
|
||||||
"函数插件功能?",
|
"函数插件功能?",
|
||||||
f"批量总结各类文件。函数插件贡献者: JasonGuo1 and BoyinLiu。支持的文件类型包括:{', '.join(supports_format)}。"
|
f"批量总结各类文件。函数插件贡献者: JasonGuo1 and BoyinLiu。支持的文件类型包括:{', '.join(supports_format)}。"
|
||||||
@@ -87,10 +88,8 @@ def 总结文件(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt
|
|||||||
return
|
return
|
||||||
|
|
||||||
# 搜索需要处理的文件清单
|
# 搜索需要处理的文件清单
|
||||||
file_manifest = []
|
|
||||||
|
|
||||||
for ext in supports_format:
|
file_manifest = [f for f in glob.glob(f'{project_folder}/**', recursive=True) if os.path.isfile(f)]
|
||||||
file_manifest += [f for f in glob.glob(f'{project_folder}/**/*{ext}', recursive=True)]
|
|
||||||
|
|
||||||
# 如果没找到任何文件
|
# 如果没找到任何文件
|
||||||
if len(file_manifest) == 0:
|
if len(file_manifest) == 0:
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户