Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
c924b6b
1
Parent(s):
293b255
new messages with raw-md toggle again
Browse files
modules/utils.py
CHANGED
@@ -265,7 +265,7 @@ def clip_rawtext(chat_message, need_escape=True):
|
|
265 |
return final_message
|
266 |
|
267 |
|
268 |
-
def convert_bot_before_marked(chat_message):
|
269 |
"""
|
270 |
注意不能给输出加缩进, 否则会被marked解析成代码块
|
271 |
"""
|
|
|
265 |
return final_message
|
266 |
|
267 |
|
268 |
+
def convert_bot_before_marked(chat_message): # deprecated after gradio 4.0
|
269 |
"""
|
270 |
注意不能给输出加缩进, 否则会被marked解析成代码块
|
271 |
"""
|
web_assets/javascript/ChuanhuChat.js
CHANGED
@@ -468,7 +468,7 @@ let ChuanhuInfo = function () {
|
|
468 |
*/
|
469 |
}
|
470 |
let description = `
|
471 |
-
© 2023 Chuanhu, MZhao, Keldos
|
472 |
GitHub repository: [https://github.com/GaiZhenbiao/ChuanhuChatGPT]\n
|
473 |
Enjoy our project!\n
|
474 |
`
|
|
|
468 |
*/
|
469 |
}
|
470 |
let description = `
|
471 |
+
© 2023 - 2024 Chuanhu, MZhao, Keldos
|
472 |
GitHub repository: [https://github.com/GaiZhenbiao/ChuanhuChatGPT]\n
|
473 |
Enjoy our project!\n
|
474 |
`
|
web_assets/javascript/message-button.js
CHANGED
@@ -1,24 +1,55 @@
|
|
1 |
|
2 |
// 为 bot 消息添加复制与切换显示按钮 以及最新消息加上重新生成,删除最新消息,嗯。
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
function addChuanhuButton(botElement) {
|
5 |
|
6 |
// botElement = botRow.querySelector('.message.bot');
|
7 |
var isLatestMessage = botElement.classList.contains('latest');
|
8 |
|
|
|
9 |
var rawMessage = botElement.querySelector('.raw-message');
|
10 |
var mdMessage = botElement.querySelector('.md-message');
|
11 |
|
12 |
-
if (!rawMessage) {
|
13 |
-
//
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
botElement.querySelector('.message
|
18 |
-
botElement.querySelector('.message
|
19 |
-
return;
|
20 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
// botElement.querySelectorAll('button.copy-bot-btn, button.toggle-md-btn').forEach(btn => btn.remove()); // 就算原先有了,也必须重新添加,而不是跳过
|
|
|
22 |
if (!isLatestMessage) botElement.querySelector('.message-btn-row')?.remove();
|
23 |
setLatestMessage();
|
24 |
|
|
|
1 |
|
2 |
// 为 bot 消息添加复制与切换显示按钮 以及最新消息加上重新生成,删除最新消息,嗯。
|
3 |
|
4 |
+
function convertBotMessage(gradioButtonMsg) {
|
5 |
+
var rawMessageStr = gradioButtonMsg.getAttribute('aria-label');
|
6 |
+
rawMessageStr = rawMessageStr.replace(/^bot's message: /, ''); // 去掉开头的“bot's message: ”
|
7 |
+
var insertChild = gradioButtonMsg.querySelector('.md');
|
8 |
+
|
9 |
+
var rawMessage = document.createElement('div');
|
10 |
+
rawMessage.classList.add('raw-message');
|
11 |
+
rawMessage.classList.add('hideM');
|
12 |
+
rawMessage.innerHTML = `<pre class="fake-pre">${rawMessageStr}</pre>`;
|
13 |
+
|
14 |
+
var mdMessage = document.createElement('div');
|
15 |
+
mdMessage.classList.add('md-message');
|
16 |
+
mdMessage.innerHTML = insertChild.innerHTML;
|
17 |
+
|
18 |
+
insertChild.innerHTML = '';
|
19 |
+
insertChild.appendChild(rawMessage);
|
20 |
+
insertChild.appendChild(mdMessage);
|
21 |
+
}
|
22 |
+
|
23 |
function addChuanhuButton(botElement) {
|
24 |
|
25 |
// botElement = botRow.querySelector('.message.bot');
|
26 |
var isLatestMessage = botElement.classList.contains('latest');
|
27 |
|
28 |
+
var gradioButtonMsg = botElement.querySelector('button[data-testid="bot"]');
|
29 |
var rawMessage = botElement.querySelector('.raw-message');
|
30 |
var mdMessage = botElement.querySelector('.md-message');
|
31 |
|
32 |
+
if (!rawMessage && !mdMessage) {
|
33 |
+
// 现在动态更新会导致 svelte.js 的 flush 出错,所以生成时不更新
|
34 |
+
if (chatbotIndicator.classList.contains('generating')) return;
|
35 |
+
|
36 |
+
convertBotMessage(gradioButtonMsg);
|
37 |
+
rawMessage = botElement.querySelector('.raw-message');
|
38 |
+
mdMessage = botElement.querySelector('.md-message');
|
|
|
39 |
}
|
40 |
+
// 没有办法,太早的版本就不管了。没有办法区分最早版本和适配gradio4版本。
|
41 |
+
|
42 |
+
// if (!rawMessage) { // 如果没有 raw message,说明是早期历史记录,去除按钮
|
43 |
+
// // var buttons = botElement.querySelectorAll('button.chuanhu-btn');
|
44 |
+
// // for (var i = 0; i < buttons.length; i++) {
|
45 |
+
// // buttons[i].parentNode.removeChild(buttons[i]);
|
46 |
+
// // }
|
47 |
+
// botElement.querySelector('.message-btn-row')?.remove();
|
48 |
+
// botElement.querySelector('.message-btn-column')?.remove();
|
49 |
+
// return;
|
50 |
+
// }
|
51 |
// botElement.querySelectorAll('button.copy-bot-btn, button.toggle-md-btn').forEach(btn => btn.remove()); // 就算原先有了,也必须重新添加,而不是跳过
|
52 |
+
|
53 |
if (!isLatestMessage) botElement.querySelector('.message-btn-row')?.remove();
|
54 |
setLatestMessage();
|
55 |
|
web_assets/stylesheet/chatbot.css
CHANGED
@@ -225,11 +225,11 @@ hr.append-display {
|
|
225 |
margin:0 !important;
|
226 |
}
|
227 |
.message .raw-message pre.fake-pre {
|
228 |
-
background: unset;
|
229 |
-
margin: unset;
|
230 |
-
font-size: unset;
|
231 |
/* font-family: unset; */
|
232 |
-
padding: unset;
|
233 |
white-space: inherit;
|
234 |
}
|
235 |
.message .raw-message {
|
|
|
225 |
margin:0 !important;
|
226 |
}
|
227 |
.message .raw-message pre.fake-pre {
|
228 |
+
background: unset !important;
|
229 |
+
margin: unset !important;
|
230 |
+
font-size: unset !important;
|
231 |
/* font-family: unset; */
|
232 |
+
padding: unset !important;
|
233 |
white-space: inherit;
|
234 |
}
|
235 |
.message .raw-message {
|
web_assets/stylesheet/markdown.css
CHANGED
@@ -1,23 +1,23 @@
|
|
1 |
|
2 |
/* 表格 */
|
3 |
-
.
|
4 |
margin: 1em 0;
|
5 |
border-collapse: collapse;
|
6 |
empty-cells: show;
|
7 |
}
|
8 |
-
.
|
9 |
border: 1.2px solid var(--border-color-primary) !important;
|
10 |
padding: 0.2em;
|
11 |
}
|
12 |
-
.
|
13 |
background-color: rgba(175,184,193,0.2);
|
14 |
}
|
15 |
-
.
|
16 |
padding: .5em .2em;
|
17 |
}
|
18 |
|
19 |
/* 行内代码 */
|
20 |
-
.
|
21 |
display: inline;
|
22 |
white-space: break-spaces;
|
23 |
font-family: var(--font-mono) !important;
|
@@ -29,8 +29,8 @@
|
|
29 |
font-size: var(--text-md) !important;
|
30 |
}
|
31 |
/* 代码块 */
|
32 |
-
.
|
33 |
-
.
|
34 |
color: #fff;
|
35 |
overflow-x: auto;
|
36 |
overflow-y: hidden;
|
@@ -38,8 +38,8 @@
|
|
38 |
border-radius: var(--radius-lg) !important;
|
39 |
background: var(--neutral-950) !important;
|
40 |
}
|
41 |
-
.
|
42 |
-
.
|
43 |
color: #fff;
|
44 |
padding: 0;
|
45 |
margin: 0;
|
@@ -48,7 +48,7 @@
|
|
48 |
font-family: var(--font-mono);
|
49 |
font-size: var(--text-md);
|
50 |
}
|
51 |
-
.
|
52 |
margin: .8em 1em 1em 0em;
|
53 |
}
|
54 |
|
|
|
1 |
|
2 |
/* 表格 */
|
3 |
+
.message table {
|
4 |
margin: 1em 0;
|
5 |
border-collapse: collapse;
|
6 |
empty-cells: show;
|
7 |
}
|
8 |
+
.message td, .message th {
|
9 |
border: 1.2px solid var(--border-color-primary) !important;
|
10 |
padding: 0.2em;
|
11 |
}
|
12 |
+
.message thead {
|
13 |
background-color: rgba(175,184,193,0.2);
|
14 |
}
|
15 |
+
.message thead th {
|
16 |
padding: .5em .2em;
|
17 |
}
|
18 |
|
19 |
/* 行内代码 */
|
20 |
+
.message :not(pre) > code {
|
21 |
display: inline;
|
22 |
white-space: break-spaces;
|
23 |
font-family: var(--font-mono) !important;
|
|
|
29 |
font-size: var(--text-md) !important;
|
30 |
}
|
31 |
/* 代码块 */
|
32 |
+
.message pre,
|
33 |
+
.message pre[class*=language-] {
|
34 |
color: #fff;
|
35 |
overflow-x: auto;
|
36 |
overflow-y: hidden;
|
|
|
38 |
border-radius: var(--radius-lg) !important;
|
39 |
background: var(--neutral-950) !important;
|
40 |
}
|
41 |
+
.message pre code,
|
42 |
+
.message pre code[class*=language-] {
|
43 |
color: #fff;
|
44 |
padding: 0;
|
45 |
margin: 0;
|
|
|
48 |
font-family: var(--font-mono);
|
49 |
font-size: var(--text-md);
|
50 |
}
|
51 |
+
.message .code_wrap {
|
52 |
margin: .8em 1em 1em 0em;
|
53 |
}
|
54 |
|