st
Browse files- crazy_functions/Latex全文润色.py +8 -12
- crazy_functions/crazy_utils.py +4 -5
- crazy_functions/下载arxiv论文翻译摘要.py +7 -6
- crazy_functions/代码重写为全英文_多线程.py +7 -6
- crazy_functions/总结word文档.py +11 -10
- crazy_functions/批量总结PDF文档.py +10 -13
- crazy_functions/批量总结PDF文档pdfminer.py +10 -13
- crazy_functions/批量翻译PDF文档_多线程.py +7 -6
- crazy_functions/理解PDF文档内容.py +10 -9
- crazy_functions/生成函数注释.py +6 -9
- crazy_functions/解析项目源代码.py +16 -18
- crazy_functions/读文章写摘要.py +8 -11
- crazy_functions/谷歌检索小助手.py +6 -6
- crazy_functions/高级功能函数模板.py +3 -3
- request_llm/bridge_chatgpt.py +6 -6
- request_llm/bridge_tgui.py +3 -3
- toolbox.py +5 -2
crazy_functions/Latex全文润色.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
fast_debug = False
|
4 |
|
@@ -14,26 +14,22 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|
14 |
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
15 |
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
16 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
17 |
-
|
18 |
-
yield chatbot, history, '正常'
|
19 |
|
20 |
if not fast_debug:
|
21 |
msg = '正常'
|
22 |
# ** gpt request **
|
23 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
24 |
|
25 |
-
print('[2] end gpt req')
|
26 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
27 |
history.append(i_say_show_user); history.append(gpt_say)
|
28 |
-
|
29 |
-
yield chatbot, history, msg
|
30 |
-
print('[4] next')
|
31 |
if not fast_debug: time.sleep(2)
|
32 |
|
33 |
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
34 |
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
|
35 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
36 |
-
yield chatbot, history
|
37 |
|
38 |
if not fast_debug:
|
39 |
msg = '正常'
|
@@ -42,10 +38,10 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|
42 |
|
43 |
chatbot[-1] = (i_say, gpt_say)
|
44 |
history.append(i_say); history.append(gpt_say)
|
45 |
-
yield chatbot, history, msg
|
46 |
res = write_results_to_file(history)
|
47 |
chatbot.append(("完成了吗?", res))
|
48 |
-
yield chatbot, history, msg
|
49 |
|
50 |
|
51 |
|
@@ -58,13 +54,13 @@ def 读文章写摘要(txt, top_p, temperature, chatbot, history, systemPromptTx
|
|
58 |
else:
|
59 |
if txt == "": txt = '空空如也的输入栏'
|
60 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
61 |
-
yield chatbot, history
|
62 |
return
|
63 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \
|
64 |
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
|
65 |
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
66 |
if len(file_manifest) == 0:
|
67 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
68 |
-
yield chatbot, history
|
69 |
return
|
70 |
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
|
|
1 |
+
from toolbox import update_ui
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
fast_debug = False
|
4 |
|
|
|
14 |
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
15 |
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
16 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
17 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
|
|
18 |
|
19 |
if not fast_debug:
|
20 |
msg = '正常'
|
21 |
# ** gpt request **
|
22 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
23 |
|
|
|
24 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
25 |
history.append(i_say_show_user); history.append(gpt_say)
|
26 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
|
|
|
|
27 |
if not fast_debug: time.sleep(2)
|
28 |
|
29 |
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
30 |
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
|
31 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
32 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
33 |
|
34 |
if not fast_debug:
|
35 |
msg = '正常'
|
|
|
38 |
|
39 |
chatbot[-1] = (i_say, gpt_say)
|
40 |
history.append(i_say); history.append(gpt_say)
|
41 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
42 |
res = write_results_to_file(history)
|
43 |
chatbot.append(("完成了吗?", res))
|
44 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
45 |
|
46 |
|
47 |
|
|
|
54 |
else:
|
55 |
if txt == "": txt = '空空如也的输入栏'
|
56 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
57 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
58 |
return
|
59 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \
|
60 |
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
|
61 |
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
62 |
if len(file_manifest) == 0:
|
63 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
64 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
65 |
return
|
66 |
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
crazy_functions/crazy_utils.py
CHANGED
@@ -118,8 +118,7 @@ def request_gpt_model_in_new_thread_with_ui_alive(
|
|
118 |
if future.done():
|
119 |
break
|
120 |
chatbot[-1] = [chatbot[-1][0], mutable[0]]
|
121 |
-
|
122 |
-
yield chatbot, [], msg
|
123 |
return future.result()
|
124 |
|
125 |
|
@@ -168,7 +167,7 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
|
|
168 |
# 用户反馈
|
169 |
chatbot.append(["请开始多线程操作。", ""])
|
170 |
msg = '正常'
|
171 |
-
yield chatbot, []
|
172 |
# 异步原子
|
173 |
mutable = [["", time.time(), "等待中"] for _ in range(n_frag)]
|
174 |
|
@@ -254,7 +253,7 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
|
|
254 |
for thread_index, done, obs in zip(range(len(worker_done)), worker_done, observe_win)])
|
255 |
chatbot[-1] = [chatbot[-1][0], f'多线程操作已经开始,完成情况: \n\n{stat_str}' + ''.join(['.']*(cnt % 10+1))]
|
256 |
msg = "正常"
|
257 |
-
yield chatbot, []
|
258 |
# 异步任务结束
|
259 |
gpt_response_collection = []
|
260 |
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(
|
|
265 |
for inputs_show_user, f in zip(inputs_show_user_array, futures):
|
266 |
gpt_res = f.result()
|
267 |
chatbot.append([inputs_show_user, gpt_res])
|
268 |
-
yield chatbot, []
|
269 |
time.sleep(1)
|
270 |
return gpt_response_collection
|
271 |
|
|
|
118 |
if future.done():
|
119 |
break
|
120 |
chatbot[-1] = [chatbot[-1][0], mutable[0]]
|
121 |
+
yield from update_ui(chatbot=chatbot, history=[])
|
|
|
122 |
return future.result()
|
123 |
|
124 |
|
|
|
167 |
# 用户反馈
|
168 |
chatbot.append(["请开始多线程操作。", ""])
|
169 |
msg = '正常'
|
170 |
+
yield from update_ui(chatbot=chatbot, history=[])
|
171 |
# 异步原子
|
172 |
mutable = [["", time.time(), "等待中"] for _ in range(n_frag)]
|
173 |
|
|
|
253 |
for thread_index, done, obs in zip(range(len(worker_done)), worker_done, observe_win)])
|
254 |
chatbot[-1] = [chatbot[-1][0], f'多线程操作已经开始,完成情况: \n\n{stat_str}' + ''.join(['.']*(cnt % 10+1))]
|
255 |
msg = "正常"
|
256 |
+
yield from update_ui(chatbot=chatbot, history=[])
|
257 |
# 异步任务结束
|
258 |
gpt_response_collection = []
|
259 |
for inputs_show_user, f in zip(inputs_show_user_array, futures):
|
|
|
264 |
for inputs_show_user, f in zip(inputs_show_user_array, futures):
|
265 |
gpt_res = f.result()
|
266 |
chatbot.append([inputs_show_user, gpt_res])
|
267 |
+
yield from update_ui(chatbot=chatbot, history=[])
|
268 |
time.sleep(1)
|
269 |
return gpt_response_collection
|
270 |
|
crazy_functions/下载arxiv论文翻译摘要.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down, get_conf
|
3 |
import re, requests, unicodedata, os
|
@@ -140,7 +141,7 @@ def 下载arxiv论文并翻译摘要(txt, top_p, temperature, chatbot, history,
|
|
140 |
|
141 |
# 基本信息:功能、贡献者
|
142 |
chatbot.append(["函数插件功能?", CRAZY_FUNCTION_INFO])
|
143 |
-
yield chatbot, history
|
144 |
|
145 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
146 |
try:
|
@@ -149,7 +150,7 @@ def 下载arxiv论文并翻译摘要(txt, top_p, temperature, chatbot, history,
|
|
149 |
report_execption(chatbot, history,
|
150 |
a = f"解析项目: {txt}",
|
151 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。")
|
152 |
-
yield chatbot, history
|
153 |
return
|
154 |
|
155 |
# 清空历史,以免输入溢出
|
@@ -162,25 +163,25 @@ def 下载arxiv论文并翻译摘要(txt, top_p, temperature, chatbot, history,
|
|
162 |
report_execption(chatbot, history,
|
163 |
a = f"解析项目: {txt}",
|
164 |
b = f"下载pdf文件未成功")
|
165 |
-
yield chatbot, history
|
166 |
return
|
167 |
|
168 |
# 翻译摘要等
|
169 |
i_say = f"请你阅读以下学术论文相关的材料,提取摘要,翻译为中文。材料如下:{str(info)}"
|
170 |
i_say_show_user = f'请你阅读以下学术论文相关的材料,提取摘要,翻译为中文。论文:{pdf_path}'
|
171 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
172 |
-
yield chatbot, history
|
173 |
msg = '正常'
|
174 |
# ** gpt request **
|
175 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
176 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
177 |
history.append(i_say_show_user); history.append(gpt_say)
|
178 |
-
yield chatbot, history, msg
|
179 |
# 写入文件
|
180 |
import shutil
|
181 |
# 重置文件的创建时间
|
182 |
shutil.copyfile(pdf_path, f'./gpt_log/{os.path.basename(pdf_path)}'); os.remove(pdf_path)
|
183 |
res = write_results_to_file(history)
|
184 |
chatbot.append(("完成了吗?", res + "\n\nPDF文件也已经下载"))
|
185 |
-
yield chatbot, history, msg
|
186 |
|
|
|
1 |
+
from toolbox import update_ui
|
2 |
from request_llm.bridge_chatgpt import predict_no_ui
|
3 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down, get_conf
|
4 |
import re, requests, unicodedata, os
|
|
|
141 |
|
142 |
# 基本信息:功能、贡献者
|
143 |
chatbot.append(["函数插件功能?", CRAZY_FUNCTION_INFO])
|
144 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
145 |
|
146 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
147 |
try:
|
|
|
150 |
report_execption(chatbot, history,
|
151 |
a = f"解析项目: {txt}",
|
152 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。")
|
153 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
154 |
return
|
155 |
|
156 |
# 清空历史,以免输入溢出
|
|
|
163 |
report_execption(chatbot, history,
|
164 |
a = f"解析项目: {txt}",
|
165 |
b = f"下载pdf文件未成功")
|
166 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
167 |
return
|
168 |
|
169 |
# 翻译摘要等
|
170 |
i_say = f"请你阅读以下学术论文相关的材料,提取摘要,翻译为中文。材料如下:{str(info)}"
|
171 |
i_say_show_user = f'请你阅读以下学术论文相关的材料,提取摘要,翻译为中文。论文:{pdf_path}'
|
172 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
173 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
174 |
msg = '正常'
|
175 |
# ** gpt request **
|
176 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
177 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
178 |
history.append(i_say_show_user); history.append(gpt_say)
|
179 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
180 |
# 写入文件
|
181 |
import shutil
|
182 |
# 重置文件的创建时间
|
183 |
shutil.copyfile(pdf_path, f'./gpt_log/{os.path.basename(pdf_path)}'); os.remove(pdf_path)
|
184 |
res = write_results_to_file(history)
|
185 |
chatbot.append(("完成了吗?", res + "\n\nPDF文件也已经下载"))
|
186 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
187 |
|
crazy_functions/代码重写为全英文_多线程.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import threading
|
2 |
from request_llm.bridge_chatgpt import predict_no_ui_long_connection
|
|
|
3 |
from toolbox import CatchException, write_results_to_file, report_execption
|
4 |
from .crazy_utils import breakdown_txt_to_satisfy_token_limit
|
5 |
|
@@ -33,7 +34,7 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
33 |
report_execption(chatbot, history,
|
34 |
a = f"解析项目: {txt}",
|
35 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade openai transformers```。")
|
36 |
-
yield chatbot, history
|
37 |
return
|
38 |
|
39 |
# 第3步:集合文件
|
@@ -53,7 +54,7 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
53 |
i_say_show_user =f'[{index}/{len(file_manifest)}] 接下来请将以下代码中包含的所有中文转化为英文,只输出转化后的英文代码,请用代码块输出代码: {os.path.abspath(fp)}'
|
54 |
i_say_show_user_buffer.append(i_say_show_user)
|
55 |
chatbot.append((i_say_show_user, "[Local Message] 等待多线程操作,中间过程不予显示."))
|
56 |
-
yield chatbot, history
|
57 |
|
58 |
|
59 |
# 第5步:Token限制下的截断与处理
|
@@ -96,7 +97,7 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
96 |
h.daemon = True
|
97 |
h.start()
|
98 |
chatbot.append(('开始了吗?', f'多线程操作已经开始'))
|
99 |
-
yield chatbot, history
|
100 |
|
101 |
# 第8步:循环轮询各个线程是否执行完毕
|
102 |
cnt = 0
|
@@ -112,7 +113,7 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
112 |
stat = [f'执行中: {obs}\n\n' if alive else '已完成\n\n' for alive, obs in zip(th_alive, observe_win)]
|
113 |
stat_str = ''.join(stat)
|
114 |
chatbot[-1] = (chatbot[-1][0], f'多线程操作已经开始,完成情况: \n\n{stat_str}' + ''.join(['.']*(cnt%10+1)))
|
115 |
-
yield chatbot, history
|
116 |
|
117 |
# 第9步:把结果写入文件
|
118 |
for index, h in enumerate(handles):
|
@@ -129,10 +130,10 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
129 |
shutil.copyfile(file_manifest[index], where_to_relocate)
|
130 |
chatbot.append((i_say_show_user, f'[Local Message] 已完成{os.path.abspath(fp)}的转化,\n\n存入{os.path.abspath(where_to_relocate)}'))
|
131 |
history.append(i_say_show_user); history.append(gpt_say)
|
132 |
-
yield chatbot, history
|
133 |
time.sleep(1)
|
134 |
|
135 |
# 第10步:备份一个文件
|
136 |
res = write_results_to_file(history)
|
137 |
chatbot.append(("生成一份任务执行报告", res))
|
138 |
-
yield chatbot, history
|
|
|
1 |
import threading
|
2 |
from request_llm.bridge_chatgpt import predict_no_ui_long_connection
|
3 |
+
from toolbox import update_ui
|
4 |
from toolbox import CatchException, write_results_to_file, report_execption
|
5 |
from .crazy_utils import breakdown_txt_to_satisfy_token_limit
|
6 |
|
|
|
34 |
report_execption(chatbot, history,
|
35 |
a = f"解析项目: {txt}",
|
36 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade openai transformers```。")
|
37 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
38 |
return
|
39 |
|
40 |
# 第3步:集合文件
|
|
|
54 |
i_say_show_user =f'[{index}/{len(file_manifest)}] 接下来请将以下代码中包含的所有中文转化为英文,只输出转化后的英文代码,请用代码块输出代码: {os.path.abspath(fp)}'
|
55 |
i_say_show_user_buffer.append(i_say_show_user)
|
56 |
chatbot.append((i_say_show_user, "[Local Message] 等待多线程操作,中间过程不予显示."))
|
57 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
58 |
|
59 |
|
60 |
# 第5步:Token限制下的截断与处理
|
|
|
97 |
h.daemon = True
|
98 |
h.start()
|
99 |
chatbot.append(('开始了吗?', f'多线程操作已经开始'))
|
100 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
101 |
|
102 |
# 第8步:循环轮询各个线程是否执行完毕
|
103 |
cnt = 0
|
|
|
113 |
stat = [f'执行中: {obs}\n\n' if alive else '已完成\n\n' for alive, obs in zip(th_alive, observe_win)]
|
114 |
stat_str = ''.join(stat)
|
115 |
chatbot[-1] = (chatbot[-1][0], f'多线程操作已经开始,完成情况: \n\n{stat_str}' + ''.join(['.']*(cnt%10+1)))
|
116 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
117 |
|
118 |
# 第9步:把结果写入文件
|
119 |
for index, h in enumerate(handles):
|
|
|
130 |
shutil.copyfile(file_manifest[index], where_to_relocate)
|
131 |
chatbot.append((i_say_show_user, f'[Local Message] 已完成{os.path.abspath(fp)}的转化,\n\n存入{os.path.abspath(where_to_relocate)}'))
|
132 |
history.append(i_say_show_user); history.append(gpt_say)
|
133 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
134 |
time.sleep(1)
|
135 |
|
136 |
# 第10步:备份一个文件
|
137 |
res = write_results_to_file(history)
|
138 |
chatbot.append(("生成一份任务执行报告", res))
|
139 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
crazy_functions/总结word文档.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
fast_debug = False
|
4 |
|
@@ -35,7 +36,7 @@ def 解析docx(file_manifest, project_folder, top_p, temperature, chatbot, histo
|
|
35 |
f'文章内容是 ```{file_content}```'
|
36 |
i_say_show_user = prefix + f'[{index+1}/{len(file_manifest)}] 假设你是论文审稿专家,请对下面的文章片段做概述: {os.path.abspath(fp)}'
|
37 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
38 |
-
yield chatbot, history
|
39 |
|
40 |
if not fast_debug:
|
41 |
msg = '正常'
|
@@ -45,21 +46,21 @@ def 解析docx(file_manifest, project_folder, top_p, temperature, chatbot, histo
|
|
45 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
46 |
history.append(i_say_show_user);
|
47 |
history.append(gpt_say)
|
48 |
-
yield chatbot, history, msg
|
49 |
if not fast_debug: time.sleep(2)
|
50 |
|
51 |
"""
|
52 |
# 可按需启用
|
53 |
i_say = f'根据你上述的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一篇英文的。'
|
54 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
55 |
-
yield chatbot, history
|
56 |
|
57 |
|
58 |
i_say = f'我想让你做一个论文写作导师。您的任务是使用人工智能工具(例如自然语言处理)提供有关如何改进其上述文章的反馈。' \
|
59 |
f'您还应该利用您在有效写作技巧方面的修辞知识和经验来建议作者可以更好地以书面形式表达他们的想法和想法的方法。' \
|
60 |
f'根据你之前的分析,提出建议'
|
61 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
62 |
-
yield chatbot, history
|
63 |
|
64 |
"""
|
65 |
|
@@ -72,10 +73,10 @@ def 解析docx(file_manifest, project_folder, top_p, temperature, chatbot, histo
|
|
72 |
chatbot[-1] = (i_say, gpt_say)
|
73 |
history.append(i_say)
|
74 |
history.append(gpt_say)
|
75 |
-
yield chatbot, history, msg
|
76 |
res = write_results_to_file(history)
|
77 |
chatbot.append(("完成了吗?", res))
|
78 |
-
yield chatbot, history, msg
|
79 |
|
80 |
|
81 |
@CatchException
|
@@ -86,7 +87,7 @@ def 总结word文档(txt, top_p, temperature, chatbot, history, systemPromptTxt,
|
|
86 |
chatbot.append([
|
87 |
"函数插件功能?",
|
88 |
"批量总结Word文档。函数插件贡献者: JasonGuo1"])
|
89 |
-
yield chatbot, history
|
90 |
|
91 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
92 |
try:
|
@@ -95,7 +96,7 @@ def 总结word文档(txt, top_p, temperature, chatbot, history, systemPromptTxt,
|
|
95 |
report_execption(chatbot, history,
|
96 |
a=f"解析项目: {txt}",
|
97 |
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade python-docx pywin32```。")
|
98 |
-
yield chatbot, history
|
99 |
return
|
100 |
|
101 |
# 清空历史,以免输入溢出
|
@@ -107,7 +108,7 @@ def 总结word文档(txt, top_p, temperature, chatbot, history, systemPromptTxt,
|
|
107 |
else:
|
108 |
if txt == "": txt = '空空如也的输入栏'
|
109 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
110 |
-
yield chatbot, history
|
111 |
return
|
112 |
|
113 |
# 搜索需要处理的文件清单
|
@@ -120,7 +121,7 @@ def 总结word文档(txt, top_p, temperature, chatbot, history, systemPromptTxt,
|
|
120 |
# 如果没找到任何文件
|
121 |
if len(file_manifest) == 0:
|
122 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何.docx或doc文件: {txt}")
|
123 |
-
yield chatbot, history
|
124 |
return
|
125 |
|
126 |
# 开始正式执行任务
|
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
2 |
+
from toolbox import update_ui
|
3 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
4 |
fast_debug = False
|
5 |
|
|
|
36 |
f'文章内容是 ```{file_content}```'
|
37 |
i_say_show_user = prefix + f'[{index+1}/{len(file_manifest)}] 假设你是论文审稿专家,请对下面的文章片段做概述: {os.path.abspath(fp)}'
|
38 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
39 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
40 |
|
41 |
if not fast_debug:
|
42 |
msg = '正常'
|
|
|
46 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
47 |
history.append(i_say_show_user);
|
48 |
history.append(gpt_say)
|
49 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
50 |
if not fast_debug: time.sleep(2)
|
51 |
|
52 |
"""
|
53 |
# 可按需启用
|
54 |
i_say = f'根据你上述的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一篇英文的。'
|
55 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
56 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
57 |
|
58 |
|
59 |
i_say = f'我想让你做一个论文写作导师。您的任务是使用人工智能工具(例如自然语言处理)提供有关如何改进其上述文章的反馈。' \
|
60 |
f'您还应该利用您在有效写作技巧方面的修辞知识和经验来建议作者可以更好地以书面形式表达他们的想法和想法的方法。' \
|
61 |
f'根据你之前的分析,提出建议'
|
62 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
63 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
64 |
|
65 |
"""
|
66 |
|
|
|
73 |
chatbot[-1] = (i_say, gpt_say)
|
74 |
history.append(i_say)
|
75 |
history.append(gpt_say)
|
76 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
77 |
res = write_results_to_file(history)
|
78 |
chatbot.append(("完成了吗?", res))
|
79 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
80 |
|
81 |
|
82 |
@CatchException
|
|
|
87 |
chatbot.append([
|
88 |
"函数插件功能?",
|
89 |
"批量总结Word文档。函数插件贡献者: JasonGuo1"])
|
90 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
91 |
|
92 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
93 |
try:
|
|
|
96 |
report_execption(chatbot, history,
|
97 |
a=f"解析项目: {txt}",
|
98 |
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade python-docx pywin32```。")
|
99 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
100 |
return
|
101 |
|
102 |
# 清空历史,以免输入溢出
|
|
|
108 |
else:
|
109 |
if txt == "": txt = '空空如也的输入栏'
|
110 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
111 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
112 |
return
|
113 |
|
114 |
# 搜索需要处理的文件清单
|
|
|
121 |
# 如果没找到任何文件
|
122 |
if len(file_manifest) == 0:
|
123 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何.docx或doc文件: {txt}")
|
124 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
125 |
return
|
126 |
|
127 |
# 开始正式执行任务
|
crazy_functions/批量总结PDF文档.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
import re
|
4 |
import unicodedata
|
@@ -72,26 +73,22 @@ def 解析PDF(file_manifest, project_folder, top_p, temperature, chatbot, histor
|
|
72 |
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
73 |
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
74 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
75 |
-
|
76 |
-
yield chatbot, history, '正常'
|
77 |
|
78 |
if not fast_debug:
|
79 |
msg = '正常'
|
80 |
# ** gpt request **
|
81 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
82 |
|
83 |
-
print('[2] end gpt req')
|
84 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
85 |
history.append(i_say_show_user); history.append(gpt_say)
|
86 |
-
|
87 |
-
yield chatbot, history, msg
|
88 |
-
print('[4] next')
|
89 |
if not fast_debug: time.sleep(2)
|
90 |
|
91 |
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
92 |
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
|
93 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
94 |
-
yield chatbot, history
|
95 |
|
96 |
if not fast_debug:
|
97 |
msg = '正常'
|
@@ -100,10 +97,10 @@ def 解析PDF(file_manifest, project_folder, top_p, temperature, chatbot, histor
|
|
100 |
|
101 |
chatbot[-1] = (i_say, gpt_say)
|
102 |
history.append(i_say); history.append(gpt_say)
|
103 |
-
yield chatbot, history, msg
|
104 |
res = write_results_to_file(history)
|
105 |
chatbot.append(("完成了吗?", res))
|
106 |
-
yield chatbot, history, msg
|
107 |
|
108 |
|
109 |
@CatchException
|
@@ -114,7 +111,7 @@ def 批量总结PDF文档(txt, top_p, temperature, chatbot, history, systemPromp
|
|
114 |
chatbot.append([
|
115 |
"函数插件功能?",
|
116 |
"批量总结PDF文档。函数插件贡献者: ValeriaWong,Eralien"])
|
117 |
-
yield chatbot, history
|
118 |
|
119 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
120 |
try:
|
@@ -123,7 +120,7 @@ def 批量总结PDF文档(txt, top_p, temperature, chatbot, history, systemPromp
|
|
123 |
report_execption(chatbot, history,
|
124 |
a = f"解析项目: {txt}",
|
125 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
|
126 |
-
yield chatbot, history
|
127 |
return
|
128 |
|
129 |
# 清空历史,以免输入溢出
|
@@ -135,7 +132,7 @@ def 批量总结PDF文档(txt, top_p, temperature, chatbot, history, systemPromp
|
|
135 |
else:
|
136 |
if txt == "": txt = '空空如也的输入栏'
|
137 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
138 |
-
yield chatbot, history
|
139 |
return
|
140 |
|
141 |
# 搜索需要处理的文件清单
|
@@ -147,7 +144,7 @@ def 批量总结PDF文档(txt, top_p, temperature, chatbot, history, systemPromp
|
|
147 |
# 如果没找到任何文件
|
148 |
if len(file_manifest) == 0:
|
149 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或.pdf文件: {txt}")
|
150 |
-
yield chatbot, history
|
151 |
return
|
152 |
|
153 |
# 开始正式执行任务
|
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
2 |
+
from toolbox import update_ui
|
3 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
4 |
import re
|
5 |
import unicodedata
|
|
|
73 |
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
74 |
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
75 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
76 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
|
|
77 |
|
78 |
if not fast_debug:
|
79 |
msg = '正常'
|
80 |
# ** gpt request **
|
81 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
82 |
|
|
|
83 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
84 |
history.append(i_say_show_user); history.append(gpt_say)
|
85 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
|
|
|
|
86 |
if not fast_debug: time.sleep(2)
|
87 |
|
88 |
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
89 |
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
|
90 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
91 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
92 |
|
93 |
if not fast_debug:
|
94 |
msg = '正常'
|
|
|
97 |
|
98 |
chatbot[-1] = (i_say, gpt_say)
|
99 |
history.append(i_say); history.append(gpt_say)
|
100 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
101 |
res = write_results_to_file(history)
|
102 |
chatbot.append(("完成了吗?", res))
|
103 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
104 |
|
105 |
|
106 |
@CatchException
|
|
|
111 |
chatbot.append([
|
112 |
"函数插件功能?",
|
113 |
"批量总结PDF文档。函数插件贡献者: ValeriaWong,Eralien"])
|
114 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
115 |
|
116 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
117 |
try:
|
|
|
120 |
report_execption(chatbot, history,
|
121 |
a = f"解析项目: {txt}",
|
122 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
|
123 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
124 |
return
|
125 |
|
126 |
# 清空历史,以免输入溢出
|
|
|
132 |
else:
|
133 |
if txt == "": txt = '空空如也的输入栏'
|
134 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
135 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
136 |
return
|
137 |
|
138 |
# 搜索需要处理的文件清单
|
|
|
144 |
# 如果没找到任何文件
|
145 |
if len(file_manifest) == 0:
|
146 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或.pdf文件: {txt}")
|
147 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
148 |
return
|
149 |
|
150 |
# 开始正式执行任务
|
crazy_functions/批量总结PDF文档pdfminer.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
|
4 |
fast_debug = False
|
@@ -77,26 +78,22 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|
77 |
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
78 |
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
79 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
80 |
-
|
81 |
-
yield chatbot, history, '正常'
|
82 |
|
83 |
if not fast_debug:
|
84 |
msg = '正常'
|
85 |
# ** gpt request **
|
86 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
87 |
|
88 |
-
print('[2] end gpt req')
|
89 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
90 |
history.append(i_say_show_user); history.append(gpt_say)
|
91 |
-
|
92 |
-
yield chatbot, history, msg
|
93 |
-
print('[4] next')
|
94 |
if not fast_debug: time.sleep(2)
|
95 |
|
96 |
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
97 |
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
|
98 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
99 |
-
yield chatbot, history
|
100 |
|
101 |
if not fast_debug:
|
102 |
msg = '正常'
|
@@ -105,10 +102,10 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|
105 |
|
106 |
chatbot[-1] = (i_say, gpt_say)
|
107 |
history.append(i_say); history.append(gpt_say)
|
108 |
-
yield chatbot, history, msg
|
109 |
res = write_results_to_file(history)
|
110 |
chatbot.append(("完成了吗?", res))
|
111 |
-
yield chatbot, history, msg
|
112 |
|
113 |
|
114 |
|
@@ -121,7 +118,7 @@ def 批量总结PDF文档pdfminer(txt, top_p, temperature, chatbot, history, sys
|
|
121 |
chatbot.append([
|
122 |
"函数插件功能?",
|
123 |
"批量总结PDF文档,此版本使用pdfminer插件,带token约简功能。函数插件贡献者: Euclid-Jie。"])
|
124 |
-
yield chatbot, history
|
125 |
|
126 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
127 |
try:
|
@@ -130,14 +127,14 @@ def 批量总结PDF文档pdfminer(txt, top_p, temperature, chatbot, history, sys
|
|
130 |
report_execption(chatbot, history,
|
131 |
a = f"解析项目: {txt}",
|
132 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。")
|
133 |
-
yield chatbot, history
|
134 |
return
|
135 |
if os.path.exists(txt):
|
136 |
project_folder = txt
|
137 |
else:
|
138 |
if txt == "": txt = '空空如也的输入栏'
|
139 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
140 |
-
yield chatbot, history
|
141 |
return
|
142 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] + \
|
143 |
[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
|
|
145 |
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
146 |
if len(file_manifest) == 0:
|
147 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或pdf文件: {txt}")
|
148 |
-
yield chatbot, history
|
149 |
return
|
150 |
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
151 |
|
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
2 |
+
from toolbox import update_ui
|
3 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
4 |
|
5 |
fast_debug = False
|
|
|
78 |
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
79 |
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
80 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
81 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
|
|
82 |
|
83 |
if not fast_debug:
|
84 |
msg = '正常'
|
85 |
# ** gpt request **
|
86 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
87 |
|
|
|
88 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
89 |
history.append(i_say_show_user); history.append(gpt_say)
|
90 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
|
|
|
|
91 |
if not fast_debug: time.sleep(2)
|
92 |
|
93 |
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
94 |
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
|
95 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
96 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
97 |
|
98 |
if not fast_debug:
|
99 |
msg = '正常'
|
|
|
102 |
|
103 |
chatbot[-1] = (i_say, gpt_say)
|
104 |
history.append(i_say); history.append(gpt_say)
|
105 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
106 |
res = write_results_to_file(history)
|
107 |
chatbot.append(("完成了吗?", res))
|
108 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
109 |
|
110 |
|
111 |
|
|
|
118 |
chatbot.append([
|
119 |
"函数插件功能?",
|
120 |
"批量总结PDF文档,此版本使用pdfminer插件,带token约简功能。函数插件贡献者: Euclid-Jie。"])
|
121 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
122 |
|
123 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
124 |
try:
|
|
|
127 |
report_execption(chatbot, history,
|
128 |
a = f"解析项目: {txt}",
|
129 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。")
|
130 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
131 |
return
|
132 |
if os.path.exists(txt):
|
133 |
project_folder = txt
|
134 |
else:
|
135 |
if txt == "": txt = '空空如也的输入栏'
|
136 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
137 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
138 |
return
|
139 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] + \
|
140 |
[f for f in glob.glob(f'{project_folder}/**/*.pdf', recursive=True)] # + \
|
|
|
142 |
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
143 |
if len(file_manifest) == 0:
|
144 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或pdf文件: {txt}")
|
145 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
146 |
return
|
147 |
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
148 |
|
crazy_functions/批量翻译PDF文档_多线程.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from toolbox import CatchException, report_execption, write_results_to_file
|
|
|
2 |
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
|
3 |
from .crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
|
4 |
|
@@ -96,7 +97,7 @@ def 批量翻译PDF文档(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
96 |
chatbot.append([
|
97 |
"函数插件功能?",
|
98 |
"批量总结PDF文档。函数插件贡献者: Binary-Husky(二进制哈士奇)"])
|
99 |
-
yield chatbot, history
|
100 |
|
101 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
102 |
try:
|
@@ -106,7 +107,7 @@ def 批量翻译PDF文档(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
106 |
report_execption(chatbot, history,
|
107 |
a=f"解析项目: {txt}",
|
108 |
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf tiktoken```。")
|
109 |
-
yield chatbot, history
|
110 |
return
|
111 |
|
112 |
# 清空历史,以免输入溢出
|
@@ -120,7 +121,7 @@ def 批量翻译PDF文档(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
120 |
txt = '空空如也的输入栏'
|
121 |
report_execption(chatbot, history,
|
122 |
a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
123 |
-
yield chatbot, history
|
124 |
return
|
125 |
|
126 |
# 搜索需要处理的文件清单
|
@@ -131,7 +132,7 @@ def 批量翻译PDF文档(txt, top_p, temperature, chatbot, history, sys_prompt,
|
|
131 |
if len(file_manifest) == 0:
|
132 |
report_execption(chatbot, history,
|
133 |
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}")
|
134 |
-
yield chatbot, history
|
135 |
return
|
136 |
|
137 |
# 开始正式执行任务
|
@@ -188,7 +189,7 @@ def 解析PDF(file_manifest, project_folder, top_p, temperature, chatbot, histor
|
|
188 |
f'./gpt_log/{create_report_file_name}')
|
189 |
chatbot.append((f"{fp}完成了吗?", res))
|
190 |
msg = "完成"
|
191 |
-
yield chatbot, history, msg
|
192 |
|
193 |
# 准备文件的下载
|
194 |
import shutil
|
@@ -201,4 +202,4 @@ def 解析PDF(file_manifest, project_folder, top_p, temperature, chatbot, histor
|
|
201 |
if os.path.exists(pdf_path):
|
202 |
os.remove(pdf_path)
|
203 |
chatbot.append(("给出输出文件清单", str(generated_conclusion_files)))
|
204 |
-
yield chatbot, history, msg
|
|
|
1 |
from toolbox import CatchException, report_execption, write_results_to_file
|
2 |
+
from toolbox import update_ui
|
3 |
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
|
4 |
from .crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
|
5 |
|
|
|
97 |
chatbot.append([
|
98 |
"函数插件功能?",
|
99 |
"批量总结PDF文档。函数插件贡献者: Binary-Husky(二进制哈士奇)"])
|
100 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
101 |
|
102 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
103 |
try:
|
|
|
107 |
report_execption(chatbot, history,
|
108 |
a=f"解析项目: {txt}",
|
109 |
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf tiktoken```。")
|
110 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
111 |
return
|
112 |
|
113 |
# 清空历史,以免输入溢出
|
|
|
121 |
txt = '空空如也的输入栏'
|
122 |
report_execption(chatbot, history,
|
123 |
a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
124 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
125 |
return
|
126 |
|
127 |
# 搜索需要处理的文件清单
|
|
|
132 |
if len(file_manifest) == 0:
|
133 |
report_execption(chatbot, history,
|
134 |
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}")
|
135 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
136 |
return
|
137 |
|
138 |
# 开始正式执行任务
|
|
|
189 |
f'./gpt_log/{create_report_file_name}')
|
190 |
chatbot.append((f"{fp}完成了吗?", res))
|
191 |
msg = "完成"
|
192 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
193 |
|
194 |
# 准备文件的下载
|
195 |
import shutil
|
|
|
202 |
if os.path.exists(pdf_path):
|
203 |
os.remove(pdf_path)
|
204 |
chatbot.append(("给出输出文件清单", str(generated_conclusion_files)))
|
205 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
crazy_functions/理解PDF文档内容.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
import re
|
4 |
import unicodedata
|
@@ -89,18 +90,18 @@ def 解析PDF(file_name, top_p, temperature, chatbot, history, systemPromptTxt):
|
|
89 |
time.sleep(1)
|
90 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
91 |
history.append(i_say_show_user); history.append(gpt_say)
|
92 |
-
yield chatbot, history
|
93 |
time.sleep(2)
|
94 |
|
95 |
i_say = f'接下来,请你扮演一名专业的学术教授,利用你的所有知识并且结合这篇文章,回答我的问题。(请牢记:1.直到我说“退出”,你才能结束任务;2.所有问题需要紧密围绕文章内容;3.如果有公式,请使用tex渲染)'
|
96 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
97 |
-
yield chatbot, history
|
98 |
|
99 |
# ** gpt request **
|
100 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say, chatbot, top_p, temperature, history=history) # 带超时倒计时
|
101 |
chatbot[-1] = (i_say, gpt_say)
|
102 |
history.append(i_say); history.append(gpt_say)
|
103 |
-
yield chatbot, history
|
104 |
|
105 |
|
106 |
@CatchException
|
@@ -111,7 +112,7 @@ def 理解PDF文档内容(txt, top_p, temperature, chatbot, history, systemPromp
|
|
111 |
chatbot.append([
|
112 |
"函数插件功能?",
|
113 |
"理解PDF论文内容,并且将结合上下文内容,进行学术解答。函数插件贡献者: Hanzoe。"])
|
114 |
-
yield chatbot, history
|
115 |
|
116 |
import tkinter as tk
|
117 |
from tkinter import filedialog
|
@@ -127,7 +128,7 @@ def 理解PDF文档内容(txt, top_p, temperature, chatbot, history, systemPromp
|
|
127 |
report_execption(chatbot, history,
|
128 |
a = f"解析项目: {txt}",
|
129 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
|
130 |
-
yield chatbot, history
|
131 |
return
|
132 |
|
133 |
# 清空历史,以免输入溢出
|
@@ -146,7 +147,7 @@ def 理解PDF文档内容标准文件输入(txt, top_p, temperature, chatbot, hi
|
|
146 |
chatbot.append([
|
147 |
"函数插件功能?",
|
148 |
"理解PDF论文内容,并且将结合上下文内容,进行学术解答。函数插件贡献者: Hanzoe。"])
|
149 |
-
yield chatbot, history
|
150 |
|
151 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
152 |
try:
|
@@ -155,7 +156,7 @@ def 理解PDF文档内容标准文件输入(txt, top_p, temperature, chatbot, hi
|
|
155 |
report_execption(chatbot, history,
|
156 |
a = f"解析项目: {txt}",
|
157 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
|
158 |
-
yield chatbot, history
|
159 |
return
|
160 |
|
161 |
# 清空历史,以免输入溢出
|
@@ -169,7 +170,7 @@ def 理解PDF文档内容标准文件输入(txt, top_p, temperature, chatbot, hi
|
|
169 |
txt = '空空如也的输入栏'
|
170 |
report_execption(chatbot, history,
|
171 |
a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
172 |
-
yield chatbot, history
|
173 |
return
|
174 |
|
175 |
# 搜索需要处理的文件清单
|
@@ -178,7 +179,7 @@ def 理解PDF文档内容标准文件输入(txt, top_p, temperature, chatbot, hi
|
|
178 |
if len(file_manifest) == 0:
|
179 |
report_execption(chatbot, history,
|
180 |
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}")
|
181 |
-
yield chatbot, history
|
182 |
return
|
183 |
txt = file_manifest[0]
|
184 |
# 开始正式执行任务
|
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
2 |
+
from toolbox import update_ui
|
3 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
4 |
import re
|
5 |
import unicodedata
|
|
|
90 |
time.sleep(1)
|
91 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
92 |
history.append(i_say_show_user); history.append(gpt_say)
|
93 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
94 |
time.sleep(2)
|
95 |
|
96 |
i_say = f'接下来,请你扮演一名专业的学术教授,利用你的所有知识并且结合这篇文章,回答我的问题。(请牢记:1.直到我说“退出”,你才能结束任务;2.所有问题需要紧密围绕文章内容;3.如果有公式,请使用tex渲染)'
|
97 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
98 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
99 |
|
100 |
# ** gpt request **
|
101 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say, chatbot, top_p, temperature, history=history) # 带超时倒计时
|
102 |
chatbot[-1] = (i_say, gpt_say)
|
103 |
history.append(i_say); history.append(gpt_say)
|
104 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
105 |
|
106 |
|
107 |
@CatchException
|
|
|
112 |
chatbot.append([
|
113 |
"函数插件功能?",
|
114 |
"理解PDF论文内容,并且将结合上下文内容,进行学术解答。函数插件贡献者: Hanzoe。"])
|
115 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
116 |
|
117 |
import tkinter as tk
|
118 |
from tkinter import filedialog
|
|
|
128 |
report_execption(chatbot, history,
|
129 |
a = f"解析项目: {txt}",
|
130 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
|
131 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
132 |
return
|
133 |
|
134 |
# 清空历史,以免输入溢出
|
|
|
147 |
chatbot.append([
|
148 |
"函数插件功能?",
|
149 |
"理解PDF论文内容,并且将结合上下文内容,进行学术解答。函数插件贡献者: Hanzoe。"])
|
150 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
151 |
|
152 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
153 |
try:
|
|
|
156 |
report_execption(chatbot, history,
|
157 |
a = f"解析项目: {txt}",
|
158 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
|
159 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
160 |
return
|
161 |
|
162 |
# 清空历史,以免输入溢出
|
|
|
170 |
txt = '空空如也的输入栏'
|
171 |
report_execption(chatbot, history,
|
172 |
a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
173 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
174 |
return
|
175 |
|
176 |
# 搜索需要处理的文件清单
|
|
|
179 |
if len(file_manifest) == 0:
|
180 |
report_execption(chatbot, history,
|
181 |
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}")
|
182 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
183 |
return
|
184 |
txt = file_manifest[0]
|
185 |
# 开始正式执行任务
|
crazy_functions/生成函数注释.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
fast_debug = False
|
4 |
|
@@ -13,26 +14,22 @@ def 生成函数注释(file_manifest, project_folder, top_p, temperature, chatbo
|
|
13 |
i_say = f'请对下面的程序文件做一个概述,并对文件中的所有函数生成注释,使用markdown表格输出结果,文件名是{os.path.relpath(fp, project_folder)},文件内容是 ```{file_content}```'
|
14 |
i_say_show_user = f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述,并对文件中的所有函数生成注释: {os.path.abspath(fp)}'
|
15 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
16 |
-
|
17 |
-
yield chatbot, history, '正常'
|
18 |
|
19 |
if not fast_debug:
|
20 |
msg = '正常'
|
21 |
# ** gpt request **
|
22 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
23 |
|
24 |
-
print('[2] end gpt req')
|
25 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
26 |
history.append(i_say_show_user); history.append(gpt_say)
|
27 |
-
|
28 |
-
yield chatbot, history, msg
|
29 |
-
print('[4] next')
|
30 |
if not fast_debug: time.sleep(2)
|
31 |
|
32 |
if not fast_debug:
|
33 |
res = write_results_to_file(history)
|
34 |
chatbot.append(("完成了吗?", res))
|
35 |
-
yield chatbot, history, msg
|
36 |
|
37 |
|
38 |
|
@@ -45,13 +42,13 @@ def 批量生成函数注释(txt, top_p, temperature, chatbot, history, systemPr
|
|
45 |
else:
|
46 |
if txt == "": txt = '空空如也的输入栏'
|
47 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
48 |
-
yield chatbot, history
|
49 |
return
|
50 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)] + \
|
51 |
[f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)]
|
52 |
|
53 |
if len(file_manifest) == 0:
|
54 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
55 |
-
yield chatbot, history
|
56 |
return
|
57 |
yield from 生成函数注释(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
2 |
+
from toolbox import update_ui
|
3 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
4 |
fast_debug = False
|
5 |
|
|
|
14 |
i_say = f'请对下面的程序文件做一个概述,并对文件中的所有函数生成注释,使用markdown表格输出结果,文件名是{os.path.relpath(fp, project_folder)},文件内容是 ```{file_content}```'
|
15 |
i_say_show_user = f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述,并对文件中的所有函数生成注释: {os.path.abspath(fp)}'
|
16 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
17 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
|
|
18 |
|
19 |
if not fast_debug:
|
20 |
msg = '正常'
|
21 |
# ** gpt request **
|
22 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
23 |
|
|
|
24 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
25 |
history.append(i_say_show_user); history.append(gpt_say)
|
26 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
|
|
|
|
27 |
if not fast_debug: time.sleep(2)
|
28 |
|
29 |
if not fast_debug:
|
30 |
res = write_results_to_file(history)
|
31 |
chatbot.append(("完成了吗?", res))
|
32 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
33 |
|
34 |
|
35 |
|
|
|
42 |
else:
|
43 |
if txt == "": txt = '空空如也的输入栏'
|
44 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
45 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
46 |
return
|
47 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)] + \
|
48 |
[f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)]
|
49 |
|
50 |
if len(file_manifest) == 0:
|
51 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
52 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
53 |
return
|
54 |
yield from 生成函数注释(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
crazy_functions/解析项目源代码.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
-
from
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
-
fast_debug = False
|
4 |
-
|
5 |
|
6 |
def 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt):
|
7 |
import os, copy
|
@@ -42,7 +40,7 @@ def 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbo
|
|
42 |
history_to_return = report_part_1
|
43 |
res = write_results_to_file(report_part_1)
|
44 |
chatbot.append(("完成?", "逐个文件分析已完成。" + res + "\n\n正在开始汇总。"))
|
45 |
-
yield chatbot, history_to_return
|
46 |
|
47 |
############################## <第二步,综合,单线程,分组+迭代处理> ##################################
|
48 |
batchsize = 16 # 10个文件为一组
|
@@ -76,7 +74,7 @@ def 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbo
|
|
76 |
history_to_return.extend(report_part_2)
|
77 |
res = write_results_to_file(history_to_return)
|
78 |
chatbot.append(("完成了吗?", res))
|
79 |
-
yield chatbot, history_to_return
|
80 |
|
81 |
|
82 |
@CatchException
|
@@ -89,7 +87,7 @@ def 解析项目本身(txt, top_p, temperature, chatbot, history, systemPromptTx
|
|
89 |
project_folder = './'
|
90 |
if len(file_manifest) == 0:
|
91 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
|
92 |
-
yield chatbot, history
|
93 |
return
|
94 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
95 |
|
@@ -102,12 +100,12 @@ def 解析一个Python项目(txt, top_p, temperature, chatbot, history, systemPr
|
|
102 |
else:
|
103 |
if txt == "": txt = '空空如也的输入栏'
|
104 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
105 |
-
yield chatbot, history
|
106 |
return
|
107 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)]
|
108 |
if len(file_manifest) == 0:
|
109 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
|
110 |
-
yield chatbot, history
|
111 |
return
|
112 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
113 |
|
@@ -121,14 +119,14 @@ def 解析一个C项目的头文件(txt, top_p, temperature, chatbot, history, s
|
|
121 |
else:
|
122 |
if txt == "": txt = '空空如也的输入栏'
|
123 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
124 |
-
yield chatbot, history
|
125 |
return
|
126 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
|
127 |
[f for f in glob.glob(f'{project_folder}/**/*.hpp', recursive=True)] #+ \
|
128 |
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
129 |
if len(file_manifest) == 0:
|
130 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
|
131 |
-
yield chatbot, history
|
132 |
return
|
133 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
134 |
|
@@ -141,7 +139,7 @@ def 解析一个C项目(txt, top_p, temperature, chatbot, history, systemPromptT
|
|
141 |
else:
|
142 |
if txt == "": txt = '空空如也的输入栏'
|
143 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
144 |
-
yield chatbot, history
|
145 |
return
|
146 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
|
147 |
[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
|
|
149 |
[f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
150 |
if len(file_manifest) == 0:
|
151 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
|
152 |
-
yield chatbot, history
|
153 |
return
|
154 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
155 |
|
@@ -163,7 +161,7 @@ def 解析一个Java项目(txt, top_p, temperature, chatbot, history, systemProm
|
|
163 |
else:
|
164 |
if txt == "": txt = '空空如也的输入栏'
|
165 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
166 |
-
yield chatbot, history
|
167 |
return
|
168 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.java', recursive=True)] + \
|
169 |
[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
|
|
171 |
[f for f in glob.glob(f'{project_folder}/**/*.sh', recursive=True)]
|
172 |
if len(file_manifest) == 0:
|
173 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何java文件: {txt}")
|
174 |
-
yield chatbot, history
|
175 |
return
|
176 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
177 |
|
@@ -185,7 +183,7 @@ def 解析一个Rect项目(txt, top_p, temperature, chatbot, history, systemProm
|
|
185 |
else:
|
186 |
if txt == "": txt = '空空如也的输入栏'
|
187 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
188 |
-
yield chatbot, history
|
189 |
return
|
190 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.ts', recursive=True)] + \
|
191 |
[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
|
|
194 |
[f for f in glob.glob(f'{project_folder}/**/*.jsx', recursive=True)]
|
195 |
if len(file_manifest) == 0:
|
196 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何Rect文件: {txt}")
|
197 |
-
yield chatbot, history
|
198 |
return
|
199 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
200 |
|
@@ -208,11 +206,11 @@ def 解析一个Golang项目(txt, top_p, temperature, chatbot, history, systemPr
|
|
208 |
else:
|
209 |
if txt == "": txt = '空空如也的输入栏'
|
210 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
211 |
-
yield chatbot, history
|
212 |
return
|
213 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.go', recursive=True)]
|
214 |
if len(file_manifest) == 0:
|
215 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何golang文件: {txt}")
|
216 |
-
yield chatbot, history
|
217 |
return
|
218 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
|
|
1 |
+
from toolbox import update_ui
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
|
|
|
|
3 |
|
4 |
def 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt):
|
5 |
import os, copy
|
|
|
40 |
history_to_return = report_part_1
|
41 |
res = write_results_to_file(report_part_1)
|
42 |
chatbot.append(("完成?", "逐个文件分析已完成。" + res + "\n\n正在开始汇总。"))
|
43 |
+
yield from update_ui(chatbot=chatbot, history=history_to_return)
|
44 |
|
45 |
############################## <第二步,综合,单线程,分组+迭代处理> ##################################
|
46 |
batchsize = 16 # 10个文件为一组
|
|
|
74 |
history_to_return.extend(report_part_2)
|
75 |
res = write_results_to_file(history_to_return)
|
76 |
chatbot.append(("完成了吗?", res))
|
77 |
+
yield from update_ui(chatbot=chatbot, history=history_to_return)
|
78 |
|
79 |
|
80 |
@CatchException
|
|
|
87 |
project_folder = './'
|
88 |
if len(file_manifest) == 0:
|
89 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
|
90 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
91 |
return
|
92 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
93 |
|
|
|
100 |
else:
|
101 |
if txt == "": txt = '空空如也的输入栏'
|
102 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
103 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
104 |
return
|
105 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)]
|
106 |
if len(file_manifest) == 0:
|
107 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
|
108 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
109 |
return
|
110 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
111 |
|
|
|
119 |
else:
|
120 |
if txt == "": txt = '空空如也的输入栏'
|
121 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
122 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
123 |
return
|
124 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
|
125 |
[f for f in glob.glob(f'{project_folder}/**/*.hpp', recursive=True)] #+ \
|
126 |
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
127 |
if len(file_manifest) == 0:
|
128 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
|
129 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
130 |
return
|
131 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
132 |
|
|
|
139 |
else:
|
140 |
if txt == "": txt = '空空如也的输入栏'
|
141 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
142 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
143 |
return
|
144 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
|
145 |
[f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
|
|
|
147 |
[f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
148 |
if len(file_manifest) == 0:
|
149 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
|
150 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
151 |
return
|
152 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
153 |
|
|
|
161 |
else:
|
162 |
if txt == "": txt = '空空如也的输入栏'
|
163 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
164 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
165 |
return
|
166 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.java', recursive=True)] + \
|
167 |
[f for f in glob.glob(f'{project_folder}/**/*.jar', recursive=True)] + \
|
|
|
169 |
[f for f in glob.glob(f'{project_folder}/**/*.sh', recursive=True)]
|
170 |
if len(file_manifest) == 0:
|
171 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何java文件: {txt}")
|
172 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
173 |
return
|
174 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
175 |
|
|
|
183 |
else:
|
184 |
if txt == "": txt = '空空如也的输入栏'
|
185 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
186 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
187 |
return
|
188 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.ts', recursive=True)] + \
|
189 |
[f for f in glob.glob(f'{project_folder}/**/*.tsx', recursive=True)] + \
|
|
|
192 |
[f for f in glob.glob(f'{project_folder}/**/*.jsx', recursive=True)]
|
193 |
if len(file_manifest) == 0:
|
194 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何Rect文件: {txt}")
|
195 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
196 |
return
|
197 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
198 |
|
|
|
206 |
else:
|
207 |
if txt == "": txt = '空空如也的输入栏'
|
208 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
|
209 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
210 |
return
|
211 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.go', recursive=True)]
|
212 |
if len(file_manifest) == 0:
|
213 |
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何golang文件: {txt}")
|
214 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
215 |
return
|
216 |
yield from 解析源代码新(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
crazy_functions/读文章写摘要.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
fast_debug = False
|
4 |
|
@@ -14,26 +15,22 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|
14 |
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
15 |
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
16 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
17 |
-
|
18 |
-
yield chatbot, history, '正常'
|
19 |
|
20 |
if not fast_debug:
|
21 |
msg = '正常'
|
22 |
# ** gpt request **
|
23 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
24 |
|
25 |
-
print('[2] end gpt req')
|
26 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
27 |
history.append(i_say_show_user); history.append(gpt_say)
|
28 |
-
|
29 |
-
yield chatbot, history, msg
|
30 |
-
print('[4] next')
|
31 |
if not fast_debug: time.sleep(2)
|
32 |
|
33 |
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
34 |
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
|
35 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
36 |
-
yield chatbot, history
|
37 |
|
38 |
if not fast_debug:
|
39 |
msg = '正常'
|
@@ -42,10 +39,10 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|
42 |
|
43 |
chatbot[-1] = (i_say, gpt_say)
|
44 |
history.append(i_say); history.append(gpt_say)
|
45 |
-
yield chatbot, history, msg
|
46 |
res = write_results_to_file(history)
|
47 |
chatbot.append(("完成了吗?", res))
|
48 |
-
yield chatbot, history, msg
|
49 |
|
50 |
|
51 |
|
@@ -58,13 +55,13 @@ def 读文章写摘要(txt, top_p, temperature, chatbot, history, systemPromptTx
|
|
58 |
else:
|
59 |
if txt == "": txt = '空空如也的输入栏'
|
60 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
61 |
-
yield chatbot, history
|
62 |
return
|
63 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \
|
64 |
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
|
65 |
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
66 |
if len(file_manifest) == 0:
|
67 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
68 |
-
yield chatbot, history
|
69 |
return
|
70 |
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
|
|
1 |
from request_llm.bridge_chatgpt import predict_no_ui
|
2 |
+
from toolbox import update_ui
|
3 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
4 |
fast_debug = False
|
5 |
|
|
|
15 |
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
16 |
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
17 |
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
18 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
|
|
19 |
|
20 |
if not fast_debug:
|
21 |
msg = '正常'
|
22 |
# ** gpt request **
|
23 |
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
24 |
|
|
|
25 |
chatbot[-1] = (i_say_show_user, gpt_say)
|
26 |
history.append(i_say_show_user); history.append(gpt_say)
|
27 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
|
|
|
|
28 |
if not fast_debug: time.sleep(2)
|
29 |
|
30 |
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
31 |
i_say = f'根据以上你自己的分析,对全文进行概括,用学术性语言写一段中文摘要,然后再写一段英文摘要(包括{all_file})。'
|
32 |
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
33 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
34 |
|
35 |
if not fast_debug:
|
36 |
msg = '正常'
|
|
|
39 |
|
40 |
chatbot[-1] = (i_say, gpt_say)
|
41 |
history.append(i_say); history.append(gpt_say)
|
42 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
43 |
res = write_results_to_file(history)
|
44 |
chatbot.append(("完成了吗?", res))
|
45 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
46 |
|
47 |
|
48 |
|
|
|
55 |
else:
|
56 |
if txt == "": txt = '空空如也的输入栏'
|
57 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
58 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
59 |
return
|
60 |
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \
|
61 |
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
|
62 |
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
63 |
if len(file_manifest) == 0:
|
64 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
65 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
66 |
return
|
67 |
yield from 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
crazy_functions/谷歌检索小助手.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file
|
|
|
3 |
|
4 |
def get_meta_information(url, chatbot, history):
|
5 |
import requests
|
@@ -55,8 +56,7 @@ def get_meta_information(url, chatbot, history):
|
|
55 |
})
|
56 |
|
57 |
chatbot[-1] = [chatbot[-1][0], title + f'\n\n是否在arxiv中(不在arxiv中无法获取完整摘要):{is_paper_in_arxiv}\n\n' + abstract]
|
58 |
-
|
59 |
-
yield chatbot, [], msg
|
60 |
return profile
|
61 |
|
62 |
@CatchException
|
@@ -65,7 +65,7 @@ def 谷歌检索小助手(txt, top_p, temperature, chatbot, history, systemPromp
|
|
65 |
chatbot.append([
|
66 |
"函数插件功能?",
|
67 |
"分析用户提供的谷歌学术(google scholar)搜索页面中,出现的所有文章: binary-husky,插件初始化中..."])
|
68 |
-
yield chatbot, history
|
69 |
|
70 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
71 |
try:
|
@@ -75,7 +75,7 @@ def 谷歌检索小助手(txt, top_p, temperature, chatbot, history, systemPromp
|
|
75 |
report_execption(chatbot, history,
|
76 |
a = f"解析项目: {txt}",
|
77 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade beautifulsoup4 arxiv```。")
|
78 |
-
yield chatbot, history
|
79 |
return
|
80 |
|
81 |
# 清空历史,以免输入溢出
|
@@ -100,7 +100,7 @@ def 谷歌检索小助手(txt, top_p, temperature, chatbot, history, systemPromp
|
|
100 |
|
101 |
chatbot.append(["状态?", "已经全部完成"])
|
102 |
msg = '正常'
|
103 |
-
yield chatbot, history, msg
|
104 |
res = write_results_to_file(history)
|
105 |
chatbot.append(("完成了吗?", res));
|
106 |
-
yield chatbot, history, msg
|
|
|
1 |
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file
|
3 |
+
from toolbox import update_ui
|
4 |
|
5 |
def get_meta_information(url, chatbot, history):
|
6 |
import requests
|
|
|
56 |
})
|
57 |
|
58 |
chatbot[-1] = [chatbot[-1][0], title + f'\n\n是否在arxiv中(不在arxiv中无法获取完整摘要):{is_paper_in_arxiv}\n\n' + abstract]
|
59 |
+
yield from update_ui(chatbot=chatbot, history=[])
|
|
|
60 |
return profile
|
61 |
|
62 |
@CatchException
|
|
|
65 |
chatbot.append([
|
66 |
"函数插件功能?",
|
67 |
"分析用户提供的谷歌学术(google scholar)搜索页面中,出现的所有文章: binary-husky,插件初始化中..."])
|
68 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
69 |
|
70 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
71 |
try:
|
|
|
75 |
report_execption(chatbot, history,
|
76 |
a = f"解析项目: {txt}",
|
77 |
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade beautifulsoup4 arxiv```。")
|
78 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
79 |
return
|
80 |
|
81 |
# 清空历史,以免输入溢出
|
|
|
100 |
|
101 |
chatbot.append(["状态?", "已经全部完成"])
|
102 |
msg = '正常'
|
103 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
104 |
res = write_results_to_file(history)
|
105 |
chatbot.append(("完成了吗?", res));
|
106 |
+
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg)
|
crazy_functions/高级功能函数模板.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
from toolbox import CatchException
|
2 |
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
|
3 |
import datetime
|
4 |
@CatchException
|
5 |
def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
6 |
history = [] # 清空历史,以免输入溢出
|
7 |
chatbot.append(("这是什么功能?", "[Local Message] 请注意,您正在调用一个[函数插件]的模板,该函数面向希望实现更多有趣功能的开发者,它可以作为创建新功能函数的模板(该函数只有20行代码)。此外我们也提供可同步处理大量文件的多线程Demo供您参考。您若希望分享新的功能模组,请不吝PR!"))
|
8 |
-
yield chatbot, history
|
9 |
for i in range(5):
|
10 |
currentMonth = (datetime.date.today() + datetime.timedelta(days=i)).month
|
11 |
currentDay = (datetime.date.today() + datetime.timedelta(days=i)).day
|
@@ -17,4 +17,4 @@ def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPr
|
|
17 |
)
|
18 |
chatbot[-1] = (i_say, gpt_say)
|
19 |
history.append(i_say);history.append(gpt_say)
|
20 |
-
yield chatbot, history
|
|
|
1 |
+
from toolbox import CatchException, update_ui
|
2 |
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
|
3 |
import datetime
|
4 |
@CatchException
|
5 |
def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
6 |
history = [] # 清空历史,以免输入溢出
|
7 |
chatbot.append(("这是什么功能?", "[Local Message] 请注意,您正在调用一个[函数插件]的模板,该函数面向希望实现更多有趣功能的开发者,它可以作为创建新功能函数的模板(该函数只有20行代码)。此外我们也提供可同步处理大量文件的多线程Demo供您参考。您若希望分享新的功能模组,请不吝PR!"))
|
8 |
+
yield from update_ui(chatbot=chatbot, history=history) # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
|
9 |
for i in range(5):
|
10 |
currentMonth = (datetime.date.today() + datetime.timedelta(days=i)).month
|
11 |
currentDay = (datetime.date.today() + datetime.timedelta(days=i)).day
|
|
|
17 |
)
|
18 |
chatbot[-1] = (i_say, gpt_say)
|
19 |
history.append(i_say);history.append(gpt_say)
|
20 |
+
yield from update_ui(chatbot=chatbot, history=history) # 界面更新
|
request_llm/bridge_chatgpt.py
CHANGED
@@ -21,7 +21,7 @@ import importlib
|
|
21 |
|
22 |
# config_private.py放自己的秘密如API和代理网址
|
23 |
# 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件
|
24 |
-
from toolbox import get_conf
|
25 |
proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, LLM_MODEL = \
|
26 |
get_conf('proxies', 'API_URL', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'LLM_MODEL')
|
27 |
|
@@ -157,7 +157,7 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
|
|
157 |
raw_input = inputs
|
158 |
logging.info(f'[raw_input] {raw_input}')
|
159 |
chatbot.append((inputs, ""))
|
160 |
-
yield chatbot, history, "等待响应"
|
161 |
|
162 |
headers, payload = generate_payload(inputs, top_p, temperature, history, system_prompt, stream)
|
163 |
history.append(inputs); history.append(" ")
|
@@ -172,7 +172,7 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
|
|
172 |
retry += 1
|
173 |
chatbot[-1] = ((chatbot[-1][0], timeout_bot_msg))
|
174 |
retry_msg = f",正在重试 ({retry}/{MAX_RETRY}) ……" if MAX_RETRY > 0 else ""
|
175 |
-
yield chatbot, history, "请求超时"+retry_msg
|
176 |
if retry > MAX_RETRY: raise TimeoutError
|
177 |
|
178 |
gpt_replying_buffer = ""
|
@@ -200,11 +200,11 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
|
|
200 |
gpt_replying_buffer = gpt_replying_buffer + json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"]
|
201 |
history[-1] = gpt_replying_buffer
|
202 |
chatbot[-1] = (history[-2], history[-1])
|
203 |
-
yield chatbot, history, status_text
|
204 |
|
205 |
except Exception as e:
|
206 |
traceback.print_exc()
|
207 |
-
yield chatbot, history, "Json解析不合常规"
|
208 |
chunk = get_full_error(chunk, stream_response)
|
209 |
error_msg = chunk.decode()
|
210 |
if "reduce the length" in error_msg:
|
@@ -218,7 +218,7 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
|
|
218 |
from toolbox import regular_txt_to_markdown
|
219 |
tb_str = '```\n' + traceback.format_exc() + '```'
|
220 |
chatbot[-1] = (chatbot[-1][0], f"[Local Message] 异常 \n\n{tb_str} \n\n{regular_txt_to_markdown(chunk.decode()[4:])}")
|
221 |
-
yield chatbot, history, "Json异常" + error_msg
|
222 |
return
|
223 |
|
224 |
def generate_payload(inputs, top_p, temperature, history, system_prompt, stream):
|
|
|
21 |
|
22 |
# config_private.py放自己的秘密如API和代理网址
|
23 |
# 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件
|
24 |
+
from toolbox import get_conf, update_ui
|
25 |
proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, LLM_MODEL = \
|
26 |
get_conf('proxies', 'API_URL', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'LLM_MODEL')
|
27 |
|
|
|
157 |
raw_input = inputs
|
158 |
logging.info(f'[raw_input] {raw_input}')
|
159 |
chatbot.append((inputs, ""))
|
160 |
+
yield from update_ui(chatbot=chatbot, history=history, msg="等待响应")
|
161 |
|
162 |
headers, payload = generate_payload(inputs, top_p, temperature, history, system_prompt, stream)
|
163 |
history.append(inputs); history.append(" ")
|
|
|
172 |
retry += 1
|
173 |
chatbot[-1] = ((chatbot[-1][0], timeout_bot_msg))
|
174 |
retry_msg = f",正在重试 ({retry}/{MAX_RETRY}) ……" if MAX_RETRY > 0 else ""
|
175 |
+
yield from update_ui(chatbot=chatbot, history=history, msg="请求超时"+retry_msg)
|
176 |
if retry > MAX_RETRY: raise TimeoutError
|
177 |
|
178 |
gpt_replying_buffer = ""
|
|
|
200 |
gpt_replying_buffer = gpt_replying_buffer + json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"]
|
201 |
history[-1] = gpt_replying_buffer
|
202 |
chatbot[-1] = (history[-2], history[-1])
|
203 |
+
yield from update_ui(chatbot=chatbot, history=history, msg=status_text)
|
204 |
|
205 |
except Exception as e:
|
206 |
traceback.print_exc()
|
207 |
+
yield from update_ui(chatbot=chatbot, history=history, msg="Json解析不合常规")
|
208 |
chunk = get_full_error(chunk, stream_response)
|
209 |
error_msg = chunk.decode()
|
210 |
if "reduce the length" in error_msg:
|
|
|
218 |
from toolbox import regular_txt_to_markdown
|
219 |
tb_str = '```\n' + traceback.format_exc() + '```'
|
220 |
chatbot[-1] = (chatbot[-1][0], f"[Local Message] 异常 \n\n{tb_str} \n\n{regular_txt_to_markdown(chunk.decode()[4:])}")
|
221 |
+
yield from update_ui(chatbot=chatbot, history=history, msg="Json异常" + error_msg)
|
222 |
return
|
223 |
|
224 |
def generate_payload(inputs, top_p, temperature, history, system_prompt, stream):
|
request_llm/bridge_tgui.py
CHANGED
@@ -12,7 +12,7 @@ import logging
|
|
12 |
import time
|
13 |
import threading
|
14 |
import importlib
|
15 |
-
from toolbox import get_conf
|
16 |
LLM_MODEL, = get_conf('LLM_MODEL')
|
17 |
|
18 |
# "TGUI:galactica-1.3b@localhost:7860"
|
@@ -111,7 +111,7 @@ def predict_tgui(inputs, top_p, temperature, chatbot=[], history=[], system_prom
|
|
111 |
logging.info(f'[raw_input] {raw_input}')
|
112 |
history.extend([inputs, ""])
|
113 |
chatbot.append([inputs, ""])
|
114 |
-
yield chatbot, history, "等待响应"
|
115 |
|
116 |
prompt = inputs
|
117 |
tgui_say = ""
|
@@ -138,7 +138,7 @@ def predict_tgui(inputs, top_p, temperature, chatbot=[], history=[], system_prom
|
|
138 |
tgui_say = mutable[0]
|
139 |
history[-1] = tgui_say
|
140 |
chatbot[-1] = (history[-2], history[-1])
|
141 |
-
yield chatbot, history
|
142 |
|
143 |
logging.info(f'[response] {tgui_say}')
|
144 |
|
|
|
12 |
import time
|
13 |
import threading
|
14 |
import importlib
|
15 |
+
from toolbox import get_conf, update_ui
|
16 |
LLM_MODEL, = get_conf('LLM_MODEL')
|
17 |
|
18 |
# "TGUI:galactica-1.3b@localhost:7860"
|
|
|
111 |
logging.info(f'[raw_input] {raw_input}')
|
112 |
history.extend([inputs, ""])
|
113 |
chatbot.append([inputs, ""])
|
114 |
+
yield from update_ui(chatbot=chatbot, history=history, msg="等待响应")
|
115 |
|
116 |
prompt = inputs
|
117 |
tgui_say = ""
|
|
|
138 |
tgui_say = mutable[0]
|
139 |
history[-1] = tgui_say
|
140 |
chatbot[-1] = (history[-2], history[-1])
|
141 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
142 |
|
143 |
logging.info(f'[response] {tgui_say}')
|
144 |
|
toolbox.py
CHANGED
@@ -22,6 +22,9 @@ def ArgsGeneralWrapper(f):
|
|
22 |
return decorated
|
23 |
|
24 |
def update_ui(chatbot, history, msg='正常', *args, **kwargs):
|
|
|
|
|
|
|
25 |
yield chatbot, history, msg
|
26 |
|
27 |
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
|
|
99 |
cnt += 1
|
100 |
chatbot[-1] = (i_say_show_user,
|
101 |
f"[Local Message] {mutable[1]}waiting gpt response {cnt}/{TIMEOUT_SECONDS*2*(MAX_RETRY+1)}"+''.join(['.']*(cnt % 4)))
|
102 |
-
yield chatbot, history
|
103 |
time.sleep(1)
|
104 |
# 把gpt的输出从mutable中取出来
|
105 |
gpt_say = mutable[0]
|
@@ -163,7 +166,7 @@ def CatchException(f):
|
|
163 |
chatbot = [["插件调度异常", "异常原因"]]
|
164 |
chatbot[-1] = (chatbot[-1][0],
|
165 |
f"[Local Message] 实验性函数调用出错: \n\n{tb_str} \n\n当前代理可用性: \n\n{check_proxy(proxies)}")
|
166 |
-
yield chatbot, history, f'异常 {e}'
|
167 |
return decorated
|
168 |
|
169 |
|
|
|
22 |
return decorated
|
23 |
|
24 |
def update_ui(chatbot, history, msg='正常', *args, **kwargs):
|
25 |
+
"""
|
26 |
+
刷新用户界面
|
27 |
+
"""
|
28 |
yield chatbot, history, msg
|
29 |
|
30 |
def get_reduce_token_percent(text):
|
|
|
102 |
cnt += 1
|
103 |
chatbot[-1] = (i_say_show_user,
|
104 |
f"[Local Message] {mutable[1]}waiting gpt response {cnt}/{TIMEOUT_SECONDS*2*(MAX_RETRY+1)}"+''.join(['.']*(cnt % 4)))
|
105 |
+
yield from update_ui(chatbot=chatbot, history=history)
|
106 |
time.sleep(1)
|
107 |
# 把gpt的输出从mutable中取出来
|
108 |
gpt_say = mutable[0]
|
|
|
166 |
chatbot = [["插件调度异常", "异常原因"]]
|
167 |
chatbot[-1] = (chatbot[-1][0],
|
168 |
f"[Local Message] 实验性函数调用出错: \n\n{tb_str} \n\n当前代理可用性: \n\n{check_proxy(proxies)}")
|
169 |
+
yield from update_ui(chatbot=chatbot, history=history, msg=f'异常 {e}')
|
170 |
return decorated
|
171 |
|
172 |
|