Update to MiniCPM-o 2.6

This commit is contained in:
yiranyyu
2025-01-14 15:33:44 +08:00
parent b75a362dd6
commit 53c0174797
123 changed files with 16848 additions and 2952 deletions

View File

@@ -0,0 +1,44 @@
// 判断终端是pc还是移动端
export const isMobile = () => {
let flag = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Linux/i.test(navigator.userAgent);
const platform = navigator.platform;
// iPad上的Safari
if (platform === 'MacIntel' && navigator.maxTouchPoints > 1) {
flag = true;
}
return flag;
};
// 单片语音长度(单位ms)
const voicePerLength = 200;
// 图片计数算出在哪一次发送语音时同时发送图片。例如一片语音100ms一秒钟发送一次语音即发送的第10片语音时需要带一张图片
export const maxCount = 1000 / voicePerLength;
export const getChunkLength = sampleRate => {
return sampleRate * (voicePerLength / 1000);
};
export const isAvailablePort = port => {
return [
8000, 8001, 8002, 8003, 8004, 8010, 8011, 8012, 8013, 8014, 8020, 8021, 8022, 8023, 8024, 8025, 8026, 8027,
8028, 32449
].includes(port);
};
// 文件转base64格式
export const fileToBase64 = file => {
return new Promise((resolve, reject) => {
if (!file) {
reject('文件不能为空');
}
const reader = new FileReader();
reader.onload = e => {
const base64String = e.target.result;
resolve(base64String);
};
reader.onerror = () => {
reject('文件转码失败');
};
reader.readAsDataURL(file);
});
};

View File

@@ -0,0 +1,91 @@
class WebSocketClient {
constructor(url, maxReconnectAttempts = 5, reconnectInterval = 5000) {
this.url = url;
this.socket = null;
this.eventHandlers = {};
this.maxReconnectAttempts = maxReconnectAttempts;
this.reconnectInterval = reconnectInterval;
this.reconnectAttempts = 0;
this.reconnectTimer = null;
}
connect() {
this.reconnectAttempts = 0;
this.establishConnection();
}
establishConnection() {
this.socket = new WebSocket(this.url);
this.socket.onopen = () => {
console.log('WebSocket connection opened');
this.reconnectAttempts = 0; // Reset reconnect attempts on successful connection
this.emit('open');
};
this.socket.onclose = event => {
console.log('WebSocket connection closed', event);
this.emit('close', event);
// 1005为主动关闭websocket
if (event.code !== 1005) {
this.reconnect();
}
};
this.socket.onerror = error => {
console.error('WebSocket error', error);
this.emit('error', error);
// Optionally, you may want to trigger a reconnect on error as well
// this.reconnect();
};
this.socket.onmessage = message => {
// console.log('WebSocket message received', message.data);
this.emit('message', message.data);
};
}
send(data) {
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
this.socket.send(data);
} else {
console.error('WebSocket is not open');
}
}
on(event, handler) {
// if (!this.eventHandlers[event]) {
this.eventHandlers[event] = [];
// }
this.eventHandlers[event].push(handler);
// console.log('Event handler added:', this.eventHandlers, event);
}
emit(event, ...args) {
if (this.eventHandlers[event]) {
this.eventHandlers[event].forEach(handler => handler(...args));
}
}
close() {
if (this.socket) {
this.socket.close();
}
clearTimeout(this.reconnectTimer);
}
reconnect() {
if (this.reconnectAttempts < this.maxReconnectAttempts) {
console.log(`Reconnecting attempt ${this.reconnectAttempts + 1}/${this.maxReconnectAttempts}...`);
this.reconnectTimer = setTimeout(() => {
this.reconnectAttempts++;
this.establishConnection();
}, this.reconnectInterval);
} else {
console.error('Max reconnect attempts reached. WebSocket will not attempt to reconnect.');
this.emit('max-reconnect-attempts');
}
}
}
export default WebSocketClient;