From 3caea6bc6edaa0cb404de010899379046cce8c04 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 6 Dec 2024 11:57:27 +0800 Subject: [PATCH] bugfix --- bricks/input.js | 5 +++-- bricks/llm.js | 47 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/bricks/input.js b/bricks/input.js index ff5fbc0..05b00f7 100644 --- a/bricks/input.js +++ b/bricks/input.js @@ -73,11 +73,12 @@ bricks.UiAudioText = class extends bricks.UiType { clear_text(){ this.text_w.setValue(''); } - getValue(){ - this.value = this.text_w.getValue(); + resultValue(){ + this.value = this.text_w.resultValue(); return this.value; } setValue(v){ + this.value = v; this.text_w.setValue(v); } set_result_text(event){ diff --git a/bricks/llm.js b/bricks/llm.js index a805165..edbd75d 100644 --- a/bricks/llm.js +++ b/bricks/llm.js @@ -1,5 +1,17 @@ bricks = window.bricks || {} +var inputdata2dic = function(data){ + if (! data instanceof FormData) return data; + var d = {} + for (let k of data.keys()){ + var x = data.get(k); + x = x instanceof File? x:x.toString(); + y = Object.prototype.toString.call(x) + d[k] = x; + console.log('x=', x, 'k=', k, 'x type=', y); + } + return d; +} bricks.LlmMsgAudio = class extends bricks.UpStreaming { constructor(opts){ super(opts); @@ -171,6 +183,19 @@ bricks.LlmModel = class extends bricks.JsWidget { } show_setup_panel(event){ + } + inputdata2uploaddata(data){ + var d = data; + if (data instanceof FormData){ + d.append('model', this.opts.model) + d.append('modelinstanceid', this.opts.modelinstanceid) + d.append('modeltypeid', this.opts.modeltypeid) + } else { + d.model = this.opts.model; + d.modelinstanceid = this.opts.modelinstanceid; + d.modeltypeid = this.opts.modeltypeid; + } + return d; } async model_inputed(data){ if (!opts.use_session){ @@ -184,27 +209,20 @@ bricks.LlmModel = class extends bricks.JsWidget { output_view:this.opts.output_view}); this.llmio.o_w.add_widget(mout); var fmt = this.opts.user_message_format || { role:'user', content:'${prompt}'}; - var umsg = bricks.apply_data(fmt, data); + var umsg = bricks.apply_data(fmt, inputdata2dic(data)); var d = {}; this.messages.push(umsg); d.model = this.opts.model; d.modelinstanceid = this.opts.modelinstanceid; d.modeltypeid = this.opts.modeltypeid; if (this.response_mode == 'stream' || this.response_mode == 'async') { - d = {}; - d.messages = this.messages; - d.model = this.opts.model; - d.modelinstanceid = this.opts.modelinstanceid; - d.modeltypeid = this.opts.modeltypeid; + var d = this.inputdata2uploaddata(data); 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)); this.chunk_ended(); } else { - d = data - d.model = this.opts.model; - d.modelinstanceid = this.opts.modelinstanceid; - d.modeltypeid = this.opts.modeltypeid; + var d = this.inputdata2uploaddata(data); var hj = new bricks.HttpJson() var resp = await hj.post(this.opts.url, {params:d}); if (this.response_mode == 'sync'){ @@ -302,8 +320,6 @@ bricks.LlmIO = class extends bricks.VBox { } async handle_input(event){ var params = event.params; - if (params.prompt) - params.prompt = bricks.escapeSpecialChars(params.prompt); await this.show_input(params); for(var i=0;i