Function Refector
This commit is contained in:
parent
5eea959103
commit
9a4b56277c
@ -84,7 +84,33 @@ def 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, ch
|
|||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
|
|
||||||
|
|
||||||
|
def get_files_from_everything(txt):
|
||||||
|
import glob, os
|
||||||
|
|
||||||
|
success = True
|
||||||
|
if txt.startswith('http'):
|
||||||
|
# 网络的远程文件
|
||||||
|
txt = txt.replace("https://github.com/", "https://raw.githubusercontent.com/")
|
||||||
|
txt = txt.replace("/blob/", "/")
|
||||||
|
import requests
|
||||||
|
from toolbox import get_conf
|
||||||
|
proxies, = get_conf('proxies')
|
||||||
|
r = requests.get(txt, proxies=proxies)
|
||||||
|
with open('./gpt_log/temp.md', 'wb+') as f: f.write(r.content)
|
||||||
|
project_folder = './gpt_log/'
|
||||||
|
file_manifest = ['./gpt_log/temp.md']
|
||||||
|
elif txt.endswith('.md'):
|
||||||
|
# 直接给定文件
|
||||||
|
file_manifest = [txt]
|
||||||
|
project_folder = os.path.dirname(txt)
|
||||||
|
elif os.path.exists(txt):
|
||||||
|
# 本地路径,递归搜索
|
||||||
|
project_folder = txt
|
||||||
|
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.md', recursive=True)]
|
||||||
|
else:
|
||||||
|
success = False
|
||||||
|
|
||||||
|
return success, file_manifest, project_folder
|
||||||
|
|
||||||
|
|
||||||
@CatchException
|
@CatchException
|
||||||
@ -107,26 +133,9 @@ def Markdown英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
|
|||||||
return
|
return
|
||||||
history = [] # 清空历史,以免输入溢出
|
history = [] # 清空历史,以免输入溢出
|
||||||
|
|
||||||
if txt.startswith('http'):
|
success, file_manifest, project_folder = get_files_from_everything(txt)
|
||||||
# 网络的远程文件
|
|
||||||
txt = txt.replace("https://github.com/", "https://raw.githubusercontent.com/")
|
if not success:
|
||||||
txt = txt.replace("/blob/", "/")
|
|
||||||
import requests
|
|
||||||
from toolbox import get_conf
|
|
||||||
proxies, = get_conf('proxies')
|
|
||||||
r = requests.get(txt, proxies=proxies)
|
|
||||||
with open('./gpt_log/temp.md', 'wb+') as f: f.write(r.content)
|
|
||||||
project_folder = './gpt_log/'
|
|
||||||
file_manifest = ['./gpt_log/temp.md']
|
|
||||||
elif txt.endswith('.md'):
|
|
||||||
# 直接给定文件
|
|
||||||
file_manifest = [txt]
|
|
||||||
project_folder = os.path.dirname(txt)
|
|
||||||
elif os.path.exists(txt):
|
|
||||||
# 本地路径,递归搜索
|
|
||||||
project_folder = txt
|
|
||||||
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.md', recursive=True)]
|
|
||||||
else:
|
|
||||||
# 什么都没有
|
# 什么都没有
|
||||||
if txt == "": txt = '空空如也的输入栏'
|
if txt == "": txt = '空空如也的输入栏'
|
||||||
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user