Spaces:
Running
Running
易读性+
Browse files- functional_crazy.py +51 -56
functional_crazy.py
CHANGED
@@ -2,61 +2,6 @@ from predict import predict_no_ui
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file
|
3 |
fast_debug = False
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
@CatchException
|
8 |
-
def 高阶功能模板函数(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
9 |
-
history = [] # 清空历史,以免输入溢出
|
10 |
-
for i in range(5):
|
11 |
-
i_say = f'我给出一个数字,你给出该数字的平方。我给出数字:{i}'
|
12 |
-
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
13 |
-
yield chatbot, history, '正常' # 由于请求gpt需要一段时间,我们先及时地做一次状态显示
|
14 |
-
|
15 |
-
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature) # 请求gpt,需要一段时间
|
16 |
-
|
17 |
-
chatbot[-1] = (i_say, gpt_say)
|
18 |
-
history.append(i_say);history.append(gpt_say)
|
19 |
-
yield chatbot, history, '正常' # 显示
|
20 |
-
|
21 |
-
|
22 |
-
@CatchException
|
23 |
-
def 解析项目本身(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
24 |
-
history = [] # 清空历史,以免输入溢出
|
25 |
-
import time, glob, os
|
26 |
-
file_manifest = [f for f in glob.glob('*.py')]
|
27 |
-
for index, fp in enumerate(file_manifest):
|
28 |
-
with open(fp, 'r', encoding='utf-8') as f:
|
29 |
-
file_content = f.read()
|
30 |
-
|
31 |
-
前言 = "接下来请你分析自己的程序构成,别紧张," if index==0 else ""
|
32 |
-
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{fp},文件代码是 ```{file_content}```'
|
33 |
-
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
|
34 |
-
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
35 |
-
yield chatbot, history, '正常'
|
36 |
-
|
37 |
-
if not fast_debug:
|
38 |
-
# ** gpt request **
|
39 |
-
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature)
|
40 |
-
|
41 |
-
chatbot[-1] = (i_say_show_user, gpt_say)
|
42 |
-
history.append(i_say_show_user); history.append(gpt_say)
|
43 |
-
yield chatbot, history, '正常'
|
44 |
-
time.sleep(2)
|
45 |
-
|
46 |
-
i_say = f'根据以上你自己的分析,对程序的整体功能和构架做出概括。然后用一张markdown表格整理每个文件的功能(包括{file_manifest})。'
|
47 |
-
chatbot.append((i_say, "[Local Message] waiting gpt response."))
|
48 |
-
yield chatbot, history, '正常'
|
49 |
-
|
50 |
-
if not fast_debug:
|
51 |
-
# ** gpt request **
|
52 |
-
gpt_say = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
53 |
-
|
54 |
-
chatbot[-1] = (i_say, gpt_say)
|
55 |
-
history.append(i_say); history.append(gpt_say)
|
56 |
-
yield chatbot, history, '正常'
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
def 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt):
|
61 |
import time, glob, os
|
62 |
print('begin analysis on:', file_manifest)
|
@@ -114,6 +59,57 @@ def 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot,
|
|
114 |
chatbot.append(("完成了吗?", res))
|
115 |
yield chatbot, history, msg
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
@CatchException
|
119 |
def 解析一个Python项目(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
@@ -183,7 +179,6 @@ def get_crazy_functionals():
|
|
183 |
"Color": "stop", # 按钮颜色
|
184 |
"Function": 高阶功能模板函数
|
185 |
},
|
186 |
-
|
187 |
}
|
188 |
|
189 |
|
|
|
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)
|
|
|
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 |
+
|
113 |
|
114 |
@CatchException
|
115 |
def 解析一个Python项目(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
|
|
179 |
"Color": "stop", # 按钮颜色
|
180 |
"Function": 高阶功能模板函数
|
181 |
},
|
|
|
182 |
}
|
183 |
|
184 |
|