Markdown翻译支持github url
This commit is contained in:
parent
856df8fb62
commit
5eea959103
@ -21,6 +21,7 @@ def get_crazy_functions():
|
|||||||
from crazy_functions.总结word文档 import 总结word文档
|
from crazy_functions.总结word文档 import 总结word文档
|
||||||
from crazy_functions.解析JupyterNotebook import 解析ipynb文件
|
from crazy_functions.解析JupyterNotebook import 解析ipynb文件
|
||||||
from crazy_functions.对话历史存档 import 对话历史存档
|
from crazy_functions.对话历史存档 import 对话历史存档
|
||||||
|
from crazy_functions.批量Markdown翻译 import Markdown英译中
|
||||||
function_plugins = {
|
function_plugins = {
|
||||||
|
|
||||||
"解析整个Python项目": {
|
"解析整个Python项目": {
|
||||||
@ -81,8 +82,14 @@ def get_crazy_functions():
|
|||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
"Function": HotReload(读文章写摘要)
|
"Function": HotReload(读文章写摘要)
|
||||||
},
|
},
|
||||||
|
"Markdown/Readme英译中": {
|
||||||
|
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
||||||
|
"Color": "stop",
|
||||||
|
"Function": HotReload(Markdown英译中)
|
||||||
|
},
|
||||||
"批量生成函数注释": {
|
"批量生成函数注释": {
|
||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
|
"AsButton": False, # 加入下拉菜单中
|
||||||
"Function": HotReload(批量生成函数注释)
|
"Function": HotReload(批量生成函数注释)
|
||||||
},
|
},
|
||||||
"[多线程Demo] 解析此项目本身(源码自译解)": {
|
"[多线程Demo] 解析此项目本身(源码自译解)": {
|
||||||
@ -110,7 +117,6 @@ def get_crazy_functions():
|
|||||||
from crazy_functions.Latex全文翻译 import Latex中译英
|
from crazy_functions.Latex全文翻译 import Latex中译英
|
||||||
from crazy_functions.Latex全文翻译 import Latex英译中
|
from crazy_functions.Latex全文翻译 import Latex英译中
|
||||||
from crazy_functions.批量Markdown翻译 import Markdown中译英
|
from crazy_functions.批量Markdown翻译 import Markdown中译英
|
||||||
from crazy_functions.批量Markdown翻译 import Markdown英译中
|
|
||||||
|
|
||||||
function_plugins.update({
|
function_plugins.update({
|
||||||
"批量翻译PDF文档(多线程)": {
|
"批量翻译PDF文档(多线程)": {
|
||||||
@ -175,12 +181,7 @@ def get_crazy_functions():
|
|||||||
"AsButton": False, # 加入下拉菜单中
|
"AsButton": False, # 加入下拉菜单中
|
||||||
"Function": HotReload(Markdown中译英)
|
"Function": HotReload(Markdown中译英)
|
||||||
},
|
},
|
||||||
"[测试功能] 批量Markdown英译中(输入路径或上传压缩包)": {
|
|
||||||
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
|
||||||
"Color": "stop",
|
|
||||||
"AsButton": False, # 加入下拉菜单中
|
|
||||||
"Function": HotReload(Markdown英译中)
|
|
||||||
},
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ def Markdown英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
|
|||||||
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
||||||
try:
|
try:
|
||||||
import tiktoken
|
import tiktoken
|
||||||
|
import glob, os
|
||||||
except:
|
except:
|
||||||
report_execption(chatbot, history,
|
report_execption(chatbot, history,
|
||||||
a=f"解析项目: {txt}",
|
a=f"解析项目: {txt}",
|
||||||
@ -105,19 +106,38 @@ def Markdown英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
|
|||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
return
|
return
|
||||||
history = [] # 清空历史,以免输入溢出
|
history = [] # 清空历史,以免输入溢出
|
||||||
import glob, os
|
|
||||||
if os.path.exists(txt):
|
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
|
project_folder = txt
|
||||||
|
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.md', recursive=True)]
|
||||||
else:
|
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}")
|
||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
return
|
return
|
||||||
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.md', recursive=True)]
|
|
||||||
if len(file_manifest) == 0:
|
if len(file_manifest) == 0:
|
||||||
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}")
|
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}")
|
||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
return
|
return
|
||||||
|
|
||||||
yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en->zh')
|
yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en->zh')
|
||||||
|
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
|
|||||||
for response in newbing_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
|
for response in newbing_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
|
||||||
chatbot[-1] = (inputs, preprocess_newbing_out(response))
|
chatbot[-1] = (inputs, preprocess_newbing_out(response))
|
||||||
yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢,尚未完成全部响应,请耐心完成后再提交新问题。")
|
yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢,尚未完成全部响应,请耐心完成后再提交新问题。")
|
||||||
|
if response == "[Local Message]: 等待NewBing响应中 ...": response = "[Local Message]: NewBing响应异常,请刷新界面重试 ..."
|
||||||
history.extend([inputs, response])
|
history.extend([inputs, response])
|
||||||
yield from update_ui(chatbot=chatbot, history=history, msg="完成全部响应,请提交新问题。")
|
yield from update_ui(chatbot=chatbot, history=history, msg="完成全部响应,请提交新问题。")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user