bugfix
This commit is contained in:
parent
24ba4a0842
commit
f581fc9b23
@ -208,26 +208,43 @@ bricks.LlmModel = class extends bricks.JsWidget {
|
|||||||
estimate_url:this.llmio.estimate_url
|
estimate_url:this.llmio.estimate_url
|
||||||
});
|
});
|
||||||
this.llmio.o_w.add_widget(mout);
|
this.llmio.o_w.add_widget(mout);
|
||||||
if (this.response_mode == 'stream' || this.response_mode == 'async') {
|
switch (this.response_mode) {
|
||||||
var d = this.inputdata2uploaddata(data);
|
case 'async':
|
||||||
var hr = new bricks.HttpResponseStream();
|
var d = this.inputdata2uploaddata(data);
|
||||||
var resp = await hr.post(this.opts.url, {params:d});
|
console.log('data_inouted=', data, 'upload_data=', d);
|
||||||
if (! resp) {
|
var hj = new bricks.HttpJson()
|
||||||
mout.run_stopped();
|
var resp = await hj.post(this.opts.url, {params:d});
|
||||||
return;
|
if (! resp) {
|
||||||
}
|
mout.run_stopped();
|
||||||
await hr.handle_chunk(resp, this.chunk_response.bind(this, mout));
|
return;
|
||||||
this.chunk_ended();
|
}
|
||||||
} else {
|
mout.update_data(resp);
|
||||||
var d = this.inputdata2uploaddata(data);
|
if (resp.status == 'FAILED'){
|
||||||
console.log('data_inouted=', data, 'upload_data=', d);
|
return;
|
||||||
var hj = new bricks.HttpJson()
|
}
|
||||||
var resp = await hj.post(this.opts.url, {params:d});
|
this.query_task_status(mout, resp.taskid)
|
||||||
if (! resp) {
|
break;
|
||||||
mout.run_stopped();
|
case 'stream':
|
||||||
return;
|
var d = this.inputdata2uploaddata(data);
|
||||||
}
|
var hr = new bricks.HttpResponseStream();
|
||||||
mout.update_data(resp);
|
var resp = await hr.post(this.opts.url, {params:d});
|
||||||
|
if (! resp) {
|
||||||
|
mout.run_stopped();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await hr.handle_chunk(resp, this.chunk_response.bind(this, mout));
|
||||||
|
this.chunk_ended();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
var d = this.inputdata2uploaddata(data);
|
||||||
|
console.log('data_inouted=', data, 'upload_data=', d);
|
||||||
|
var hj = new bricks.HttpJson()
|
||||||
|
var resp = await hj.post(this.opts.url, {params:d});
|
||||||
|
if (! resp) {
|
||||||
|
mout.run_stopped();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mout.update_data(resp);
|
||||||
}
|
}
|
||||||
mout.estimate_w.show();
|
mout.estimate_w.show();
|
||||||
}
|
}
|
||||||
@ -240,6 +257,22 @@ bricks.LlmModel = class extends bricks.JsWidget {
|
|||||||
llm_msg_format(){
|
llm_msg_format(){
|
||||||
return this.llm_message_format || {role:'assistant', content:"${content}"}
|
return this.llm_message_format || {role:'assistant', content:"${content}"}
|
||||||
}
|
}
|
||||||
|
query_task_status(mout, taskid){
|
||||||
|
var pt = this.opts.period_time || 30;
|
||||||
|
if (this.query_task) {
|
||||||
|
this.query_task.cancel()
|
||||||
|
}
|
||||||
|
var hj = new bricks.HttpJson()
|
||||||
|
var resp = await hj.post(this.opts.url, {params:d});
|
||||||
|
if (! resp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mout.update_data(resp)
|
||||||
|
if (resp.status == 'FAILED' || resp.status == 'SUCCEEDED'){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
schedule_once(this.query_task_status.bind(this, mout, taskid), pt)
|
||||||
|
}
|
||||||
chunk_response(mout, l){
|
chunk_response(mout, l){
|
||||||
l = l.trim();
|
l = l.trim();
|
||||||
try {
|
try {
|
||||||
@ -249,9 +282,8 @@ bricks.LlmModel = class extends bricks.JsWidget {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.opts.response_mode == 'async'){
|
if (this.opts.response_mode == 'async'){
|
||||||
if(d.status != 'SUCCEEDED' && d.status != 'FAILED' ){
|
if (d.taskid){
|
||||||
console.log('filter all message not successed or failed', d);
|
this.query_task_status(mout, d.taskid)
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('l=', l, 'd=', d);
|
console.log('l=', l, 'd=', d);
|
||||||
|
|||||||
@ -81,6 +81,7 @@ bricks.LlmOut = class extends bricks.VBox {
|
|||||||
this.i_w = null;
|
this.i_w = null;
|
||||||
this.a_w = null;
|
this.a_w = null;
|
||||||
this.glb_w = null;
|
this.glb_w = null;
|
||||||
|
this.s_w = null; // 状态
|
||||||
this.images = [];
|
this.images = [];
|
||||||
this.reasoning_content = '';
|
this.reasoning_content = '';
|
||||||
this.content = '';
|
this.content = '';
|
||||||
@ -88,6 +89,13 @@ bricks.LlmOut = class extends bricks.VBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(data){
|
update(data){
|
||||||
|
if (data.status){
|
||||||
|
this.s_w = new bricks.Text({
|
||||||
|
width: '100%',
|
||||||
|
height: 'auto',
|
||||||
|
text: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
}
|
||||||
if (data.audio){
|
if (data.audio){
|
||||||
var url = data.audio;
|
var url = data.audio;
|
||||||
if (! data.audio.startsWith('http')){
|
if (! data.audio.startsWith('http')){
|
||||||
@ -188,6 +196,9 @@ bricks.LlmOut = class extends bricks.VBox {
|
|||||||
this.add_widget(w)
|
this.add_widget(w)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if(this.s_w){
|
||||||
|
this.add_widget(this.s_w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bricks.Factory.register('LlmOut', bricks.LlmOut);
|
bricks.Factory.register('LlmOut', bricks.LlmOut);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user