Compare commits

..

No commits in common. "b46c82b402ad73108e6962d5eeb9731633544651" and "b43d2e7cbd25efd89ef2242dc6a285b0062a9e5d" have entirely different histories.

View File

@ -77,54 +77,17 @@ bricks.LlmOut = class extends bricks.VBox {
super(opts); super(opts);
this.rc_w = null; this.rc_w = null;
this.c_w = null; this.c_w = null;
this.v_w = null;
this.i_w = null;
this.a_w = null;
this.glb_w = null;
this.s_w = null; // 状态 this.s_w = null; // 状态
this.glbs = [];
this.videos = [];
this.audios = []
this.images = []; this.images = [];
this.reasoning_content = ''; this.reasoning_content = '';
this.content = ''; this.content = '';
this.error = ''; this.error = '';
} }
render_video(v){
var w = new bricks.VideoPlayer({
width: '100%',
url: v,
autoplay: true
});
this.add_widget(w);
}
render_glb(glb){
var w = new bricks.GlbViewer({
url:glb,
width: '100%'
});
this.add_widget(w);
}
render_audio(a){
var url = a;
if (! url.startsWith('http')){
if (! url.startsWith('data:audio/')){
url = 'data:audio/wav;base64,' + url;
}
}
var w = new bricks.AudioPlayer({
width: '100%',
autoplay: true,
url: url,
cheight:2
});
}
this.add_widget(w);
}
render_image(i){
var w = new bricks.Image({
width: '100%',
url: i
});
this.add_widget(w);
}
update(data){ update(data){
if (data.status){ if (data.status){
this.s_w = new bricks.Text({ this.s_w = new bricks.Text({
@ -134,31 +97,38 @@ bricks.LlmOut = class extends bricks.VBox {
}); });
} }
if (data.audio){ if (data.audio){
if (Array.isArray(data.audio)){ var url = data.audio;
this.audios.concat(data.audio); if (! data.audio.startsWith('http')){
if (! data.audio.startsWith('data:audio/')){
url = 'data:audio/wav;base64,' + url;
}
}
if (!this.a_w) {
this.a_w = new bricks.AudioPlayer({
width: '100%',
autoplay: true,
url: url,
cheight:2
});
} else { } else {
this.audios.push(data.audio); this.a_w.add_url(url);
} }
} }
if (data.glb){ if (data.glb){
if (Array.isArray(data.glb)){ this.glb_w = new bricks.GlbViewer({
this.glbs.concat(data.glb); url:data.glb,
} else { width: '100%'
this.glbs.push(data.glb); });
}
} }
if (data.video){ if (data.video){
if (Array.isArray(data.video)){ if (!this.v_w){
this.videos.concat(data.video); this.v_w = new bricks.VideoPlayer({
width: '100%',
url: data.video,
autoplay: true
});
} else { } else {
this.videos.push(data.video); this.v_w.add_url(data.video);
}
}
if (data.image){
if (Array.isArray(data.image)){
this.images.concat(data.image);
} else {
this.images.push(data.image);
} }
} }
if (data.error){ if (data.error){
@ -170,6 +140,13 @@ bricks.LlmOut = class extends bricks.VBox {
if (data.content){ if (data.content){
this.content += data.content; this.content += data.content;
} }
if (data.image){
if (Array.isArray(data.image)){
this.images.concat(data.image);
} else {
this.images.push(data.image);
}
}
this.clear_widgets(); this.clear_widgets();
if (this.error.length) { if (this.error.length) {
var txt = bricks.escapeSpecialChars(this.error); var txt = bricks.escapeSpecialChars(this.error);
@ -201,17 +178,23 @@ bricks.LlmOut = class extends bricks.VBox {
}); });
this.add_widget(this.c_w); this.add_widget(this.c_w);
} }
this.videos.forEach(v => { if (this.v_w) {
this.render_video(v); this.add_widget(this.v_w);
})
this.glbs.forEach(glb => {
this.render_glb(glb);
} }
this.audios.forEach(a => { if (this.glb_w){
this.render_audio(a); this.add_widget(this.glb_w);
} }
this.imges.forEach(i => { if (this.a_w) {
this.render_image(i); this.add_widget(this.a_w);
}
if (this.images.length){
this.images.forEach( i => {
var w = new bricks.Image({
width: '100%',
url: i
});
this.add_widget(w)
});
} }
if(this.s_w){ if(this.s_w){
this.add_widget(this.s_w); this.add_widget(this.s_w);