Spaces:
Build error
Build error
模块化封装
Browse files- crazy_functions/生成函数注释.py +2 -2
- crazy_functions/解析项目源代码.py +147 -0
- crazy_functions/读文章写摘要.py +3 -3
- crazy_functions/高级功能函数模板.py +17 -0
- functional_crazy.py +4 -154
- toolbox.py +21 -1
crazy_functions/生成函数注释.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from predict import predict_no_ui
|
2 |
-
from toolbox import CatchException, report_execption, write_results_to_file
|
3 |
fast_debug = False
|
4 |
|
5 |
|
@@ -21,7 +21,7 @@ def 生成函数注释(file_manifest, project_folder, top_p, temperature, chatbo
|
|
21 |
# ** gpt request **
|
22 |
while True:
|
23 |
try:
|
24 |
-
gpt_say =
|
25 |
break
|
26 |
except ConnectionAbortedError as e:
|
27 |
i_say = i_say[:len(i_say)//2]
|
|
|
1 |
from predict 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 |
|
5 |
|
|
|
21 |
# ** gpt request **
|
22 |
while True:
|
23 |
try:
|
24 |
+
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
25 |
break
|
26 |
except ConnectionAbortedError as e:
|
27 |
i_say = i_say[:len(i_say)//2]
|
crazy_functions/解析项目源代码.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from predict 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 |
+
|
5 |
+
def 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt):
|
6 |
+
import time, glob, os
|
7 |
+
print('begin analysis on:', file_manifest)
|
8 |
+
for index, fp in enumerate(file_manifest):
|
9 |
+
with open(fp, 'r', encoding='utf-8') as f:
|
10 |
+
file_content = f.read()
|
11 |
+
|
12 |
+
前言 = "接下来请你逐文件分析下面的工程" if index==0 else ""
|
13 |
+
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{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 |
+
print('[1] yield chatbot, history')
|
17 |
+
yield chatbot, history, '正常'
|
18 |
+
|
19 |
+
if not fast_debug:
|
20 |
+
msg = '正常'
|
21 |
+
# ** gpt request **
|
22 |
+
while True:
|
23 |
+
try:
|
24 |
+
# gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature)
|
25 |
+
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
26 |
+
break
|
27 |
+
except ConnectionAbortedError as e:
|
28 |
+
i_say = i_say[:len(i_say)//2]
|
29 |
+
msg = '文件太长,进行了拦腰截断'
|
30 |
+
|
31 |
+
print('[2] end gpt req')
|
32 |
+
chatbot[-1] = (i_say_show_user, gpt_say)
|
33 |
+
history.append(i_say_show_user); history.append(gpt_say)
|
34 |
+
print('[3] yield chatbot, history')
|
35 |
+
yield chatbot, history, msg
|
36 |
+
print('[4] next')
|
37 |
+
if not fast_debug: time.sleep(2)
|
38 |
+
|
39 |
+
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
40 |
+
i_say = f'根据以上你自己的分析,对程序的整体功能和构架做出概括。然后用一张markdown表格整理每个文件的功能(包括{all_file})。'
|
41 |
+
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
42 |
+
yield chatbot, history, '正常'
|
43 |
+
|
44 |
+
if not fast_debug:
|
45 |
+
msg = '正常'
|
46 |
+
# ** gpt request **
|
47 |
+
while True:
|
48 |
+
try:
|
49 |
+
# gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
50 |
+
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=history) # 带超时倒计时
|
51 |
+
break
|
52 |
+
except ConnectionAbortedError as e:
|
53 |
+
history = [his[len(his)//2:] for his in history]
|
54 |
+
msg = '对话历史太长,每段历史拦腰截断'
|
55 |
+
|
56 |
+
|
57 |
+
chatbot[-1] = (i_say, gpt_say)
|
58 |
+
history.append(i_say); history.append(gpt_say)
|
59 |
+
yield chatbot, history, msg
|
60 |
+
res = write_results_to_file(history)
|
61 |
+
chatbot.append(("完成了吗?", res))
|
62 |
+
yield chatbot, history, msg
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
@CatchException
|
68 |
+
def 解析项目本身(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
69 |
+
history = [] # 清空历史,以免输入溢出
|
70 |
+
import time, glob, os
|
71 |
+
file_manifest = [f for f in glob.glob('*.py')]
|
72 |
+
for index, fp in enumerate(file_manifest):
|
73 |
+
# if 'test_project' in fp: continue
|
74 |
+
with open(fp, 'r', encoding='utf-8') as f:
|
75 |
+
file_content = f.read()
|
76 |
+
|
77 |
+
前言 = "接下来请你分析自己的程序构成,别紧张," if index==0 else ""
|
78 |
+
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{fp},文件代码是 ```{file_content}```'
|
79 |
+
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
|
80 |
+
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
81 |
+
yield chatbot, history, '正常'
|
82 |
+
|
83 |
+
if not fast_debug:
|
84 |
+
# ** gpt request **
|
85 |
+
# gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature)
|
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 chatbot, history, '正常'
|
91 |
+
time.sleep(2)
|
92 |
+
|
93 |
+
i_say = f'根据以上你自己的分析,对程序的整体功能和构架做出概括。然后用一张markdown表格整理每个文件的功能(包括{file_manifest})。'
|
94 |
+
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
95 |
+
yield chatbot, history, '正常'
|
96 |
+
|
97 |
+
if not fast_debug:
|
98 |
+
# ** gpt request **
|
99 |
+
# gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
100 |
+
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=history) # 带超时倒计时
|
101 |
+
|
102 |
+
chatbot[-1] = (i_say, gpt_say)
|
103 |
+
history.append(i_say); history.append(gpt_say)
|
104 |
+
yield chatbot, history, '正常'
|
105 |
+
res = write_results_to_file(history)
|
106 |
+
chatbot.append(("完成了吗?", res))
|
107 |
+
yield chatbot, history, '正常'
|
108 |
+
|
109 |
+
@CatchException
|
110 |
+
def 解析一个Python项目(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
111 |
+
history = [] # 清空历史,以免输入溢出
|
112 |
+
import glob, os
|
113 |
+
if os.path.exists(txt):
|
114 |
+
project_folder = txt
|
115 |
+
else:
|
116 |
+
if txt == "": txt = '空空如也的输入栏'
|
117 |
+
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
118 |
+
yield chatbot, history, '正常'
|
119 |
+
return
|
120 |
+
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)]
|
121 |
+
if len(file_manifest) == 0:
|
122 |
+
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
|
123 |
+
yield chatbot, history, '正常'
|
124 |
+
return
|
125 |
+
yield from 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
126 |
+
|
127 |
+
|
128 |
+
@CatchException
|
129 |
+
def 解析一个C项目的头文件(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
130 |
+
history = [] # 清空历史,以免输入溢出
|
131 |
+
import glob, os
|
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 chatbot, history, '正常'
|
138 |
+
return
|
139 |
+
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] # + \
|
140 |
+
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
|
141 |
+
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
142 |
+
if len(file_manifest) == 0:
|
143 |
+
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
|
144 |
+
yield chatbot, history, '正常'
|
145 |
+
return
|
146 |
+
yield from 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
147 |
+
|
crazy_functions/读文章写摘要.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from predict import predict_no_ui
|
2 |
-
from toolbox import CatchException, report_execption, write_results_to_file
|
3 |
fast_debug = False
|
4 |
|
5 |
|
@@ -22,7 +22,7 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|
22 |
# ** gpt request **
|
23 |
while True:
|
24 |
try:
|
25 |
-
gpt_say =
|
26 |
break
|
27 |
except ConnectionAbortedError as e:
|
28 |
i_say = i_say[:len(i_say)//2]
|
@@ -46,7 +46,7 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|
46 |
# ** gpt request **
|
47 |
while True:
|
48 |
try:
|
49 |
-
gpt_say =
|
50 |
break
|
51 |
except ConnectionAbortedError as e:
|
52 |
history = [his[len(his)//2:] for his in history]
|
|
|
1 |
from predict 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 |
|
5 |
|
|
|
22 |
# ** gpt request **
|
23 |
while True:
|
24 |
try:
|
25 |
+
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]) # 带超时倒计时
|
26 |
break
|
27 |
except ConnectionAbortedError as e:
|
28 |
i_say = i_say[:len(i_say)//2]
|
|
|
46 |
# ** gpt request **
|
47 |
while True:
|
48 |
try:
|
49 |
+
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=history) # 带超时倒计时
|
50 |
break
|
51 |
except ConnectionAbortedError as e:
|
52 |
history = [his[len(his)//2:] for his in history]
|
crazy_functions/高级功能函数模板.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from predict 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 |
+
|
5 |
+
@CatchException
|
6 |
+
def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
7 |
+
history = [] # 清空历史,以免输入溢出
|
8 |
+
for i in range(5):
|
9 |
+
i_say = f'我给出一个数字,你给出该数字的平方。我给出数字:{i}'
|
10 |
+
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
11 |
+
yield chatbot, history, '正常' # 由于请求gpt需要一段时间,我们先及时地做一次状态显示
|
12 |
+
|
13 |
+
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature) # 请求gpt,需要一段时间
|
14 |
+
|
15 |
+
chatbot[-1] = (i_say, gpt_say)
|
16 |
+
history.append(i_say);history.append(gpt_say)
|
17 |
+
yield chatbot, history, '正常' # 显示
|
functional_crazy.py
CHANGED
@@ -1,161 +1,11 @@
|
|
1 |
-
from predict import predict_no_ui
|
2 |
-
from toolbox import CatchException, report_execption, write_results_to_file
|
3 |
-
fast_debug = False
|
4 |
-
|
5 |
-
def 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt):
|
6 |
-
import time, glob, os
|
7 |
-
print('begin analysis on:', file_manifest)
|
8 |
-
for index, fp in enumerate(file_manifest):
|
9 |
-
with open(fp, 'r', encoding='utf-8') as f:
|
10 |
-
file_content = f.read()
|
11 |
-
|
12 |
-
前言 = "接下来请你逐文件分析下面的工程" if index==0 else ""
|
13 |
-
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{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 |
-
print('[1] yield chatbot, history')
|
17 |
-
yield chatbot, history, '正常'
|
18 |
-
|
19 |
-
if not fast_debug:
|
20 |
-
msg = '正常'
|
21 |
-
# ** gpt request **
|
22 |
-
while True:
|
23 |
-
try:
|
24 |
-
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature)
|
25 |
-
break
|
26 |
-
except ConnectionAbortedError as e:
|
27 |
-
i_say = i_say[:len(i_say)//2]
|
28 |
-
msg = '文件太长,进行了拦腰截断'
|
29 |
-
|
30 |
-
print('[2] end gpt req')
|
31 |
-
chatbot[-1] = (i_say_show_user, gpt_say)
|
32 |
-
history.append(i_say_show_user); history.append(gpt_say)
|
33 |
-
print('[3] yield chatbot, history')
|
34 |
-
yield chatbot, history, msg
|
35 |
-
print('[4] next')
|
36 |
-
if not fast_debug: time.sleep(2)
|
37 |
-
|
38 |
-
all_file = ', '.join([os.path.relpath(fp, project_folder) for index, fp in enumerate(file_manifest)])
|
39 |
-
i_say = f'根据以上你自己的分析,对程序的整体功能和构架做出概括。然后用一张markdown表格整理每个文件的功能(包括{all_file})。'
|
40 |
-
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
41 |
-
yield chatbot, history, '正常'
|
42 |
-
|
43 |
-
if not fast_debug:
|
44 |
-
msg = '正常'
|
45 |
-
# ** gpt request **
|
46 |
-
while True:
|
47 |
-
try:
|
48 |
-
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
49 |
-
break
|
50 |
-
except ConnectionAbortedError as e:
|
51 |
-
history = [his[len(his)//2:] for his in history]
|
52 |
-
msg = '对话历史太长,每段历史拦腰截断'
|
53 |
-
|
54 |
-
|
55 |
-
chatbot[-1] = (i_say, gpt_say)
|
56 |
-
history.append(i_say); history.append(gpt_say)
|
57 |
-
yield chatbot, history, msg
|
58 |
-
res = write_results_to_file(history)
|
59 |
-
chatbot.append(("完成了吗?", res))
|
60 |
-
yield chatbot, history, msg
|
61 |
-
|
62 |
-
@CatchException
|
63 |
-
def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
64 |
-
history = [] # 清空历史,以免输入溢出
|
65 |
-
for i in range(5):
|
66 |
-
i_say = f'我给出一个数字,你给出该数字的平方。我给出数字:{i}'
|
67 |
-
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
68 |
-
yield chatbot, history, '正常' # 由于请求gpt需要一段时间,我们先及时地做一次状态显示
|
69 |
-
|
70 |
-
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature) # 请求gpt,需要一段时间
|
71 |
-
|
72 |
-
chatbot[-1] = (i_say, gpt_say)
|
73 |
-
history.append(i_say);history.append(gpt_say)
|
74 |
-
yield chatbot, history, '正常' # 显示
|
75 |
-
|
76 |
-
|
77 |
-
@CatchException
|
78 |
-
def 解析项目本身(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
79 |
-
history = [] # 清空历史,以免输入溢出
|
80 |
-
import time, glob, os
|
81 |
-
file_manifest = [f for f in glob.glob('*.py')]
|
82 |
-
for index, fp in enumerate(file_manifest):
|
83 |
-
with open(fp, 'r', encoding='utf-8') as f:
|
84 |
-
file_content = f.read()
|
85 |
-
|
86 |
-
前言 = "接下来请你分析自己的程序构成,别紧张," if index==0 else ""
|
87 |
-
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{fp},文件代码是 ```{file_content}```'
|
88 |
-
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
|
89 |
-
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
90 |
-
yield chatbot, history, '正常'
|
91 |
-
|
92 |
-
if not fast_debug:
|
93 |
-
# ** gpt request **
|
94 |
-
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature)
|
95 |
-
|
96 |
-
chatbot[-1] = (i_say_show_user, gpt_say)
|
97 |
-
history.append(i_say_show_user); history.append(gpt_say)
|
98 |
-
yield chatbot, history, '正常'
|
99 |
-
time.sleep(2)
|
100 |
-
|
101 |
-
i_say = f'根据以上你自己的分析,对程序的整体功能和构架做出概括。然后用一张markdown表格整理每个文件的功能(包括{file_manifest})。'
|
102 |
-
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
103 |
-
yield chatbot, history, '正常'
|
104 |
-
|
105 |
-
if not fast_debug:
|
106 |
-
# ** gpt request **
|
107 |
-
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
108 |
-
|
109 |
-
chatbot[-1] = (i_say, gpt_say)
|
110 |
-
history.append(i_say); history.append(gpt_say)
|
111 |
-
yield chatbot, history, '正常'
|
112 |
-
res = write_results_to_file(history)
|
113 |
-
chatbot.append(("完成了吗?", res))
|
114 |
-
yield chatbot, history, '正常'
|
115 |
-
|
116 |
-
@CatchException
|
117 |
-
def 解析一个Python项目(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
118 |
-
history = [] # 清空历史,以免输入溢出
|
119 |
-
import glob, os
|
120 |
-
if os.path.exists(txt):
|
121 |
-
project_folder = txt
|
122 |
-
else:
|
123 |
-
if txt == "": txt = '空空如也的输入栏'
|
124 |
-
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
125 |
-
yield chatbot, history, '正常'
|
126 |
-
return
|
127 |
-
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)]
|
128 |
-
if len(file_manifest) == 0:
|
129 |
-
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
|
130 |
-
yield chatbot, history, '正常'
|
131 |
-
return
|
132 |
-
yield from 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
133 |
-
|
134 |
-
|
135 |
-
@CatchException
|
136 |
-
def 解析一个C项目的头文件(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
137 |
-
history = [] # 清空历史,以免输入溢出
|
138 |
-
import glob, os
|
139 |
-
if os.path.exists(txt):
|
140 |
-
project_folder = txt
|
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)] + \
|
148 |
-
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
149 |
-
if len(file_manifest) == 0:
|
150 |
-
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
|
151 |
-
yield chatbot, history, '正常'
|
152 |
-
return
|
153 |
-
yield from 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
154 |
-
|
155 |
|
156 |
def get_crazy_functionals():
|
157 |
from crazy_functions.读文章写摘要 import 读文章写摘要
|
158 |
from crazy_functions.生成函数注释 import 批量生成函数注释
|
|
|
|
|
|
|
|
|
159 |
|
160 |
return {
|
161 |
"[实验功能] 请解析并解构此项目本身": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
def get_crazy_functionals():
|
3 |
from crazy_functions.读文章写摘要 import 读文章写摘要
|
4 |
from crazy_functions.生成函数注释 import 批量生成函数注释
|
5 |
+
from crazy_functions.解析项目源代码 import 解析项目本身
|
6 |
+
from crazy_functions.解析项目源代码 import 解析一个Python项目
|
7 |
+
from crazy_functions.解析项目源代码 import 解析一个C项目的头文件
|
8 |
+
from crazy_functions.高级功能函数模板 import 高阶功能模板函数
|
9 |
|
10 |
return {
|
11 |
"[实验功能] 请解析并解构此项目本身": {
|
toolbox.py
CHANGED
@@ -1,7 +1,27 @@
|
|
1 |
-
import markdown, mdtex2html
|
2 |
from show_math import convert as convert_math
|
3 |
from functools import wraps
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def write_results_to_file(history, file_name=None):
|
6 |
"""
|
7 |
将对话记录history以Markdown格式写入文件中。如果没有指定文件名,则使用当前时间生成文件名。
|
|
|
1 |
+
import markdown, mdtex2html, threading
|
2 |
from show_math import convert as convert_math
|
3 |
from functools import wraps
|
4 |
|
5 |
+
def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[]):
|
6 |
+
"""
|
7 |
+
调用简单的predict_no_ui接口,但是依然保留了些许界面心跳功能
|
8 |
+
"""
|
9 |
+
import time
|
10 |
+
try: from config_private import TIMEOUT_SECONDS
|
11 |
+
except: from config import TIMEOUT_SECONDS
|
12 |
+
from predict import predict_no_ui
|
13 |
+
mutable = [None]
|
14 |
+
def mt(): mutable[0] = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
15 |
+
thread_name = threading.Thread(target=mt); thread_name.start()
|
16 |
+
cnt = 0
|
17 |
+
while thread_name.is_alive():
|
18 |
+
cnt += 1
|
19 |
+
chatbot[-1] = (i_say_show_user, f"[Local Message] waiting gpt response {cnt}/{TIMEOUT_SECONDS*2}"+''.join(['.']*(cnt%4)))
|
20 |
+
yield chatbot, history, '正常'
|
21 |
+
time.sleep(1)
|
22 |
+
gpt_say = mutable[0]
|
23 |
+
return gpt_say
|
24 |
+
|
25 |
def write_results_to_file(history, file_name=None):
|
26 |
"""
|
27 |
将对话记录history以Markdown格式写入文件中。如果没有指定文件名,则使用当前时间生成文件名。
|