Spaces:
Runtime error
Runtime error
JohnSmith9982
commited on
Commit
·
ec7d4a0
1
Parent(s):
a55ec1c
Upload 8 files
Browse files- app.py +8 -1
- modules/llama_func.py +4 -2
- modules/utils.py +10 -0
app.py
CHANGED
@@ -92,7 +92,8 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
92 |
"🧹 新的对话",
|
93 |
)
|
94 |
retryBtn = gr.Button("🔄 重新生成")
|
95 |
-
|
|
|
96 |
reduceTokenBtn = gr.Button("♻️ 总结对话")
|
97 |
|
98 |
with gr.Column():
|
@@ -306,6 +307,12 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
306 |
)
|
307 |
retryBtn.click(**get_usage_args)
|
308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
delLastBtn.click(
|
310 |
delete_last_conversation,
|
311 |
[chatbot, history, token_count],
|
|
|
92 |
"🧹 新的对话",
|
93 |
)
|
94 |
retryBtn = gr.Button("🔄 重新生成")
|
95 |
+
delFirstBtn = gr.Button("🗑️ 删除最旧对话")
|
96 |
+
delLastBtn = gr.Button("🗑️ 删除最新对话")
|
97 |
reduceTokenBtn = gr.Button("♻️ 总结对话")
|
98 |
|
99 |
with gr.Column():
|
|
|
307 |
)
|
308 |
retryBtn.click(**get_usage_args)
|
309 |
|
310 |
+
delFirstBtn.click(
|
311 |
+
delete_first_conversation,
|
312 |
+
[history, token_count],
|
313 |
+
[history, token_count, status_display],
|
314 |
+
)
|
315 |
+
|
316 |
delLastBtn.click(
|
317 |
delete_last_conversation,
|
318 |
[chatbot, history, token_count],
|
modules/llama_func.py
CHANGED
@@ -17,9 +17,11 @@ from modules.presets import *
|
|
17 |
from modules.utils import *
|
18 |
|
19 |
def get_index_name(file_src):
|
20 |
-
index_name =
|
21 |
for file in file_src:
|
22 |
-
index_name
|
|
|
|
|
23 |
index_name = sha1sum(index_name)
|
24 |
return index_name
|
25 |
|
|
|
17 |
from modules.utils import *
|
18 |
|
19 |
def get_index_name(file_src):
|
20 |
+
index_name = []
|
21 |
for file in file_src:
|
22 |
+
index_name.append(os.path.basename(file.name))
|
23 |
+
index_name = sorted(index_name)
|
24 |
+
index_name = "".join(index_name)
|
25 |
index_name = sha1sum(index_name)
|
26 |
return index_name
|
27 |
|
modules/utils.py
CHANGED
@@ -153,6 +153,16 @@ def construct_assistant(text):
|
|
153 |
def construct_token_message(token, stream=False):
|
154 |
return f"Token 计数: {token}"
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
def delete_last_conversation(chatbot, history, previous_token_count):
|
158 |
if len(chatbot) > 0 and standard_error_msg in chatbot[-1][1]:
|
|
|
153 |
def construct_token_message(token, stream=False):
|
154 |
return f"Token 计数: {token}"
|
155 |
|
156 |
+
def delete_first_conversation(history, previous_token_count):
|
157 |
+
if history:
|
158 |
+
del history[:2]
|
159 |
+
del previous_token_count[0]
|
160 |
+
return (
|
161 |
+
history,
|
162 |
+
previous_token_count,
|
163 |
+
construct_token_message(sum(previous_token_count)),
|
164 |
+
)
|
165 |
+
|
166 |
|
167 |
def delete_last_conversation(chatbot, history, previous_token_count):
|
168 |
if len(chatbot) > 0 and standard_error_msg in chatbot[-1][1]:
|