bugfix
This commit is contained in:
parent
9e687ee3c1
commit
7d45d9b71f
@ -5,8 +5,8 @@ SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js \
|
||||
input.js registerfunction.js button.js accordion.js \
|
||||
tree.js multiple_state_image.js dynamiccolumn.js form.js message.js conform.js \
|
||||
paging.js datagrid.js dataviewer.js iframe.js \
|
||||
floaticonbar.js \
|
||||
miniform.js wterm.js dynamicaccordion.js "
|
||||
floaticonbar.js miniform.js wterm.js dynamicaccordion.js \
|
||||
llm_dialog.js "
|
||||
echo ${SOURCES}
|
||||
cat ${SOURCES} > ../dist/bricks.js
|
||||
# uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js
|
||||
|
@ -261,3 +261,19 @@ body {
|
||||
padding: 10px;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.llm_msg {
|
||||
width: 90%;
|
||||
margin-left: 5px;
|
||||
margin-right: auto;
|
||||
margin-bottom: 10px;
|
||||
background-color:#fefe44;
|
||||
}
|
||||
|
||||
.user_msg {
|
||||
width: 90%;
|
||||
margin-left: auto;
|
||||
margin-right: 5px;
|
||||
margin-bottom: 10px;
|
||||
background-color:#44fefe;
|
||||
}
|
||||
|
@ -5,14 +5,25 @@ function url_params(data) {
|
||||
/*
|
||||
async function doit() {
|
||||
const response = await fetch("http://localhost:3000")
|
||||
const reader = response.body.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
let result = await reader.read()
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
let result = await reader.read();
|
||||
var buffer = '';
|
||||
while (!result.done) {
|
||||
const text = decoder.decode(result.value)
|
||||
console.log("chunk is", text)
|
||||
const text = decoder.decode(result.value);
|
||||
buffer += text;
|
||||
const newline = /\r?\n/gm;
|
||||
var rez = newline.exec(buffer);
|
||||
while (rez){
|
||||
yield buffer.substring(0, rez.index);
|
||||
buffer = buffer.substring(newline.lastIndex);
|
||||
rez = newline.exec(buffer);
|
||||
}
|
||||
result = await reader.read()
|
||||
}
|
||||
if (buffer != ''){
|
||||
yield bufffer;
|
||||
}
|
||||
}
|
||||
// chunked response handle
|
||||
*/
|
||||
@ -115,7 +126,6 @@ bricks.HttpText = class {
|
||||
"data":result.data || '',
|
||||
"code":result.code || ''
|
||||
};
|
||||
const error = new Error();
|
||||
error.info = resp_error;
|
||||
return error;
|
||||
}
|
||||
@ -191,6 +201,30 @@ bricks.HttpResponse = class extends bricks.HttpText {
|
||||
}
|
||||
}
|
||||
|
||||
bricks.HttpResponseStream = class extends bricks.HttpText {
|
||||
async get_result_data(resp){
|
||||
const reader = resp.body.getReader();
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
let result = await reader.read();
|
||||
var buffer = '';
|
||||
while (!result.done) {
|
||||
const text = decoder.decode(result.value);
|
||||
buffer += text;
|
||||
const newline = /\r?\n/gm;
|
||||
var rez = newline.exec(buffer);
|
||||
while (rez){
|
||||
yield buffer.substring(0, rez.index);
|
||||
buffer = buffer.substring(newline.lastIndex);
|
||||
rez = newline.exec(buffer);
|
||||
}
|
||||
result = await reader.read()
|
||||
}
|
||||
if (buffer != ''){
|
||||
yield bufffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bricks.HttpRaw = class extends bricks.HttpText {
|
||||
async get_result_data(resp){
|
||||
return await resp.blob();
|
||||
|
61
bricks/llm_dialog.js
Normal file
61
bricks/llm_dialog.js
Normal file
@ -0,0 +1,61 @@
|
||||
var bricks = window.bricks || {}
|
||||
|
||||
bricks.LlmDialog = class extends bricks.VScrollPanel {
|
||||
/*
|
||||
{
|
||||
"url":
|
||||
"model",
|
||||
"user_msg_css"
|
||||
"llm_msg_css"
|
||||
}
|
||||
method:
|
||||
set_prompt(prompt)
|
||||
event:
|
||||
llm_answer event.params = assistant answer content
|
||||
*/
|
||||
constructor(opts){
|
||||
super(opts);
|
||||
this.messages = [];
|
||||
}
|
||||
set_prompt(prompt){
|
||||
var w = bricks.MdWidget({mdtext:prompt});
|
||||
w.set_css(this.user_msg_css||'user_msg');
|
||||
this.add_widget(w);
|
||||
this.llm_request(prompt);
|
||||
}
|
||||
llm_request(prompt){
|
||||
var d = {
|
||||
messages:this.messages,
|
||||
model:this.model,
|
||||
prompt:prompt
|
||||
}
|
||||
var hr = bricks.HttpResponseStream();
|
||||
var w = bricks.MdWidget({mdtext:''});
|
||||
w.set_css(this.llm_msg_css||'llm_msg');
|
||||
this.add_widget(w);
|
||||
for await (const line of hr.get(this.url, {params=d})) {
|
||||
this.processLine(line, w);
|
||||
}
|
||||
this.messages.push({
|
||||
role:'user',
|
||||
content:prompt
|
||||
});
|
||||
this.messages.push({
|
||||
role:'assistant',
|
||||
content:w.md_content
|
||||
});
|
||||
var d = {
|
||||
model:this.model,
|
||||
messages:this.messages
|
||||
}
|
||||
this.dispatch('llm_answered', d);
|
||||
}
|
||||
processLine(l, w){
|
||||
var d = JSON.parse();
|
||||
var txt = w.md_content + d.content;
|
||||
w.set_content(txt);
|
||||
}
|
||||
}
|
||||
|
||||
bricks.Factory.register('LlmDialog', bricks.LlmDialog);
|
||||
|
@ -28,6 +28,10 @@ bricks.MdWidget = class extends bricks.JsWidget {
|
||||
schedule_once(f, 0.01);
|
||||
}
|
||||
}
|
||||
set_content(content){
|
||||
this.md_content = content;
|
||||
this._build1();
|
||||
}
|
||||
show_scroll(event){
|
||||
bricks.debug('scrollY=', window.scrollY);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user