Compare commits

..

No commits in common. "a5a33d8d1efd996fd52552fa07cbb0e5e014a6cb" and "03179fa97061b187d96b13b4e301d2ec7d3e604a" have entirely different histories.

7 changed files with 6 additions and 83 deletions

View File

@ -38,12 +38,6 @@ bricks.AudioPlayer = class extends bricks.JsWidget {
this.audio.src = url;
bricks.debug(this.audio.src,' new src seted');
}
set_source_from_response(resp){
// 将服务器返回的数据设置为音频源
this.audio.src = URL.createObjectURL(new Blob([response.body]));
// 播放音频
this.audio.play();
}
play(){
this.audio.play();
}

View File

@ -6,7 +6,6 @@ SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \
tree.js multiple_state_image.js dynamiccolumn.js form.js message.js conform.js \
paging.js datagrid.js iframe.js cols.js echartsext.js \
floaticonbar.js miniform.js wterm.js dynamicaccordion.js \
binstreaming.js streaming_audio.js \
llm_dialog.js llm.js websocket.js datarow.js tabular.js \
line.js pie.js bar.js gobang.js "
echo ${SOURCES}

View File

@ -75,7 +75,6 @@ bricks.Button = class extends bricks.Layout {
var txt = new bricks.Text(opts);
this.add_widget(txt);
txt.bind('click', this.target_clicked.bind(this));
this.text_w = txt;
}
}
target_clicked(event){

View File

@ -7,6 +7,9 @@
<link rel="stylesheet" href="/bricks/3parties/xterm.css" />
<link href="/bricks/3parties/video-js.css" rel="stylesheet" />
<link rel="stylesheet" href="/bricks/css/bricks.css">
<!-- support IE8 (for Video.js versions prior to v7) -->
<script src="{{entire_url('/bricks/3parties/videojs-ie8.min.js')}}"></script>
</head>
<body>
<!--
@ -14,9 +17,6 @@
<script>eruda.init();</script>
-->
<script type="text/javascript" src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.7/dist/bundle.min.js"></script>
<script src="/bricks/3parties/marked.min.js"></script>
<script src="/bricks/3parties/xterm.js"></script>
<script src="/bricks/3parties/video.min.js"></script>

View File

@ -28,9 +28,6 @@ bricks.Image = class extends bricks.JsWidget {
this.dom_element.style.height = this.height;
}
}
removeBase64Header(base64String) {
return base64String.replace(/^data:[^;]*;base64,/, '');
}
base64(){
const image = this.dom_element;
// 创建一个画布来绘制图像
@ -45,8 +42,7 @@ bricks.Image = class extends bricks.JsWidget {
ctx.drawImage(image, 0, 0);
// 获取画布数据并转换为 base64
var dataURL = canvas.toDataURL('image/png'); // 可以根据需要修改图像格式
dataURL = this.removeBase64Header(dataURL);
const dataURL = canvas.toDataURL('image/png'); // 可以根据需要修改图像格式
console.log(dataURL);
return dataURL;
}

View File

@ -1,46 +1,5 @@
bricks = window.bricks || {}
bricks.LlmMsgAudio = class extends bricks.UpStreaming {
constructor(opts){
super(opts);
this.olddata = '';
this.data = '';
this.cn_p = ["。","","","","\n"];
this.other_p = [".",",","!","?","\n"];
this.audio = AudioPlayer({})
}
detectLanguage(text) {
try {
const detector = new Intl.LocaleDetector();
const locale = detector.detectLocaleOf(text);
return locale.language;
} catch (error) {
console.error('无法检测语言:', error);
return '未知';
}
}
send(data){
var newdata = data.slice(this.olddata.length);
this.olddata = data;
this.data += newdata;
var lang = detectLaguage(this.data);
var parts;
if (lang='zh'){
parts = this.data.split(this.cn_p).filter(part => part.trim()!== '');
} else {
parts = this.data.split(this.oter_p).filter(part => part.trim()!== '');
}
for(var i=0;i<parts.length - 1; i++){
super.send(parts[i]);
}
this.data = parts[parts.length - 1];
}
async go(){
var resp = await super.go();
this.audio.set_source_from_response(resp);
return resp;
}
}
bricks.ModelOutput = class extends bricks.HBox {
/* {
icon:
@ -105,16 +64,8 @@ bricks.ModelOutput = class extends bricks.HBox {
if (this.run) {
this.run.stop_timepass();
this.remove_widget(this.run);
if(this.textvoice){
this.upstreaming = new bricks.UpStreaming({
url:this.tts_url
});
this.upstreaming.go();
}
}
if (this.upstreaming){
this.upstreaming.send(data.content);
}
console.log('update_data():data=', data);
this.run = null;
var w = await bricks.widgetBuild(this.output_view, this.llmio, data);
w.set_css('llm_msg');
@ -128,11 +79,6 @@ bricks.ModelOutput = class extends bricks.HBox {
}
}
}
finish(){
if (this.upstreaming){
this.upstreaming.finish();
}
}
}
bricks.LlmModel = class extends bricks.JsWidget {
@ -149,8 +95,6 @@ bricks.LlmModel = class extends bricks.JsWidget {
llm_message_format:
use_session:
input_from:
textvoice:
tts_url:
response_mode:stream, sync or async
}
*/
@ -175,8 +119,6 @@ bricks.LlmModel = class extends bricks.JsWidget {
}
async model_inputed(data){
var mout = new bricks.ModelOutput({
textvoice:this.textvoice,
tts_url:this.tts_url,
icon:this.opts.icon,
estimate_url:this.llmio.estimate_url,
output_view:this.opts.output_view});
@ -283,15 +225,8 @@ bricks.LlmIO = class extends bricks.VBox {
this.o_w = new bricks.Filler({overflow:'auto'});
this.add_widget(this.title_w);
this.add_widget(this.o_w);
if (this.models.length < 2 && this.tts_url){
this.textvoice = true;
}
this.add_widget(this.i_w);
this.models.forEach( m =>{
if (this.textvoice){
m.textvoice = true;
m.tts_url = this.tts_url;
}
var lm = new bricks.LlmModel(this, m);
this.llmmodels.push(lm);
var tw = lm.render_title();

View File

@ -309,7 +309,7 @@ bricks.TextBase = class extends bricks.JsWidget {
if (this.i18n) {
text = this._i18n._(this.otext);
} else {
text = this.otext;
text = otext;
}
this.set_text(text);
}