Spaces:
Sleeping
Sleeping
Keldos commited on
Commit ·
856fe04
1
Parent(s): da0fe02
feat: 调整助理思考显示样式
Browse files- assets/custom.css +12 -0
- assets/custom.js +2 -1
- modules/models/base_model.py +1 -1
- modules/utils.py +26 -8
assets/custom.css
CHANGED
|
@@ -538,6 +538,18 @@ ol:not(.options), ul:not(.options) {
|
|
| 538 |
display: none;
|
| 539 |
}
|
| 540 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
/* custom buttons */
|
| 542 |
.chuanhu-btn {
|
| 543 |
border-radius: 5px;
|
|
|
|
| 538 |
display: none;
|
| 539 |
}
|
| 540 |
|
| 541 |
+
/* 川虎助理 */
|
| 542 |
+
.agent-prefix {
|
| 543 |
+
font-size: smaller;
|
| 544 |
+
opacity: 0.6;
|
| 545 |
+
padding: 6px 0 4px;
|
| 546 |
+
}
|
| 547 |
+
.agent-prefix::before {
|
| 548 |
+
content: '🐯';
|
| 549 |
+
filter: grayscale();
|
| 550 |
+
padding: 0 4px;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
/* custom buttons */
|
| 554 |
.chuanhu-btn {
|
| 555 |
border-radius: 5px;
|
assets/custom.js
CHANGED
|
@@ -439,7 +439,8 @@ function addChuanhuButton(botElement) {
|
|
| 439 |
const gradio_clipboard_content = await navigator.clipboard.readText();
|
| 440 |
const regex = /<!-- SOO IN MESSAGE --><div class="really-raw hideM">([\s\S]*?)\n<\/div><!-- EOO IN MESSAGE -->/;
|
| 441 |
const real_raw_message = gradio_clipboard_content.match(regex)[1];
|
| 442 |
-
|
|
|
|
| 443 |
// console.log("Copied from gradio's clipboard");
|
| 444 |
} catch (error) {
|
| 445 |
await navigator.clipboard.writeText(textToCopy);
|
|
|
|
| 439 |
const gradio_clipboard_content = await navigator.clipboard.readText();
|
| 440 |
const regex = /<!-- SOO IN MESSAGE --><div class="really-raw hideM">([\s\S]*?)\n<\/div><!-- EOO IN MESSAGE -->/;
|
| 441 |
const real_raw_message = gradio_clipboard_content.match(regex)[1];
|
| 442 |
+
const after_agent_prefix = str.replace(/<!-- S O PREFIX --><p class="agent-prefix">(.+?)<\/p><!-- E O PREFIX -->/g, '$1\n');
|
| 443 |
+
await navigator.clipboard.writeText(after_agent_prefix)
|
| 444 |
// console.log("Copied from gradio's clipboard");
|
| 445 |
} catch (error) {
|
| 446 |
await navigator.clipboard.writeText(textToCopy);
|
modules/models/base_model.py
CHANGED
|
@@ -77,7 +77,7 @@ def get_action_description(text):
|
|
| 77 |
action_name = json_dict['action']
|
| 78 |
action_input = json_dict['action_input']
|
| 79 |
if action_name != "Final Answer":
|
| 80 |
-
return f'<p
|
| 81 |
else:
|
| 82 |
return ""
|
| 83 |
|
|
|
|
| 77 |
action_name = json_dict['action']
|
| 78 |
action_input = json_dict['action_input']
|
| 79 |
if action_name != "Final Answer":
|
| 80 |
+
return f'<!-- S O PREFIX --><p class="agent-prefix">{action_name}: {action_input}</p><!-- E O PREFIX -->'
|
| 81 |
else:
|
| 82 |
return ""
|
| 83 |
|
modules/utils.py
CHANGED
|
@@ -206,6 +206,28 @@ def convert_mdtext(md_text): # deprecated
|
|
| 206 |
output += ALREADY_CONVERTED_MARK
|
| 207 |
return output
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
def convert_bot_before_marked(chat_message):
|
| 210 |
"""
|
| 211 |
注意不能给输出加缩进, 否则会被marked解析成代码块
|
|
@@ -213,16 +235,13 @@ def convert_bot_before_marked(chat_message):
|
|
| 213 |
if '<div class="md-message">' in chat_message:
|
| 214 |
return chat_message
|
| 215 |
else:
|
|
|
|
|
|
|
|
|
|
| 216 |
code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
|
| 217 |
code_blocks = code_block_pattern.findall(chat_message)
|
| 218 |
non_code_parts = code_block_pattern.split(chat_message)[::2]
|
| 219 |
-
result = []
|
| 220 |
-
|
| 221 |
-
hr_pattern = r'\n\n<hr class="append-display no-in-raw" />(.*?)'
|
| 222 |
-
hr_match = re.search(hr_pattern, chat_message, re.DOTALL)
|
| 223 |
-
clip_hr = chat_message[:hr_match.start()] if hr_match else chat_message
|
| 224 |
-
|
| 225 |
-
raw = f'<div class="raw-message hideM">{escape_markdown(clip_hr)}</div>'
|
| 226 |
for non_code, code in zip(non_code_parts, code_blocks + [""]):
|
| 227 |
if non_code.strip():
|
| 228 |
result.append(non_code)
|
|
@@ -231,7 +250,6 @@ def convert_bot_before_marked(chat_message):
|
|
| 231 |
result.append(code)
|
| 232 |
result = "".join(result)
|
| 233 |
md = f'<div class="md-message">{result}\n</div>'
|
| 234 |
-
really_raw = f'{START_OF_OUTPUT_MARK}<div class="really-raw hideM">{clip_hr}\n</div>{END_OF_OUTPUT_MARK}'
|
| 235 |
return raw + md + really_raw
|
| 236 |
|
| 237 |
def convert_user_before_marked(chat_message):
|
|
|
|
| 206 |
output += ALREADY_CONVERTED_MARK
|
| 207 |
return output
|
| 208 |
|
| 209 |
+
|
| 210 |
+
def clip_rawtext(chat_message, need_escape=True):
|
| 211 |
+
# first, clip hr line
|
| 212 |
+
hr_pattern = r'\n\n<hr class="append-display no-in-raw" />(.*?)'
|
| 213 |
+
hr_match = re.search(hr_pattern, chat_message, re.DOTALL)
|
| 214 |
+
message_clipped = chat_message[:hr_match.start()] if hr_match else chat_message
|
| 215 |
+
# second, avoid agent-prefix being escaped
|
| 216 |
+
agent_prefix_pattern = r'<!-- S O PREFIX --><p class="agent-prefix">(.*?)<\/p><!-- E O PREFIX -->'
|
| 217 |
+
agent_matches = re.findall(agent_prefix_pattern, message_clipped)
|
| 218 |
+
final_message = ""
|
| 219 |
+
if agent_matches:
|
| 220 |
+
agent_parts = re.split(agent_prefix_pattern, message_clipped)
|
| 221 |
+
for i, part in enumerate(agent_parts):
|
| 222 |
+
if i % 2 == 0:
|
| 223 |
+
final_message += escape_markdown(part) if need_escape else part
|
| 224 |
+
else:
|
| 225 |
+
final_message += f'<!-- S O PREFIX --><p class="agent-prefix">{part}</p><!-- E O PREFIX -->'
|
| 226 |
+
else:
|
| 227 |
+
final_message = escape_markdown(message_clipped) if need_escape else message_clipped
|
| 228 |
+
return final_message
|
| 229 |
+
|
| 230 |
+
|
| 231 |
def convert_bot_before_marked(chat_message):
|
| 232 |
"""
|
| 233 |
注意不能给输出加缩进, 否则会被marked解析成代码块
|
|
|
|
| 235 |
if '<div class="md-message">' in chat_message:
|
| 236 |
return chat_message
|
| 237 |
else:
|
| 238 |
+
raw = f'<div class="raw-message hideM">{clip_rawtext(chat_message)}</div>'
|
| 239 |
+
really_raw = f'{START_OF_OUTPUT_MARK}<div class="really-raw hideM">{clip_rawtext(chat_message, need_escape=False)}\n</div>{END_OF_OUTPUT_MARK}'
|
| 240 |
+
|
| 241 |
code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
|
| 242 |
code_blocks = code_block_pattern.findall(chat_message)
|
| 243 |
non_code_parts = code_block_pattern.split(chat_message)[::2]
|
| 244 |
+
result = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
for non_code, code in zip(non_code_parts, code_blocks + [""]):
|
| 246 |
if non_code.strip():
|
| 247 |
result.append(non_code)
|
|
|
|
| 250 |
result.append(code)
|
| 251 |
result = "".join(result)
|
| 252 |
md = f'<div class="md-message">{result}\n</div>'
|
|
|
|
| 253 |
return raw + md + really_raw
|
| 254 |
|
| 255 |
def convert_user_before_marked(chat_message):
|