Skip to content

Commit

Permalink
chore: support editing the model repoID, filename, model path
Browse files Browse the repository at this point in the history
  • Loading branch information
hibig committed Dec 10, 2024
1 parent acf99a6 commit 15f685f
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 43 deletions.
21 changes: 11 additions & 10 deletions src/components/audio-player/raw-audio-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ const RawAudioPlayer: React.FC<AudioPlayerProps> = forwardRef((props, ref) => {

audioRef.current.addEventListener('loadeddata', () => {
initEnvents();
initAudioContext();
generateVisualData();
if (!audioContext.current) {
initAudioContext();
generateVisualData();
}
props.onLoadedData?.();
});

Expand Down Expand Up @@ -107,12 +109,6 @@ const RawAudioPlayer: React.FC<AudioPlayerProps> = forwardRef((props, ref) => {
});
};

const handleAudioOnPlay = () => {
audioRef.current?.play();
};

const handleLoadedMetadata = () => {};

useImperativeHandle(ref, () => ({
play: () => {
audioRef.current?.play();
Expand All @@ -124,6 +120,8 @@ const RawAudioPlayer: React.FC<AudioPlayerProps> = forwardRef((props, ref) => {

useEffect(() => {
if (audioRef.current) {
console.log('audioRef.current', audioRef.current, props.url);
initEnvents();
}
return () => {
if (audioContext.current) {
Expand All @@ -150,12 +148,15 @@ const RawAudioPlayer: React.FC<AudioPlayerProps> = forwardRef((props, ref) => {

return (
<audio
width={props.width || 300}
height={props.height || 40}
controls
autoPlay={autoplay}
src={props.url}
ref={audioRef}
style={{
position: 'absolute',
left: '-9999px',
opacity: 0
}}
preload="metadata"
></audio>
);
Expand Down
4 changes: 4 additions & 0 deletions src/components/drop-down-buttons/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dropdown-button.middle {
height: 28px;
width: 28px;
}
12 changes: 10 additions & 2 deletions src/components/drop-down-buttons/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { MoreOutlined } from '@ant-design/icons';
import { useIntl } from '@umijs/max';
import { Button, Dropdown, Tooltip, type MenuProps } from 'antd';
import classNames from 'classnames';
import _ from 'lodash';
import { memo } from 'react';
import './index.less';

interface DropdownButtonsProps {
items: MenuProps['items'];
Expand All @@ -12,7 +14,7 @@ interface DropdownButtonsProps {

const DropdownButtons: React.FC<DropdownButtonsProps> = ({
items,
size = 'small',
size = 'middle',
onSelect
}) => {
const intl = useIntl();
Expand Down Expand Up @@ -81,12 +83,18 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
key="leftButton"
>
<Button
className={classNames('dropdown-button', size)}
onClick={handleButtonClick}
size={size}
icon={_.head(items)?.icon}
></Button>
</Tooltip>,
<Button icon={<MoreOutlined />} size={size} key="menu"></Button>
<Button
icon={<MoreOutlined />}
size={size}
key="menu"
className={classNames('dropdown-button', size)}
></Button>
]}
></Dropdown.Button>
)}
Expand Down
24 changes: 14 additions & 10 deletions src/components/seal-table/components/table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ const TableRow: React.FC<
}
}, [rowSelection]);

// useEffect(() => {
// if (expandedRowKeys?.includes(record[rowKey])) {
// setExpanded(true);
// } else {
// setExpanded(false);
// }
// }, [expandedRowKeys]);

useEffect(() => {
return () => {
if (pollTimer.current) {
Expand Down Expand Up @@ -160,8 +152,6 @@ const TableRow: React.FC<
pollTimer.current = setInterval(() => {
handlePolling();
}, 1000);
} else {
handleLoadChildren();
}
};

Expand All @@ -179,6 +169,20 @@ const TableRow: React.FC<
}
};

useEffect(() => {
if (expandedRowKeys?.includes(record[rowKey])) {
setExpanded(true);
} else {
setExpanded(false);
}
}, [expandedRowKeys]);

useEffect(() => {
if (expanded) {
handleLoadChildren();
}
}, [expanded]);

useEffect(() => {
if (!firstLoad && expanded) {
cacheDataListRef.current = childrenData;
Expand Down
15 changes: 14 additions & 1 deletion src/components/speech-content/speech-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const SpeechItem: React.FC<SpeechContentProps> = (props) => {
}, [ref.current]);

const handleOnAnalyse = useCallback((data: any, analyser: any) => {
console.log('data+++++++++++++++++=:', data);
setAudioChunks((pre: any) => {
return {
data: data,
Expand All @@ -88,6 +89,7 @@ const SpeechItem: React.FC<SpeechContentProps> = (props) => {

const handleOnAudioprocess = useCallback(
(current: number) => {
console.log('current:', current);
throttleUpdateCurrentTime(current);
},
[throttleUpdateCurrentTime]
Expand Down Expand Up @@ -119,7 +121,7 @@ const SpeechItem: React.FC<SpeechContentProps> = (props) => {
};

const handleReady = useCallback((duration: number) => {
console.log('duration:', duration);
console.log('ready+++++++++++++++', duration);
setDuration(duration);
}, []);

Expand Down Expand Up @@ -159,6 +161,17 @@ const SpeechItem: React.FC<SpeechContentProps> = (props) => {
onAudioprocess={handleOnAudioprocess}
ref={ref}
></AudioPlayer>
{/* <RawAudioPlayer
{...props}
url={props.audioUrl}
onReady={handleReady}
onEnded={handleOnFinish}
onPlay={handleOnPlay}
onPause={handleOnPause}
onAnalyse={handleOnAnalyse}
onAudioProcess={handleOnAudioprocess}
ref={ref}
></RawAudioPlayer> */}
{isPlay && (
<AudioAnimation
maxBarCount={100}
Expand Down
1 change: 1 addition & 0 deletions src/config/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const KeybindingsMap = {
NEW1: ['Ctrl+1', 'Meta+1'],
NEW2: ['Ctrl+2', 'Meta+2'],
NEW3: ['Ctrl+3', 'Meta+3'],
NEW4: ['Ctrl+4', 'Meta+4'],
FOCUS: ['/', '/'],
ADD: ['Alt+Ctrl+Enter', 'Alt+Meta+Enter']
};
Expand Down
4 changes: 4 additions & 0 deletions src/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ body {
.ant-image {
border-radius: var(--border-radius-base);
overflow: hidden;

.ant-image-mask {
background: rgba(0, 0, 0, 25%);
}
}

.ant-message-notice-wrapper {
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/use-expanded-row-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default function useExpandedRowKeys() {
);

const updateExpandedRowKeys = (keys: React.Key[]) => {
setExpandedRowKeys(keys);
};

const removeExpandedRowKey = (keys: React.Key[]) => {
// remove expanded row keys that are in the deleted keys
const newExpandedRowKeys = expandedRowKeys.filter(
(key) => !keys.includes(key)
Expand All @@ -30,6 +34,7 @@ export default function useExpandedRowKeys() {
expandedRowKeys,
clearExpandedRowKeys,
updateExpandedRowKeys,
removeExpandedRowKey,
handleExpandChange
};
}
1 change: 0 additions & 1 deletion src/pages/llmodels/components/advance-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ interface AdvanceConfigProps {
gpuOptions: Array<any>;
action: PageActionType;
source: string;
modelTask: Record<string, any>;
}

const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/llmodels/components/data-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
<SealAutoComplete
filterOption
defaultActiveFirstOption
disabled={action === PageAction.EDIT}
disabled={false}
options={ollamaModelOptions}
label={intl.formatMessage({ id: 'model.form.ollama.model' })}
placeholder={intl.formatMessage({ id: 'model.form.ollamaholder' })}
Expand Down Expand Up @@ -503,7 +503,6 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
form={form}
gpuOptions={gpuOptions}
isGGUF={isGGUF}
modelTask={modelTask}
action={action}
source={props.source}
></AdvanceConfig>
Expand Down
34 changes: 28 additions & 6 deletions src/pages/llmodels/components/table-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ const Models: React.FC<ModelsProps> = ({
const intl = useIntl();
const navigate = useNavigate();
const rowSelection = useTableRowSelection();
const { handleExpandChange, updateExpandedRowKeys, expandedRowKeys } =
useExpandedRowKeys();
const {
handleExpandChange,
updateExpandedRowKeys,
removeExpandedRowKey,
expandedRowKeys
} = useExpandedRowKeys();
const { sortOrder, setSortOrder } = useTableSort({
defaultSortOrder: 'descend'
});
Expand Down Expand Up @@ -152,6 +156,20 @@ const Models: React.FC<ModelsProps> = ({
enabled: !openAddModal && !openDeployModal.show && !openLogModal
}
);
useHotkeys(
HotKeys.NEW4.join(','),
() => {
setOpenDeployModal({
show: true,
width: 600,
source: modelSourceMap.local_path_value
});
},
{
preventDefault: true,
enabled: !openAddModal && !openDeployModal.show && !openLogModal
}
);

const sourceOptions = [
{
Expand Down Expand Up @@ -299,16 +317,20 @@ const Models: React.FC<ModelsProps> = ({

const result = getSourceRepoConfigValue(openDeployModal.source, data);

await createModel({
const modelData = await createModel({
data: {
...result.values,
..._.omit(data, result.omits)
}
});
console.log('modelData:', modelData);
setOpenDeployModal({
...openDeployModal,
show: false
});
setTimeout(() => {
updateExpandedRowKeys([modelData.id]);
}, 300);
message.success(intl.formatMessage({ id: 'common.message.success' }));
} catch (error) {}
},
Expand All @@ -324,7 +346,7 @@ const Models: React.FC<ModelsProps> = ({
name: row.name,
async onOk() {
await deleteModel(row.id);
updateExpandedRowKeys([row.id]);
removeExpandedRowKey([row.id]);
rowSelection.removeSelectedKey(row.id);
}
});
Expand All @@ -336,7 +358,7 @@ const Models: React.FC<ModelsProps> = ({
async onOk() {
await handleBatchRequest(rowSelection.selectedRowKeys, deleteModel);
rowSelection.clearSelections();
updateExpandedRowKeys(rowSelection.selectedRowKeys);
removeExpandedRowKey(rowSelection.selectedRowKeys);
}
});
};
Expand Down Expand Up @@ -386,7 +408,7 @@ const Models: React.FC<ModelsProps> = ({
async onOk() {
await deleteModelInstance(row.id);
if (list.length === 1) {
updateExpandedRowKeys([row.model_id]);
removeExpandedRowKey([row.model_id]);
}
}
});
Expand Down
Loading

0 comments on commit 15f685f

Please sign in to comment.