This commit is contained in:
yumoqing 2024-07-31 16:06:49 +08:00
parent d3b1a1f75b
commit 03179fa970
3 changed files with 26 additions and 20 deletions

View File

@ -94,7 +94,7 @@ bricks.HttpText = class {
var data = this.add_own_params(params); var data = this.add_own_params(params);
var header = this.add_own_headers(headers); var header = this.add_own_headers(headers);
var _params = { var _params = {
"method":method, method:method
} }
// _params.headers = headers; // _params.headers = headers;
if (method == 'GET' || method == 'HEAD') { if (method == 'GET' || method == 'HEAD') {

View File

@ -57,7 +57,7 @@ bricks.ModelOutput = class extends bricks.HBox {
var icon = event.target.bricks_widget; var icon = event.target.bricks_widget;
icon.rate = 2; icon.rate = 2;
icon.charsize_sizing(); icon.charsize_sizing();
w = await bricks.widgetBuild(desc, this); var w = await bricks.widgetBuild(desc, this);
this.estimate_w.disabled(true); this.estimate_w.disabled(true);
} }
async update_data(data){ async update_data(data){
@ -65,6 +65,7 @@ bricks.ModelOutput = class extends bricks.HBox {
this.run.stop_timepass(); this.run.stop_timepass();
this.remove_widget(this.run); this.remove_widget(this.run);
} }
console.log('update_data():data=', data);
this.run = null; this.run = null;
var w = await bricks.widgetBuild(this.output_view, this.llmio, data); var w = await bricks.widgetBuild(this.output_view, this.llmio, data);
w.set_css('llm_msg'); w.set_css('llm_msg');
@ -140,7 +141,7 @@ bricks.LlmModel = class extends bricks.JsWidget {
d.modeltypeid = this.opts.modeltypeid; d.modeltypeid = this.opts.modeltypeid;
} }
console.log('upload data=', d, this.options); console.log('upload data=', d, this.options);
if (this.response_mode == 'stream') { if (this.response_mode == 'stream' || this.response_mode == 'async') {
var hr = new bricks.HttpResponseStream(); var hr = new bricks.HttpResponseStream();
var resp = await hr.post(this.opts.url, {params:d}); var resp = await hr.post(this.opts.url, {params:d});
await hr.handle_chunk(resp, this.chunk_response.bind(this, mout)); await hr.handle_chunk(resp, this.chunk_response.bind(this, mout));
@ -177,6 +178,7 @@ bricks.LlmModel = class extends bricks.JsWidget {
d.content = bricks.escapeSpecialChars(d.content); d.content = bricks.escapeSpecialChars(d.content);
this.resp_data = d; this.resp_data = d;
mout.update_data(d); mout.update_data(d);
console.log('stream data=', d);
} }
chunk_ended(){ chunk_ended(){
if (! this.messages) { if (! this.messages) {

View File

@ -39,7 +39,6 @@ bricks.Video = class extends bricks.Layout {
this.hidedbtn = new bricks.Button({text:'click me'}); this.hidedbtn = new bricks.Button({text:'click me'});
this.hidedbtn.hide(); this.hidedbtn.hide();
this.add_widget(this.hidedbtn); this.add_widget(this.hidedbtn);
this.hidedbtn.bind('click', this.play.bind(this));
} }
destroy_resource(params, event){ destroy_resource(params, event){
var w = event.target.bricks_widget; var w = event.target.bricks_widget;
@ -61,25 +60,26 @@ bricks.Video = class extends bricks.Layout {
} }
} }
auto_play(){ auto_play(){
this.hidedbtn.dispatch('click');
schedule_once(this.disable_captions.bind(this), 2); schedule_once(this.disable_captions.bind(this), 2);
this.player.on('error',this.report_error.bind(this)); this.player.on('error',this.report_error.bind(this));
this.player.on('play', this.report_playok.bind(this)); this.player.on('play', this.report_playok.bind(this));
this.player.on('ended', this.report_ended.bind(this)); this.player.on('ended', this.report_ended.bind(this));
this.hidedbtn.dispatch('click');
} }
play(){ play(){
this.player.play(); this.player.play();
} }
create_player(){ create_player(){
if(this.url){
this.player = videojs(this.video_body.dom_element, { this.player = videojs(this.video_body.dom_element, {
controls:true, controls:true,
nativeTextTracks:false, nativeTextTracks:false,
textTrackSettings: false textTrackSettings: false
}); });
this.player.ready(this.auto_play.bind(this)); this.player.ready(this.auto_play.bind(this));
this._set_source(); this._set_source();
} }
}
report_ended(){ report_ended(){
this.dispatch('play_end',{src:this.video_body.cur_url,type:this.video_body.cur_vtype}); this.dispatch('play_end',{src:this.video_body.cur_url,type:this.video_body.cur_vtype});
} }
@ -92,16 +92,20 @@ bricks.Video = class extends bricks.Layout {
this.dispatch('play_failed', {'src':this.video_body.cur_url, type:this.video_body.cur_vtype}); this.dispatch('play_failed', {'src':this.video_body.cur_url, type:this.video_body.cur_vtype});
} }
_set_source(){ _set_source(){
if (this.player){
this.player.src({ this.player.src({
src:this.video_body.cur_url, src:this.video_body.cur_url,
type:this.video_body.cur_vtype type:this.video_body.cur_vtype
}); });
} }
}
set_source(url, vtype){ set_source(url, vtype){
if(this.player){
this.video_body.cur_url = url; this.video_body.cur_url = url;
this.video_body.cur_vtype = vtype; this.video_body.cur_vtype = vtype;
this._set_source(); this._set_source();
} }
} }
}
bricks.Factory.register('Video', bricks.Video); bricks.Factory.register('Video', bricks.Video);