This commit is contained in:
yumoqing 2024-04-16 11:26:06 +08:00
parent a17d7f7a94
commit bff3e1726c

View File

@ -1,5 +1,18 @@
var bricks = window.bricks || {}
bricks.escapeSpecialChars = function(s){
return s
.replace(/\\/g, '\\\\') // escape backslashes
.replace(/"/g, '\\"') // escape double quotes
// .replace(/'/g, '\\\'') // escape single quotes
.replace(/\n/g, '\\n') // escape newlines
.replace(/\r/g, '\\r') // escape carriage returns
.replace(/\t/g, '\\t') // escape tabs
.replace(/\f/g, '\\f') // escape form feeds
.replace(/\v/g, '\\v') // escape vertical tabs
.replace(/\0/g, '\\0'); // escape null bytes
}
bricks.UserMsgBox = class extends bricks.HBox {
/*
{
@ -65,7 +78,9 @@ bricks.LlmMsgBox = class extends bricks.HBox {
}
chunk_ended(){
var msg = this.llm_msg_format();
var lmsg = bricks.apply_data(msg, {content:this.w.md_content});
var txt = this.w.md_content;
txt = bricks.escapeSpecialChars(txt);
var lmsg = bricks.apply_data(msg, {content:txt});
this.messages.push(lmsg);
}
async set_prompt(prompt){
@ -145,6 +160,7 @@ bricks.LlmDialog = class extends bricks.VBox {
this.add_widget(filler);
}
async set_prompt(prompt){
prompt = bricks.escapeSpecialChars(prompt);
var box = new bricks.UserMsgBox({
width:'100%',
icon:this.user_icon,