bugfix
This commit is contained in:
parent
b1da0eeca2
commit
0a03b5c0d4
@ -151,14 +151,24 @@ bricks.widgetBuild = async function(desc, widget, data){
|
|||||||
if (data){
|
if (data){
|
||||||
desc = bricks.apply_data(desc, data);
|
desc = bricks.apply_data(desc, data);
|
||||||
}
|
}
|
||||||
|
if (!desc.widgettype){
|
||||||
|
console.log('widgettype is null', desc);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
let klass = bricks.Factory.get(desc.widgettype);
|
let klass = bricks.Factory.get(desc.widgettype);
|
||||||
if (! klass){
|
if (! klass){
|
||||||
bricks.debug('widgetBuild():',desc.widgettype, 'not registered', bricks.Factory.widgets_kw);
|
console.log('widgetBuild():',
|
||||||
|
desc.widgettype,
|
||||||
|
'not registered',
|
||||||
|
bricks.Factory.widgets_kw);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var options = desc.options || {};
|
var options = desc.options || {};
|
||||||
options.baseURI = base_url;
|
options.baseURI = base_url;
|
||||||
let w = new klass(options);
|
let w = new klass(options);
|
||||||
|
if (! w){
|
||||||
|
console.log('w is null');
|
||||||
|
}
|
||||||
if (desc.id){
|
if (desc.id){
|
||||||
w.set_id(desc.id);
|
w.set_id(desc.id);
|
||||||
}
|
}
|
||||||
|
@ -129,10 +129,18 @@ bricks.ModelOutput = class extends bricks.VBox {
|
|||||||
this.upstreaming.send(data.content);
|
this.upstreaming.send(data.content);
|
||||||
}
|
}
|
||||||
this.run = null;
|
this.run = null;
|
||||||
var w = await bricks.widgetBuild(this.output_view, this.llmio, data);
|
this.filler.clear_widgets();
|
||||||
|
if (typeof this.output_view === 'string'){
|
||||||
|
this.output_view = JSON.parse(this.output_view);
|
||||||
|
}
|
||||||
|
var desc = bricks.apply_data(this.output_view, data);
|
||||||
|
var w = await bricks.widgetBuild(desc, this.llmio);
|
||||||
|
if (! w){
|
||||||
|
console.log('widgetBuild() return null, desc=', this.output_view, desc, 'data=', data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
w.set_css('llm_msg');
|
w.set_css('llm_msg');
|
||||||
w.set_style('width', '100%');
|
w.set_style('width', '100%');
|
||||||
this.filler.clear_widgets();
|
|
||||||
this.filler.add_widget(w);
|
this.filler.add_widget(w);
|
||||||
this.filler.add_widget(this.estimate_w);
|
this.filler.add_widget(this.estimate_w);
|
||||||
if (data.logid){
|
if (data.logid){
|
||||||
@ -190,7 +198,12 @@ bricks.LlmModel = class extends bricks.JsWidget {
|
|||||||
|
|
||||||
}
|
}
|
||||||
inputdata2uploaddata(data){
|
inputdata2uploaddata(data){
|
||||||
var d = data;
|
var d;
|
||||||
|
if (data instanceof FormData){
|
||||||
|
d = bricks.formdata_copy(data);
|
||||||
|
} else {
|
||||||
|
d = objcopy(data);
|
||||||
|
}
|
||||||
var fmt = this.opts.user_message_format;
|
var fmt = this.opts.user_message_format;
|
||||||
if (fmt){
|
if (fmt){
|
||||||
var umsg = bricks.apply_data(fmt, inputdata2dic(data));
|
var umsg = bricks.apply_data(fmt, inputdata2dic(data));
|
||||||
@ -223,6 +236,7 @@ bricks.LlmModel = class extends bricks.JsWidget {
|
|||||||
this.llmio.o_w.add_widget(mout);
|
this.llmio.o_w.add_widget(mout);
|
||||||
if (this.response_mode == 'stream' || this.response_mode == 'async') {
|
if (this.response_mode == 'stream' || this.response_mode == 'async') {
|
||||||
var d = this.inputdata2uploaddata(data);
|
var d = this.inputdata2uploaddata(data);
|
||||||
|
console.log('data_inouted=', data, 'upload_data=', d);
|
||||||
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));
|
||||||
@ -261,7 +275,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);
|
// console.log('stream data=', d);
|
||||||
}
|
}
|
||||||
chunk_ended(){
|
chunk_ended(){
|
||||||
if (! this.messages) {
|
if (! this.messages) {
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
var bricks = window.bricks || {};
|
var bricks = window.bricks || {};
|
||||||
bricks.bug = false;
|
bricks.bug = false;
|
||||||
|
|
||||||
|
bricks.formdata_copy = function(fd){
|
||||||
|
var cfd = new FormData();
|
||||||
|
|
||||||
|
// 遍历 originalFormData 中的所有条目并添加到 clonedFormData 中
|
||||||
|
for (var pair of fd.entries()) {
|
||||||
|
cfd.append(pair[0], pair[1]);
|
||||||
|
}
|
||||||
|
return cfd;
|
||||||
|
}
|
||||||
|
|
||||||
bricks.map = function(data_source, mapping, need_others){
|
bricks.map = function(data_source, mapping, need_others){
|
||||||
ret = {};
|
ret = {};
|
||||||
Object.entries(data_source).forEach(([key, value]) => {
|
Object.entries(data_source).forEach(([key, value]) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user