This commit is contained in:
yumoqing 2024-11-20 17:11:30 +08:00
parent c5812e8762
commit 9f3b4cf05d
4 changed files with 17 additions and 20 deletions

0
bricks/build.sh Normal file → Executable file
View File

View File

@ -360,7 +360,12 @@ bricks.UiImage =class extends bricks.VBox {
this.imgw = null; this.imgw = null;
} }
take_photo(){ take_photo(){
var camera = new bricks.Camera({}); var camera = new bricks.Camera({
"archor":"cc",
"auto_open":true,
"height":"90%",
"width":"90%"
});
camera.bind('shot', function(d){ camera.bind('shot', function(d){
if (this.imgw){ if (this.imgw){
this.remove_widget(this.imgw); this.remove_widget(this.imgw);

View File

@ -157,9 +157,7 @@ bricks.LlmModel = class extends bricks.JsWidget {
constructor(llmio, opts){ constructor(llmio, opts){
super(opts); super(opts);
this.llmio = llmio; this.llmio = llmio;
if (opts.use_session){ this.messages = [];
this.messages = [];
}
} }
render_title(){ render_title(){
var w = new bricks.HBox({}); var w = new bricks.HBox({});
@ -174,6 +172,9 @@ bricks.LlmModel = class extends bricks.JsWidget {
} }
async model_inputed(data){ async model_inputed(data){
if (!opts.use_session){
this.messages = [];
}
var mout = new bricks.ModelOutput({ var mout = new bricks.ModelOutput({
textvoice:this.textvoice, textvoice:this.textvoice,
tts_url:this.tts_url, tts_url:this.tts_url,
@ -184,20 +185,12 @@ bricks.LlmModel = class extends bricks.JsWidget {
var fmt = this.opts.user_message_format || { role:'user', content:'${prompt}'}; var fmt = this.opts.user_message_format || { role:'user', content:'${prompt}'};
var umsg = bricks.apply_data(fmt, data); var umsg = bricks.apply_data(fmt, data);
var d = data; var d = data;
if (this.messages){ this.messages.push(umsg);
this.messages.push(umsg); d = {};
d = bricks.extend({}, data); d.messages = this.messages;
d.messages = this.messages; d.model = this.opts.model;
d.model = this.opts.model; d.modelinstanceid = this.opts.modelinstanceid;
d.modelinstanceid = this.opts.modelinstanceid; d.modeltypeid = this.opts.modeltypeid;
d.modeltypeid = this.opts.modeltypeid;
} else {
d = bricks.extend({}, data);
d.model = this.opts.model;
d.mapi = this.mapi;
d.modelinstanceid = this.opts.modelinstanceid;
d.modeltypeid = this.opts.modeltypeid;
}
console.log('upload data=', d, this.options); console.log('upload data=', d, this.options);
if (this.response_mode == 'stream' || this.response_mode == 'async') { if (this.response_mode == 'stream' || this.response_mode == 'async') {
var hr = new bricks.HttpResponseStream(); var hr = new bricks.HttpResponseStream();

View File

@ -96,13 +96,12 @@ bricks.LlmMsgBox = class extends bricks.HBox {
var d = { var d = {
messages:this.messages, messages:this.messages,
mapi:this.mapi, mapi:this.mapi,
prompt:prompt,
model:this.model, model:this.model,
} }
// console.log('messages=', this.messages, 'msg=', msg, 'umsg=', umsg); // console.log('messages=', this.messages, 'msg=', msg, 'umsg=', umsg);
if (this.response_mode == 'stream') { if (this.response_mode == 'stream') {
var hr = new bricks.HttpResponseStream(); var hr = new bricks.HttpResponseStream();
var resp = await hr.post(this.url, {params:d}); var resp = await hr.post(this.url, {data:d});
this.responsed(); this.responsed();
await hr.handle_chunk(resp, this.chunk_response.bind(this)); await hr.handle_chunk(resp, this.chunk_response.bind(this));
this.chunk_ended(); this.chunk_ended();