From 0a03b5c0d4cff5bce22c7faa448a1d4679e5fe83 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 15 Mar 2025 16:58:12 +0800 Subject: [PATCH] bugfix --- bricks/bricks.js | 12 +++++++++++- bricks/llm.js | 22 ++++++++++++++++++---- bricks/utils.js | 10 ++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/bricks/bricks.js b/bricks/bricks.js index 6526bb0..334980a 100644 --- a/bricks/bricks.js +++ b/bricks/bricks.js @@ -151,14 +151,24 @@ bricks.widgetBuild = async function(desc, widget, data){ if (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); 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; } var options = desc.options || {}; options.baseURI = base_url; let w = new klass(options); + if (! w){ + console.log('w is null'); + } if (desc.id){ w.set_id(desc.id); } diff --git a/bricks/llm.js b/bricks/llm.js index 92497ac..ac3a8a7 100644 --- a/bricks/llm.js +++ b/bricks/llm.js @@ -129,10 +129,18 @@ bricks.ModelOutput = class extends bricks.VBox { this.upstreaming.send(data.content); } 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_style('width', '100%'); - this.filler.clear_widgets(); this.filler.add_widget(w); this.filler.add_widget(this.estimate_w); if (data.logid){ @@ -190,7 +198,12 @@ bricks.LlmModel = class extends bricks.JsWidget { } 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; if (fmt){ 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); if (this.response_mode == 'stream' || this.response_mode == 'async') { var d = this.inputdata2uploaddata(data); + console.log('data_inouted=', data, 'upload_data=', d); var hr = new bricks.HttpResponseStream(); var resp = await hr.post(this.opts.url, {params:d}); 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); this.resp_data = d; mout.update_data(d); - console.log('stream data=', d); + // console.log('stream data=', d); } chunk_ended(){ if (! this.messages) { diff --git a/bricks/utils.js b/bricks/utils.js index a544245..21cba79 100644 --- a/bricks/utils.js +++ b/bricks/utils.js @@ -1,6 +1,16 @@ var bricks = window.bricks || {}; 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){ ret = {}; Object.entries(data_source).forEach(([key, value]) => {