fix: do not init audio model

This commit is contained in:
jialin
2025-02-28 12:23:02 +08:00
parent 295b4b3b72
commit 9927da5088
14 changed files with 134 additions and 70 deletions
@@ -115,10 +115,11 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
modelData,
handleChildSelect
}) => {
const [api, contextHolder] = notification.useNotification();
const [api, contextHolder] = notification.useNotification({
stack: { threshold: 1 }
});
const { downloadStream } = useDownloadStream();
const intl = useIntl();
const actionItems = useMemo(() => {
return _.filter(childActionList, (action: any) => {
if (action.key === 'viewlog' || action.key === 'download') {
@@ -135,12 +136,25 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
};
const downloadNotification = useCallback(
(data: HandlerOptions & { filename: string; duration?: number }) => {
(
data: HandlerOptions & {
filename: string;
duration?: number;
chunkRequestRef: any;
}
) => {
api.open({
duration: data.duration,
message: renderMessage(data.filename),
key: data.filename,
description: <Progress percent={data.percent} size="small"></Progress>
closeIcon: (
<span>{intl.formatMessage({ id: 'common.button.cancel' })}</span>
),
description: <Progress percent={data.percent} size="small"></Progress>,
onClose() {
data.chunkRequestRef?.current?.abort();
notification.destroy?.(data.filename);
}
});
},
[]
@@ -198,10 +198,9 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
};
const submitMessage = async (current?: { role: string; content: string }) => {
await formRef.current?.form.validateFields();
if (!parameters.model) return;
try {
await formRef.current?.form.validateFields();
if (!parameters.model) return;
const validTextList = textList.filter((item) => item.text);
const validFileList = fileList.filter((item) => item.text);
@@ -229,7 +229,9 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
<FileImageOutlined className="font-size-32 text-secondary" />
</span>
<span>
{intl.formatMessage({ id: 'playground.params.empty.tips' })}
{intl.formatMessage({
id: 'playground.params.empty.tips'
})}
</span>
</div>
)}
@@ -308,7 +310,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
})}
>
<Button
size="middle"
size="small"
type="text"
icon={<SwapOutlined />}
onClick={handleToggleParamsStyle}
@@ -218,9 +218,9 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
};
const submitMessage = async () => {
await formRef.current?.form.validateFields();
if (!parameters.model) return;
try {
await formRef.current?.form.validateFields();
if (!parameters.model) return;
const documentList: any[] = [...textList, ...fileList];
const validDocus = documentList.filter((item) => item.text);
+19 -13
View File
@@ -41,10 +41,6 @@ interface MessageProps {
ref?: any;
}
const initialValues = {
language: 'auto'
};
const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
const intl = useIntl();
const { modelList } = props;
@@ -57,8 +53,9 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
const selectModel = searchParams.get('model')
? modelType === 'stt' && searchParams.get('model')
: '';
const defaultModel = selectModel || modelList[0]?.value || '';
const [parameters, setParams] = useState<any>({
model: selectModel,
model: defaultModel,
language: 'auto'
});
const [show, setShow] = useState(false);
@@ -112,9 +109,9 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
};
const submitMessage = async () => {
await formRef.current?.form.validateFields();
if (!parameters.model) return;
try {
await formRef.current?.form.validateFields();
if (!parameters.model) return;
setLoading(true);
setMessageId();
setTokenResult(null);
@@ -181,9 +178,6 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
}
};
const handleClear = () => {
if (!messageList.length) {
return;
}
setMessageId();
setMessageList([]);
setTokenResult(null);
@@ -243,6 +237,10 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
}, []);
const handleOnGenerate = async () => {
if (loading) {
handleStopConversation();
return;
}
submitMessage();
};
@@ -340,7 +338,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
title={
loading
? intl.formatMessage({
id: 'playground.audio.generating'
id: 'common.button.stop'
})
: intl.formatMessage({
id: 'playground.audio.button.generate'
@@ -350,12 +348,20 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
{
<Button
disabled={!audioData}
loading={loading}
type="primary"
size="middle"
shape="circle"
onClick={handleOnGenerate}
icon={<SendOutlined></SendOutlined>}
icon={
loading ? (
<IconFont
type="icon-stop1"
className="font-size-14"
></IconFont>
) : (
<SendOutlined></SendOutlined>
)
}
></Button>
}
</Tooltip>
+10 -15
View File
@@ -92,6 +92,10 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
};
});
const defaultModel = useMemo(() => {
return selectModel || modelList[0]?.value || '';
}, [modelList]);
const viewCodeContent = useMemo(() => {
return TextToSpeechCode({
api: AUDIO_TEXT_TO_SPEECH_API,
@@ -147,9 +151,9 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
};
const submitMessage = async (current?: { role: string; content: string }) => {
await formRef.current?.form.validateFields();
if (!parameters.model) return;
try {
await formRef.current?.form.validateFields();
if (!parameters.model) return;
setLoading(true);
setMessageId();
setTokenResult(null);
@@ -235,14 +239,6 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
const handleSelectModel = useCallback(
async (value: string) => {
if (!value) {
setVoiceList([]);
setParams((pre: any) => {
return {
...pre,
voice: ''
};
});
formRef.current?.form.setFieldValue('voice', '');
return;
}
const model = modelList.find((item) => item.value === value);
@@ -259,10 +255,10 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
setParams((pre: any) => {
return {
...pre,
model: value,
voice: newList[0]?.value
};
});
formRef.current?.form.setFieldValue('voice', newList[0]?.value);
},
[modelList]
);
@@ -307,11 +303,10 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
}, [paramsConfig, intl, voiceList]);
useEffect(() => {
if (!parameters.model && modelList.length) {
const model = modelList[0]?.value;
handleSelectModel(model);
if (defaultModel) {
handleSelectModel(defaultModel);
}
}, [modelList, parameters.model, handleSelectModel]);
}, [defaultModel]);
useEffect(() => {
if (scroller.current) {
@@ -506,7 +506,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
})}
>
<Button
size="middle"
size="small"
type="text"
icon={<SwapOutlined />}
onClick={handleToggleParamsStyle}
+6 -7
View File
@@ -162,7 +162,7 @@ export const useInitImageMeta = (props: MessageProps) => {
const { modelList } = props;
const form = useRef<any>(null);
const [searchParams] = useSearchParams();
const selectModel = searchParams.get('model') || '';
const defaultModel = searchParams.get('model') || modelList?.[0]?.value || '';
const [modelMeta, setModelMeta] = useState<any>({});
const [isOpenaiCompatible, setIsOpenaiCompatible] = useState<boolean>(false);
const [imageSizeOptions, setImageSizeOptions] = React.useState<
@@ -175,7 +175,7 @@ export const useInitImageMeta = (props: MessageProps) => {
const [initialValues, setInitialValues] = useState<any>({
...imgInitialValues,
...advancedFieldsDefaultValus,
model: selectModel
model: defaultModel
});
const [paramsConfig, setParamsConfig] = useState<ParamsSchema[]>([
...ImageCountConfig,
@@ -186,7 +186,7 @@ export const useInitImageMeta = (props: MessageProps) => {
const [parameters, setParams] = useState<any>({
...imgInitialValues,
...advancedFieldsDefaultValus,
model: selectModel
model: defaultModel
});
const cacheFormData = React.useRef<Record<string, any>>({
@@ -410,11 +410,10 @@ export const useInitImageMeta = (props: MessageProps) => {
);
useEffect(() => {
if (!parameters.model && modelList.length) {
const model = modelList[0]?.value;
handleOnModelChange(model);
if (defaultModel) {
handleOnModelChange(defaultModel);
}
}, [modelList, parameters.model, handleOnModelChange]);
}, [defaultModel, handleOnModelChange]);
return {
extractIMGMeta,
+2
View File
@@ -107,6 +107,7 @@ const Playground: React.FC = () => {
with_meta: true
};
const res = await queryModelsList(params);
const list = _.map(res.data || [], (item: any) => {
return {
value: item.id,
@@ -127,6 +128,7 @@ const Playground: React.FC = () => {
with_meta: true
};
const res = await queryModelsList(params);
const list = _.map(res.data || [], (item: any) => {
return {
value: item.id,