This commit is contained in:
qingxu fu 2023-04-09 19:49:42 +08:00
parent 47445fdc90
commit ea031ab05b
17 changed files with 127 additions and 138 deletions

View File

@ -1,4 +1,4 @@
from request_llm.bridge_chatgpt import predict_no_ui from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
fast_debug = False fast_debug = False
@ -14,26 +14,22 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```' i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}' i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response.")) chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
print('[1] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=history)
yield chatbot, history, '正常'
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
# ** gpt request ** # ** gpt request **
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时 gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
print('[2] end gpt req')
chatbot[-1] = (i_say_show_user, gpt_say) chatbot[-1] = (i_say_show_user, gpt_say)
history.append(i_say_show_user); history.append(gpt_say) history.append(i_say_show_user); history.append(gpt_say)
print('[3] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
yield chatbot, history, msg
print('[4] next')
if not fast_debug: time.sleep(2) if not fast_debug: time.sleep(2)
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)]) all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。' i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
chatbot.append((i_say, "[Local Message] waiting gpt response.")) chatbot.append((i_say, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
@ -42,10 +38,10 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
chatbot[-1] = (i_say, gpt_say) chatbot[-1] = (i_say, gpt_say)
history.append(i_say); history.append(gpt_say) history.append(i_say); history.append(gpt_say)
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("完成了吗?", res)) chatbot.append(("完成了吗?", res))
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
@ -58,13 +54,13 @@ def 读文章写摘要(txt, top_p, temperature, chatbot, history, systemPromptTx
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \ # [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] # [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)

View File

@ -118,8 +118,7 @@ def request_gpt_model_in_new_thread_with_ui_alive(
if future.done(): if future.done():
break break
chatbot[-1] = [chatbot[-1][0], mutable[0]] chatbot[-1] = [chatbot[-1][0], mutable[0]]
msg = "正常" yield from update_ui(chatbot=chatbot, history=[])
yield chatbot, [], msg
return future.result() return future.result()
@ -168,7 +167,7 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
# 用户反馈 # 用户反馈
chatbot.append(["请开始多线程操作。", ""]) chatbot.append(["请开始多线程操作。", ""])
msg = '正常' msg = '正常'
yield chatbot, [], msg yield from update_ui(chatbot=chatbot, history=[])
# 异步原子 # 异步原子
mutable = [["", time.time(), "等待中"] for _ in range(n_frag)] mutable = [["", time.time(), "等待中"] for _ in range(n_frag)]
@ -254,7 +253,7 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
for thread_index, done, obs in zip(range(len(worker_done)), worker_done, observe_win)]) for thread_index, done, obs in zip(range(len(worker_done)), worker_done, observe_win)])
chatbot[-1] = [chatbot[-1][0], f'多线程操作已经开始,完成情况: \n\n{stat_str}' + ''.join(['.']*(cnt % 10+1))] chatbot[-1] = [chatbot[-1][0], f'多线程操作已经开始,完成情况: \n\n{stat_str}' + ''.join(['.']*(cnt % 10+1))]
msg = "正常" msg = "正常"
yield chatbot, [], msg yield from update_ui(chatbot=chatbot, history=[])
# 异步任务结束 # 异步任务结束
gpt_response_collection = [] gpt_response_collection = []
for inputs_show_user, f in zip(inputs_show_user_array, futures): for inputs_show_user, f in zip(inputs_show_user_array, futures):
@ -265,7 +264,7 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
for inputs_show_user, f in zip(inputs_show_user_array, futures): for inputs_show_user, f in zip(inputs_show_user_array, futures):
gpt_res = f.result() gpt_res = f.result()
chatbot.append([inputs_show_user, gpt_res]) chatbot.append([inputs_show_user, gpt_res])
yield chatbot, [], msg yield from update_ui(chatbot=chatbot, history=[])
time.sleep(1) time.sleep(1)
return gpt_response_collection return gpt_response_collection

View File

@ -1,3 +1,4 @@
from toolbox import update_ui
from request_llm.bridge_chatgpt import predict_no_ui from request_llm.bridge_chatgpt import predict_no_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down, get_conf from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down, get_conf
import re, requests, unicodedata, os import re, requests, unicodedata, os
@ -140,7 +141,7 @@ def 下载arxiv论文并翻译摘要(txt, top_p, temperature, chatbot, history,
# 基本信息:功能、贡献者 # 基本信息:功能、贡献者
chatbot.append(["函数插件功能?", CRAZY_FUNCTION_INFO]) chatbot.append(["函数插件功能?", CRAZY_FUNCTION_INFO])
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 尝试导入依赖,如果缺少依赖,则给出安装建议 # 尝试导入依赖,如果缺少依赖,则给出安装建议
try: try:
@ -149,7 +150,7 @@ def 下载arxiv论文并翻译摘要(txt, top_p, temperature, chatbot, history,
report_execption(chatbot, history, report_execption(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 清空历史,以免输入溢出 # 清空历史,以免输入溢出
@ -162,25 +163,25 @@ def 下载arxiv论文并翻译摘要(txt, top_p, temperature, chatbot, history,
report_execption(chatbot, history, report_execption(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"下载pdf文件未成功") b = f"下载pdf文件未成功")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 翻译摘要等 # 翻译摘要等
i_say = f"请你阅读以下学术论文相关的材料,提取摘要,翻译为中文。材料如下:{str(info)}" i_say = f"请你阅读以下学术论文相关的材料,提取摘要,翻译为中文。材料如下:{str(info)}"
i_say_show_user = f'请你阅读以下学术论文相关的材料,提取摘要,翻译为中文。论文:{pdf_path}' i_say_show_user = f'请你阅读以下学术论文相关的材料,提取摘要,翻译为中文。论文:{pdf_path}'
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response.")) chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
msg = '正常' msg = '正常'
# ** gpt request ** # ** gpt request **
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时 gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
chatbot[-1] = (i_say_show_user, gpt_say) chatbot[-1] = (i_say_show_user, gpt_say)
history.append(i_say_show_user); history.append(gpt_say) history.append(i_say_show_user); history.append(gpt_say)
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
# 写入文件 # 写入文件
import shutil import shutil
# 重置文件的创建时间 # 重置文件的创建时间
shutil.copyfile(pdf_path, f'./gpt_log/{os.path.basename(pdf_path)}'); os.remove(pdf_path) shutil.copyfile(pdf_path, f'./gpt_log/{os.path.basename(pdf_path)}'); os.remove(pdf_path)
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("完成了吗?", res + "\n\nPDF文件也已经下载")) chatbot.append(("完成了吗?", res + "\n\nPDF文件也已经下载"))
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)

View File

@ -1,5 +1,6 @@
import threading import threading
from request_llm.bridge_chatgpt import predict_no_ui_long_connection from request_llm.bridge_chatgpt import predict_no_ui_long_connection
from toolbox import update_ui
from toolbox import CatchException, write_results_to_file, report_execption from toolbox import CatchException, write_results_to_file, report_execption
from .crazy_utils import breakdown_txt_to_satisfy_token_limit from .crazy_utils import breakdown_txt_to_satisfy_token_limit
@ -33,7 +34,7 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
report_execption(chatbot, history, report_execption(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade openai transformers```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade openai transformers```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 第3步集合文件 # 第3步集合文件
@ -53,7 +54,7 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
i_say_show_user =f'[{index}/{len(file_manifest)}] 接下来请将以下代码中包含的所有中文转化为英文,只输出转化后的英文代码,请用代码块输出代码: {os.path.abspath(fp)}' i_say_show_user =f'[{index}/{len(file_manifest)}] 接下来请将以下代码中包含的所有中文转化为英文,只输出转化后的英文代码,请用代码块输出代码: {os.path.abspath(fp)}'
i_say_show_user_buffer.append(i_say_show_user) i_say_show_user_buffer.append(i_say_show_user)
chatbot.append((i_say_show_user, "[Local Message] 等待多线程操作,中间过程不予显示.")) chatbot.append((i_say_show_user, "[Local Message] 等待多线程操作,中间过程不予显示."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 第5步Token限制下的截断与处理 # 第5步Token限制下的截断与处理
@ -96,7 +97,7 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
h.daemon = True h.daemon = True
h.start() h.start()
chatbot.append(('开始了吗?', f'多线程操作已经开始')) chatbot.append(('开始了吗?', f'多线程操作已经开始'))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 第8步循环轮询各个线程是否执行完毕 # 第8步循环轮询各个线程是否执行完毕
cnt = 0 cnt = 0
@ -112,7 +113,7 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
stat = [f'执行中: {obs}\n\n' if alive else '已完成\n\n' for alive, obs in zip(th_alive, observe_win)] stat = [f'执行中: {obs}\n\n' if alive else '已完成\n\n' for alive, obs in zip(th_alive, observe_win)]
stat_str = ''.join(stat) stat_str = ''.join(stat)
chatbot[-1] = (chatbot[-1][0], f'多线程操作已经开始,完成情况: \n\n{stat_str}' + ''.join(['.']*(cnt%10+1))) chatbot[-1] = (chatbot[-1][0], f'多线程操作已经开始,完成情况: \n\n{stat_str}' + ''.join(['.']*(cnt%10+1)))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 第9步把结果写入文件 # 第9步把结果写入文件
for index, h in enumerate(handles): for index, h in enumerate(handles):
@ -129,10 +130,10 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
shutil.copyfile(file_manifest[index], where_to_relocate) shutil.copyfile(file_manifest[index], where_to_relocate)
chatbot.append((i_say_show_user, f'[Local Message] 已完成{os.path.abspath(fp)}的转化,\n\n存入{os.path.abspath(where_to_relocate)}')) chatbot.append((i_say_show_user, f'[Local Message] 已完成{os.path.abspath(fp)}的转化,\n\n存入{os.path.abspath(where_to_relocate)}'))
history.append(i_say_show_user); history.append(gpt_say) history.append(i_say_show_user); history.append(gpt_say)
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
time.sleep(1) time.sleep(1)
# 第10步备份一个文件 # 第10步备份一个文件
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("生成一份任务执行报告", res)) chatbot.append(("生成一份任务执行报告", res))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)

View File

@ -1,4 +1,5 @@
from request_llm.bridge_chatgpt import predict_no_ui from request_llm.bridge_chatgpt import predict_no_ui
from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
fast_debug = False fast_debug = False
@ -35,7 +36,7 @@ def 解析docx(file_manifest, project_folder, top_p, temperature, chatbot, histo
f'文章内容是 ```{file_content}```' f'文章内容是 ```{file_content}```'
i_say_show_user = prefix + f'[{index+1}/{len(file_manifest)}] 假设你是论文审稿专家,请对下面的文章片段做概述: {os.path.abspath(fp)}' i_say_show_user = prefix + f'[{index+1}/{len(file_manifest)}] 假设你是论文审稿专家,请对下面的文章片段做概述: {os.path.abspath(fp)}'
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response.")) chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
@ -45,21 +46,21 @@ def 解析docx(file_manifest, project_folder, top_p, temperature, chatbot, histo
chatbot[-1] = (i_say_show_user, gpt_say) chatbot[-1] = (i_say_show_user, gpt_say)
history.append(i_say_show_user); history.append(i_say_show_user);
history.append(gpt_say) history.append(gpt_say)
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
if not fast_debug: time.sleep(2) if not fast_debug: time.sleep(2)
""" """
# 可按需启用 # 可按需启用
i_say = f'根据你上述的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一篇英文的。' i_say = f'根据你上述的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一篇英文的。'
chatbot.append((i_say, "[Local Message] waiting gpt response.")) chatbot.append((i_say, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
i_say = f'我想让你做一个论文写作导师。您的任务是使用人工智能工具(例如自然语言处理)提供有关如何改进其上述文章的反馈。' \ i_say = f'我想让你做一个论文写作导师。您的任务是使用人工智能工具(例如自然语言处理)提供有关如何改进其上述文章的反馈。' \
f'您还应该利用您在有效写作技巧方面的修辞知识和经验来建议作者可以更好地以书面形式表达他们的想法和想法的方法。' \ f'您还应该利用您在有效写作技巧方面的修辞知识和经验来建议作者可以更好地以书面形式表达他们的想法和想法的方法。' \
f'根据你之前的分析,提出建议' f'根据你之前的分析,提出建议'
chatbot.append((i_say, "[Local Message] waiting gpt response.")) chatbot.append((i_say, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
""" """
@ -72,10 +73,10 @@ def 解析docx(file_manifest, project_folder, top_p, temperature, chatbot, histo
chatbot[-1] = (i_say, gpt_say) chatbot[-1] = (i_say, gpt_say)
history.append(i_say) history.append(i_say)
history.append(gpt_say) history.append(gpt_say)
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("完成了吗?", res)) chatbot.append(("完成了吗?", res))
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
@CatchException @CatchException
@ -86,7 +87,7 @@ def 总结word文档(txt, top_p, temperature, chatbot, history, systemPromptTxt,
chatbot.append([ chatbot.append([
"函数插件功能?", "函数插件功能?",
"批量总结Word文档。函数插件贡献者: JasonGuo1"]) "批量总结Word文档。函数插件贡献者: JasonGuo1"])
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 尝试导入依赖,如果缺少依赖,则给出安装建议 # 尝试导入依赖,如果缺少依赖,则给出安装建议
try: try:
@ -95,7 +96,7 @@ def 总结word文档(txt, top_p, temperature, chatbot, history, systemPromptTxt,
report_execption(chatbot, history, report_execption(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade python-docx pywin32```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade python-docx pywin32```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 清空历史,以免输入溢出 # 清空历史,以免输入溢出
@ -107,7 +108,7 @@ def 总结word文档(txt, top_p, temperature, chatbot, history, systemPromptTxt,
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 搜索需要处理的文件清单 # 搜索需要处理的文件清单
@ -120,7 +121,7 @@ def 总结word文档(txt, top_p, temperature, chatbot, history, systemPromptTxt,
# 如果没找到任何文件 # 如果没找到任何文件
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何.docx或doc文件: {txt}") report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何.docx或doc文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 开始正式执行任务 # 开始正式执行任务

View File

@ -1,4 +1,5 @@
from request_llm.bridge_chatgpt import predict_no_ui from request_llm.bridge_chatgpt import predict_no_ui
from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
import re import re
import unicodedata import unicodedata
@ -72,26 +73,22 @@ def 解析PDF(file_manifest, project_folder, top_p, temperature, chatbot, histor
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```' i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}' i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response.")) chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
print('[1] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=history)
yield chatbot, history, '正常'
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
# ** gpt request ** # ** gpt request **
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时 gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
print('[2] end gpt req')
chatbot[-1] = (i_say_show_user, gpt_say) chatbot[-1] = (i_say_show_user, gpt_say)
history.append(i_say_show_user); history.append(gpt_say) history.append(i_say_show_user); history.append(gpt_say)
print('[3] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
yield chatbot, history, msg
print('[4] next')
if not fast_debug: time.sleep(2) if not fast_debug: time.sleep(2)
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)]) all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。' i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
chatbot.append((i_say, "[Local Message] waiting gpt response.")) chatbot.append((i_say, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
@ -100,10 +97,10 @@ def 解析PDF(file_manifest, project_folder, top_p, temperature, chatbot, histor
chatbot[-1] = (i_say, gpt_say) chatbot[-1] = (i_say, gpt_say)
history.append(i_say); history.append(gpt_say) history.append(i_say); history.append(gpt_say)
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("完成了吗?", res)) chatbot.append(("完成了吗?", res))
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
@CatchException @CatchException
@ -114,7 +111,7 @@ def 批量总结PDF文档(txt, top_p, temperature, chatbot, history, systemPromp
chatbot.append([ chatbot.append([
"函数插件功能?", "函数插件功能?",
"批量总结PDF文档。函数插件贡献者: ValeriaWongEralien"]) "批量总结PDF文档。函数插件贡献者: ValeriaWongEralien"])
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 尝试导入依赖,如果缺少依赖,则给出安装建议 # 尝试导入依赖,如果缺少依赖,则给出安装建议
try: try:
@ -123,7 +120,7 @@ def 批量总结PDF文档(txt, top_p, temperature, chatbot, history, systemPromp
report_execption(chatbot, history, report_execption(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 清空历史,以免输入溢出 # 清空历史,以免输入溢出
@ -135,7 +132,7 @@ def 批量总结PDF文档(txt, top_p, temperature, chatbot, history, systemPromp
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 搜索需要处理的文件清单 # 搜索需要处理的文件清单
@ -147,7 +144,7 @@ def 批量总结PDF文档(txt, top_p, temperature, chatbot, history, systemPromp
# 如果没找到任何文件 # 如果没找到任何文件
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或.pdf文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或.pdf文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 开始正式执行任务 # 开始正式执行任务

View File

@ -1,4 +1,5 @@
from request_llm.bridge_chatgpt import predict_no_ui from request_llm.bridge_chatgpt import predict_no_ui
from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
fast_debug = False fast_debug = False
@ -77,26 +78,22 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```' i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}' i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response.")) chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
print('[1] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=history)
yield chatbot, history, '正常'
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
# ** gpt request ** # ** gpt request **
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时 gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
print('[2] end gpt req')
chatbot[-1] = (i_say_show_user, gpt_say) chatbot[-1] = (i_say_show_user, gpt_say)
history.append(i_say_show_user); history.append(gpt_say) history.append(i_say_show_user); history.append(gpt_say)
print('[3] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
yield chatbot, history, msg
print('[4] next')
if not fast_debug: time.sleep(2) if not fast_debug: time.sleep(2)
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)]) all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。' i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
chatbot.append((i_say, "[Local Message] waiting gpt response.")) chatbot.append((i_say, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
@ -105,10 +102,10 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
chatbot[-1] = (i_say, gpt_say) chatbot[-1] = (i_say, gpt_say)
history.append(i_say); history.append(gpt_say) history.append(i_say); history.append(gpt_say)
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("完成了吗?", res)) chatbot.append(("完成了吗?", res))
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
@ -121,7 +118,7 @@ def 批量总结PDF文档pdfminer(txt, top_p, temperature, chatbot, history, sys
chatbot.append([ chatbot.append([
"函数插件功能?", "函数插件功能?",
"批量总结PDF文档此版本使用pdfminer插件带token约简功能。函数插件贡献者: Euclid-Jie。"]) "批量总结PDF文档此版本使用pdfminer插件带token约简功能。函数插件贡献者: Euclid-Jie。"])
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 尝试导入依赖,如果缺少依赖,则给出安装建议 # 尝试导入依赖,如果缺少依赖,则给出安装建议
try: try:
@ -130,14 +127,14 @@ def 批量总结PDF文档pdfminer(txt, top_p, temperature, chatbot, history, sys
report_execption(chatbot, history, report_execption(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
if os.path.exists(txt): if os.path.exists(txt):
project_folder = txt project_folder = txt
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.pdf', recursive=True)] # + \ [f for f in glob.glob(f'{project_folder}/**/*.pdf', recursive=True)] # + \
@ -145,7 +142,7 @@ def 批量总结PDF文档pdfminer(txt, top_p, temperature, chatbot, history, sys
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] # [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或pdf文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或pdf文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)

View File

@ -1,4 +1,5 @@
from toolbox import CatchException, report_execption, write_results_to_file from toolbox import CatchException, report_execption, write_results_to_file
from toolbox import update_ui
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from .crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency from .crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
@ -96,7 +97,7 @@ def 批量翻译PDF文档(txt, top_p, temperature, chatbot, history, sys_prompt,
chatbot.append([ chatbot.append([
"函数插件功能?", "函数插件功能?",
"批量总结PDF文档。函数插件贡献者: Binary-Husky二进制哈士奇"]) "批量总结PDF文档。函数插件贡献者: Binary-Husky二进制哈士奇"])
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 尝试导入依赖,如果缺少依赖,则给出安装建议 # 尝试导入依赖,如果缺少依赖,则给出安装建议
try: try:
@ -106,7 +107,7 @@ def 批量翻译PDF文档(txt, top_p, temperature, chatbot, history, sys_prompt,
report_execption(chatbot, history, report_execption(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf tiktoken```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 清空历史,以免输入溢出 # 清空历史,以免输入溢出
@ -120,7 +121,7 @@ def 批量翻译PDF文档(txt, top_p, temperature, chatbot, history, sys_prompt,
txt = '空空如也的输入栏' txt = '空空如也的输入栏'
report_execption(chatbot, history, report_execption(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 搜索需要处理的文件清单 # 搜索需要处理的文件清单
@ -131,7 +132,7 @@ def 批量翻译PDF文档(txt, top_p, temperature, chatbot, history, sys_prompt,
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, report_execption(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}") a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 开始正式执行任务 # 开始正式执行任务
@ -188,7 +189,7 @@ def 解析PDF(file_manifest, project_folder, top_p, temperature, chatbot, histor
f'./gpt_log/{create_report_file_name}') f'./gpt_log/{create_report_file_name}')
chatbot.append((f"{fp}完成了吗?", res)) chatbot.append((f"{fp}完成了吗?", res))
msg = "完成" msg = "完成"
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
# 准备文件的下载 # 准备文件的下载
import shutil import shutil
@ -201,4 +202,4 @@ def 解析PDF(file_manifest, project_folder, top_p, temperature, chatbot, histor
if os.path.exists(pdf_path): if os.path.exists(pdf_path):
os.remove(pdf_path) os.remove(pdf_path)
chatbot.append(("给出输出文件清单", str(generated_conclusion_files))) chatbot.append(("给出输出文件清单", str(generated_conclusion_files)))
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)

View File

@ -1,4 +1,5 @@
from request_llm.bridge_chatgpt import predict_no_ui from request_llm.bridge_chatgpt import predict_no_ui
from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
import re import re
import unicodedata import unicodedata
@ -89,18 +90,18 @@ def 解析PDF(file_name, top_p, temperature, chatbot, history, systemPromptTxt):
time.sleep(1) time.sleep(1)
chatbot[-1] = (i_say_show_user, gpt_say) chatbot[-1] = (i_say_show_user, gpt_say)
history.append(i_say_show_user); history.append(gpt_say) history.append(i_say_show_user); history.append(gpt_say)
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
time.sleep(2) time.sleep(2)
i_say = f'接下来请你扮演一名专业的学术教授利用你的所有知识并且结合这篇文章回答我的问题。请牢记1.直到我说“退出”你才能结束任务2.所有问题需要紧密围绕文章内容;3.如果有公式请使用tex渲染)' i_say = f'接下来请你扮演一名专业的学术教授利用你的所有知识并且结合这篇文章回答我的问题。请牢记1.直到我说“退出”你才能结束任务2.所有问题需要紧密围绕文章内容;3.如果有公式请使用tex渲染)'
chatbot.append((i_say, "[Local Message] waiting gpt response.")) chatbot.append((i_say, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# ** gpt request ** # ** gpt request **
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say, chatbot, top_p, temperature, history=history) # 带超时倒计时 gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say, chatbot, top_p, temperature, history=history) # 带超时倒计时
chatbot[-1] = (i_say, gpt_say) chatbot[-1] = (i_say, gpt_say)
history.append(i_say); history.append(gpt_say) history.append(i_say); history.append(gpt_say)
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
@CatchException @CatchException
@ -111,7 +112,7 @@ def 理解PDF文档内容(txt, top_p, temperature, chatbot, history, systemPromp
chatbot.append([ chatbot.append([
"函数插件功能?", "函数插件功能?",
"理解PDF论文内容并且将结合上下文内容进行学术解答。函数插件贡献者: Hanzoe。"]) "理解PDF论文内容并且将结合上下文内容进行学术解答。函数插件贡献者: Hanzoe。"])
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
import tkinter as tk import tkinter as tk
from tkinter import filedialog from tkinter import filedialog
@ -127,7 +128,7 @@ def 理解PDF文档内容(txt, top_p, temperature, chatbot, history, systemPromp
report_execption(chatbot, history, report_execption(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 清空历史,以免输入溢出 # 清空历史,以免输入溢出
@ -146,7 +147,7 @@ def 理解PDF文档内容标准文件输入(txt, top_p, temperature, chatbot, hi
chatbot.append([ chatbot.append([
"函数插件功能?", "函数插件功能?",
"理解PDF论文内容并且将结合上下文内容进行学术解答。函数插件贡献者: Hanzoe。"]) "理解PDF论文内容并且将结合上下文内容进行学术解答。函数插件贡献者: Hanzoe。"])
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 尝试导入依赖,如果缺少依赖,则给出安装建议 # 尝试导入依赖,如果缺少依赖,则给出安装建议
try: try:
@ -155,7 +156,7 @@ def 理解PDF文档内容标准文件输入(txt, top_p, temperature, chatbot, hi
report_execption(chatbot, history, report_execption(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 清空历史,以免输入溢出 # 清空历史,以免输入溢出
@ -169,7 +170,7 @@ def 理解PDF文档内容标准文件输入(txt, top_p, temperature, chatbot, hi
txt = '空空如也的输入栏' txt = '空空如也的输入栏'
report_execption(chatbot, history, report_execption(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 搜索需要处理的文件清单 # 搜索需要处理的文件清单
@ -178,7 +179,7 @@ def 理解PDF文档内容标准文件输入(txt, top_p, temperature, chatbot, hi
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, report_execption(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}") a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
txt = file_manifest[0] txt = file_manifest[0]
# 开始正式执行任务 # 开始正式执行任务

View File

@ -1,4 +1,5 @@
from request_llm.bridge_chatgpt import predict_no_ui from request_llm.bridge_chatgpt import predict_no_ui
from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
fast_debug = False fast_debug = False
@ -13,26 +14,22 @@ def 生成函数注释(file_manifest, project_folder, top_p, temperature, chatbo
i_say = f'请对下面的程序文件做一个概述并对文件中的所有函数生成注释使用markdown表格输出结果文件名是{os.path.relpath(fp, project_folder)},文件内容是 ```{file_content}```' i_say = f'请对下面的程序文件做一个概述并对文件中的所有函数生成注释使用markdown表格输出结果文件名是{os.path.relpath(fp, project_folder)},文件内容是 ```{file_content}```'
i_say_show_user = f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述,并对文件中的所有函数生成注释: {os.path.abspath(fp)}' i_say_show_user = f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述,并对文件中的所有函数生成注释: {os.path.abspath(fp)}'
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response.")) chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
print('[1] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=history)
yield chatbot, history, '正常'
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
# ** gpt request ** # ** gpt request **
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时 gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
print('[2] end gpt req')
chatbot[-1] = (i_say_show_user, gpt_say) chatbot[-1] = (i_say_show_user, gpt_say)
history.append(i_say_show_user); history.append(gpt_say) history.append(i_say_show_user); history.append(gpt_say)
print('[3] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
yield chatbot, history, msg
print('[4] next')
if not fast_debug: time.sleep(2) if not fast_debug: time.sleep(2)
if not fast_debug: if not fast_debug:
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("完成了吗?", res)) chatbot.append(("完成了吗?", res))
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
@ -45,13 +42,13 @@ def 批量生成函数注释(txt, top_p, temperature, chatbot, history, systemPr
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 生成函数注释(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 生成函数注释(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)

View File

@ -1,7 +1,5 @@
from request_llm.bridge_chatgpt import predict_no_ui from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
fast_debug = False
def 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt): def 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt):
import os, copy import os, copy
@ -42,7 +40,7 @@ def 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbo
history_to_return = report_part_1 history_to_return = report_part_1
res = write_results_to_file(report_part_1) res = write_results_to_file(report_part_1)
chatbot.append(("完成?", "逐个文件分析已完成。" + res + "\n\n正在开始汇总。")) chatbot.append(("完成?", "逐个文件分析已完成。" + res + "\n\n正在开始汇总。"))
yield chatbot, history_to_return, msg yield from update_ui(chatbot=chatbot, history=history_to_return)
############################## <第二步,综合,单线程,分组+迭代处理> ################################## ############################## <第二步,综合,单线程,分组+迭代处理> ##################################
batchsize = 16 # 10个文件为一组 batchsize = 16 # 10个文件为一组
@ -76,7 +74,7 @@ def 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbo
history_to_return.extend(report_part_2) history_to_return.extend(report_part_2)
res = write_results_to_file(history_to_return) res = write_results_to_file(history_to_return)
chatbot.append(("完成了吗?", res)) chatbot.append(("完成了吗?", res))
yield chatbot, history_to_return, msg yield from update_ui(chatbot=chatbot, history=history_to_return)
@CatchException @CatchException
@ -89,7 +87,7 @@ def 解析项目本身(txt, top_p, temperature, chatbot, history, systemPromptTx
project_folder = './' project_folder = './'
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
@ -102,12 +100,12 @@ def 解析一个Python项目(txt, top_p, temperature, chatbot, history, systemPr
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
@ -121,14 +119,14 @@ def 解析一个C项目的头文件(txt, top_p, temperature, chatbot, history, s
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.hpp', recursive=True)] #+ \ [f for f in glob.glob(f'{project_folder}/**/*.hpp', recursive=True)] #+ \
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] # [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
@ -141,7 +139,7 @@ def 解析一个C项目(txt, top_p, temperature, chatbot, history, systemPromptT
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
@ -149,7 +147,7 @@ def 解析一个C项目(txt, top_p, temperature, chatbot, history, systemPromptT
[f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
@ -163,7 +161,7 @@ def 解析一个Java项目(txt, top_p, temperature, chatbot, history, systemProm
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.java', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.java', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.jar', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/*.jar', recursive=True)] + \
@ -171,7 +169,7 @@ def 解析一个Java项目(txt, top_p, temperature, chatbot, history, systemProm
[f for f in glob.glob(f'{project_folder}/**/*.sh', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.sh', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何java文件: {txt}") report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何java文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
@ -185,7 +183,7 @@ def 解析一个Rect项目(txt, top_p, temperature, chatbot, history, systemProm
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.ts', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.ts', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.tsx', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/*.tsx', recursive=True)] + \
@ -194,7 +192,7 @@ def 解析一个Rect项目(txt, top_p, temperature, chatbot, history, systemProm
[f for f in glob.glob(f'{project_folder}/**/*.jsx', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.jsx', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何Rect文件: {txt}") report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何Rect文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
@ -208,11 +206,11 @@ def 解析一个Golang项目(txt, top_p, temperature, chatbot, history, systemPr
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.go', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.go', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何golang文件: {txt}") report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何golang文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)

View File

@ -1,4 +1,5 @@
from request_llm.bridge_chatgpt import predict_no_ui from request_llm.bridge_chatgpt import predict_no_ui
from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
fast_debug = False fast_debug = False
@ -14,26 +15,22 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```' i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}' i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response.")) chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
print('[1] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=history)
yield chatbot, history, '正常'
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
# ** gpt request ** # ** gpt request **
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时 gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
print('[2] end gpt req')
chatbot[-1] = (i_say_show_user, gpt_say) chatbot[-1] = (i_say_show_user, gpt_say)
history.append(i_say_show_user); history.append(gpt_say) history.append(i_say_show_user); history.append(gpt_say)
print('[3] yield chatbot, history') yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
yield chatbot, history, msg
print('[4] next')
if not fast_debug: time.sleep(2) if not fast_debug: time.sleep(2)
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)]) all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。' i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
chatbot.append((i_say, "[Local Message] waiting gpt response.")) chatbot.append((i_say, "[Local Message] waiting gpt response."))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
if not fast_debug: if not fast_debug:
msg = '正常' msg = '正常'
@ -42,10 +39,10 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
chatbot[-1] = (i_say, gpt_say) chatbot[-1] = (i_say, gpt_say)
history.append(i_say); history.append(gpt_say) history.append(i_say); history.append(gpt_say)
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("完成了吗?", res)) chatbot.append(("完成了吗?", res))
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
@ -58,13 +55,13 @@ def 读文章写摘要(txt, top_p, temperature, chatbot, history, systemPromptTx
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 chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \ # [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] # [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt) yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)

View File

@ -1,5 +1,6 @@
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from toolbox import CatchException, report_execption, write_results_to_file from toolbox import CatchException, report_execption, write_results_to_file
from toolbox import update_ui
def get_meta_information(url, chatbot, history): def get_meta_information(url, chatbot, history):
import requests import requests
@ -55,8 +56,7 @@ def get_meta_information(url, chatbot, history):
}) })
chatbot[-1] = [chatbot[-1][0], title + f'\n\n是否在arxiv中不在arxiv中无法获取完整摘要:{is_paper_in_arxiv}\n\n' + abstract] chatbot[-1] = [chatbot[-1][0], title + f'\n\n是否在arxiv中不在arxiv中无法获取完整摘要:{is_paper_in_arxiv}\n\n' + abstract]
msg = "正常" yield from update_ui(chatbot=chatbot, history=[])
yield chatbot, [], msg
return profile return profile
@CatchException @CatchException
@ -65,7 +65,7 @@ def 谷歌检索小助手(txt, top_p, temperature, chatbot, history, systemPromp
chatbot.append([ chatbot.append([
"函数插件功能?", "函数插件功能?",
"分析用户提供的谷歌学术google scholar搜索页面中出现的所有文章: binary-husky插件初始化中..."]) "分析用户提供的谷歌学术google scholar搜索页面中出现的所有文章: binary-husky插件初始化中..."])
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
# 尝试导入依赖,如果缺少依赖,则给出安装建议 # 尝试导入依赖,如果缺少依赖,则给出安装建议
try: try:
@ -75,7 +75,7 @@ def 谷歌检索小助手(txt, top_p, temperature, chatbot, history, systemPromp
report_execption(chatbot, history, report_execption(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade beautifulsoup4 arxiv```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade beautifulsoup4 arxiv```。")
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
return return
# 清空历史,以免输入溢出 # 清空历史,以免输入溢出
@ -100,7 +100,7 @@ def 谷歌检索小助手(txt, top_p, temperature, chatbot, history, systemPromp
chatbot.append(["状态?", "已经全部完成"]) chatbot.append(["状态?", "已经全部完成"])
msg = '正常' msg = '正常'
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
res = write_results_to_file(history) res = write_results_to_file(history)
chatbot.append(("完成了吗?", res)); chatbot.append(("完成了吗?", res));
yield chatbot, history, msg yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)

View File

@ -1,11 +1,11 @@
from toolbox import CatchException from toolbox import CatchException, update_ui
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
import datetime import datetime
@CatchException @CatchException
def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT): def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
history = [] # 清空历史,以免输入溢出 history = [] # 清空历史,以免输入溢出
chatbot.append(("这是什么功能?", "[Local Message] 请注意,您正在调用一个[函数插件]的模板该函数面向希望实现更多有趣功能的开发者它可以作为创建新功能函数的模板该函数只有20行代码。此外我们也提供可同步处理大量文件的多线程Demo供您参考。您若希望分享新的功能模组请不吝PR")) chatbot.append(("这是什么功能?", "[Local Message] 请注意,您正在调用一个[函数插件]的模板该函数面向希望实现更多有趣功能的开发者它可以作为创建新功能函数的模板该函数只有20行代码。此外我们也提供可同步处理大量文件的多线程Demo供您参考。您若希望分享新的功能模组请不吝PR"))
yield chatbot, history, '正常' # 由于请求gpt需要一段时间我们先及时地做一次状态显示 yield from update_ui(chatbot=chatbot, history=history) # 由于请求gpt需要一段时间我们先及时地做一次界面更新
for i in range(5): for i in range(5):
currentMonth = (datetime.date.today() + datetime.timedelta(days=i)).month currentMonth = (datetime.date.today() + datetime.timedelta(days=i)).month
currentDay = (datetime.date.today() + datetime.timedelta(days=i)).day currentDay = (datetime.date.today() + datetime.timedelta(days=i)).day
@ -17,4 +17,4 @@ def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPr
) )
chatbot[-1] = (i_say, gpt_say) chatbot[-1] = (i_say, gpt_say)
history.append(i_say);history.append(gpt_say) history.append(i_say);history.append(gpt_say)
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history) # 界面更新

View File

@ -21,7 +21,7 @@ import importlib
# config_private.py放自己的秘密如API和代理网址 # config_private.py放自己的秘密如API和代理网址
# 读取时首先看是否存在私密的config_private配置文件不受git管控如果有则覆盖原config文件 # 读取时首先看是否存在私密的config_private配置文件不受git管控如果有则覆盖原config文件
from toolbox import get_conf from toolbox import get_conf, update_ui
proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, LLM_MODEL = \ proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, LLM_MODEL = \
get_conf('proxies', 'API_URL', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'LLM_MODEL') get_conf('proxies', 'API_URL', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'LLM_MODEL')
@ -157,7 +157,7 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
raw_input = inputs raw_input = inputs
logging.info(f'[raw_input] {raw_input}') logging.info(f'[raw_input] {raw_input}')
chatbot.append((inputs, "")) chatbot.append((inputs, ""))
yield chatbot, history, "等待响应" yield from update_ui(chatbot=chatbot, history=history, msg="等待响应")
headers, payload = generate_payload(inputs, top_p, temperature, history, system_prompt, stream) headers, payload = generate_payload(inputs, top_p, temperature, history, system_prompt, stream)
history.append(inputs); history.append(" ") history.append(inputs); history.append(" ")
@ -172,7 +172,7 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
retry += 1 retry += 1
chatbot[-1] = ((chatbot[-1][0], timeout_bot_msg)) chatbot[-1] = ((chatbot[-1][0], timeout_bot_msg))
retry_msg = f",正在重试 ({retry}/{MAX_RETRY}) ……" if MAX_RETRY > 0 else "" retry_msg = f",正在重试 ({retry}/{MAX_RETRY}) ……" if MAX_RETRY > 0 else ""
yield chatbot, history, "请求超时"+retry_msg yield from update_ui(chatbot=chatbot, history=history, msg="请求超时"+retry_msg)
if retry > MAX_RETRY: raise TimeoutError if retry > MAX_RETRY: raise TimeoutError
gpt_replying_buffer = "" gpt_replying_buffer = ""
@ -200,11 +200,11 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
gpt_replying_buffer = gpt_replying_buffer + json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"] gpt_replying_buffer = gpt_replying_buffer + json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"]
history[-1] = gpt_replying_buffer history[-1] = gpt_replying_buffer
chatbot[-1] = (history[-2], history[-1]) chatbot[-1] = (history[-2], history[-1])
yield chatbot, history, status_text yield from update_ui(chatbot=chatbot, history=history, msg=status_text)
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()
yield chatbot, history, "Json解析不合常规" yield from update_ui(chatbot=chatbot, history=history, msg="Json解析不合常规")
chunk = get_full_error(chunk, stream_response) chunk = get_full_error(chunk, stream_response)
error_msg = chunk.decode() error_msg = chunk.decode()
if "reduce the length" in error_msg: if "reduce the length" in error_msg:
@ -218,7 +218,7 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
from toolbox import regular_txt_to_markdown from toolbox import regular_txt_to_markdown
tb_str = '```\n' + traceback.format_exc() + '```' tb_str = '```\n' + traceback.format_exc() + '```'
chatbot[-1] = (chatbot[-1][0], f"[Local Message] 异常 \n\n{tb_str} \n\n{regular_txt_to_markdown(chunk.decode()[4:])}") chatbot[-1] = (chatbot[-1][0], f"[Local Message] 异常 \n\n{tb_str} \n\n{regular_txt_to_markdown(chunk.decode()[4:])}")
yield chatbot, history, "Json异常" + error_msg yield from update_ui(chatbot=chatbot, history=history, msg="Json异常" + error_msg)
return return
def generate_payload(inputs, top_p, temperature, history, system_prompt, stream): def generate_payload(inputs, top_p, temperature, history, system_prompt, stream):

View File

@ -12,7 +12,7 @@ import logging
import time import time
import threading import threading
import importlib import importlib
from toolbox import get_conf from toolbox import get_conf, update_ui
LLM_MODEL, = get_conf('LLM_MODEL') LLM_MODEL, = get_conf('LLM_MODEL')
# "TGUI:galactica-1.3b@localhost:7860" # "TGUI:galactica-1.3b@localhost:7860"
@ -111,7 +111,7 @@ def predict_tgui(inputs, top_p, temperature, chatbot=[], history=[], system_prom
logging.info(f'[raw_input] {raw_input}') logging.info(f'[raw_input] {raw_input}')
history.extend([inputs, ""]) history.extend([inputs, ""])
chatbot.append([inputs, ""]) chatbot.append([inputs, ""])
yield chatbot, history, "等待响应" yield from update_ui(chatbot=chatbot, history=history, msg="等待响应")
prompt = inputs prompt = inputs
tgui_say = "" tgui_say = ""
@ -138,7 +138,7 @@ def predict_tgui(inputs, top_p, temperature, chatbot=[], history=[], system_prom
tgui_say = mutable[0] tgui_say = mutable[0]
history[-1] = tgui_say history[-1] = tgui_say
chatbot[-1] = (history[-2], history[-1]) chatbot[-1] = (history[-2], history[-1])
yield chatbot, history, "status_text" yield from update_ui(chatbot=chatbot, history=history)
logging.info(f'[response] {tgui_say}') logging.info(f'[response] {tgui_say}')

View File

@ -22,6 +22,9 @@ def ArgsGeneralWrapper(f):
return decorated return decorated
def update_ui(chatbot, history, msg='正常', *args, **kwargs): def update_ui(chatbot, history, msg='正常', *args, **kwargs):
"""
刷新用户界面
"""
yield chatbot, history, msg yield chatbot, history, msg
def get_reduce_token_percent(text): def get_reduce_token_percent(text):
@ -99,7 +102,7 @@ def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temp
cnt += 1 cnt += 1
chatbot[-1] = (i_say_show_user, chatbot[-1] = (i_say_show_user,
f"[Local Message] {mutable[1]}waiting gpt response {cnt}/{TIMEOUT_SECONDS*2*(MAX_RETRY+1)}"+''.join(['.']*(cnt % 4))) f"[Local Message] {mutable[1]}waiting gpt response {cnt}/{TIMEOUT_SECONDS*2*(MAX_RETRY+1)}"+''.join(['.']*(cnt % 4)))
yield chatbot, history, '正常' yield from update_ui(chatbot=chatbot, history=history)
time.sleep(1) time.sleep(1)
# 把gpt的输出从mutable中取出来 # 把gpt的输出从mutable中取出来
gpt_say = mutable[0] gpt_say = mutable[0]
@ -163,7 +166,7 @@ def CatchException(f):
chatbot = [["插件调度异常", "异常原因"]] chatbot = [["插件调度异常", "异常原因"]]
chatbot[-1] = (chatbot[-1][0], chatbot[-1] = (chatbot[-1][0],
f"[Local Message] 实验性函数调用出错: \n\n{tb_str} \n\n当前代理可用性: \n\n{check_proxy(proxies)}") f"[Local Message] 实验性函数调用出错: \n\n{tb_str} \n\n当前代理可用性: \n\n{check_proxy(proxies)}")
yield chatbot, history, f'异常 {e}' yield from update_ui(chatbot=chatbot, history=history, msg=f'异常 {e}')
return decorated return decorated