feat: upload audio file in chat

This commit is contained in:
jialin
2025-06-03 19:58:08 +08:00
parent ed28bcdfb0
commit 471e1ae96f
8 changed files with 187 additions and 52 deletions
+28 -2
View File
@@ -1,6 +1,6 @@
import _, { map } from 'lodash';
import { CREAT_IMAGE_API } from '../apis';
import { MessageItem } from './types';
import { AudioData, MessageItem } from './types';
export const Roles = {
User: 'user',
@@ -76,7 +76,33 @@ export const generateMessagesByListContent = (messageList: any[]) => {
content: content
};
}
return _.omit(item, ['uid', 'imgs']);
// audio
if (item.audio?.length) {
const content = map(item.audio, (item: AudioData) => {
return {
type: 'input_audio',
input_audio: {
data: item.base64,
format: item.format
}
};
});
if (item.content) {
content.push({
type: 'text',
text: item.content
});
}
return {
role: item.role,
content: content
};
}
return _.omit(item, ['uid', 'imgs', 'audio']);
});
};
+14 -1
View File
@@ -13,10 +13,23 @@ export type MessageItemAction =
| 'markdown'
| 'edit';
export type AudioFormat = 'wav' | 'mp3';
export interface AudioData {
uid: string | number;
base64: string;
format: AudioFormat;
data: {
url: string;
name: string;
duration: number;
};
}
export interface MessageItem {
content: string;
imgs?: { uid: string | number; dataUrl: string }[];
audio?: { uid: string | number; dataUrl: string; format: 'wav' | 'mp3' };
audio?: AudioData[];
role: string;
title?: React.ReactNode;
uid: number;