chore: deploy model from local path

This commit is contained in:
jialin
2024-11-07 17:35:07 +08:00
parent 8bc67b323c
commit 93a6a77c2b
15 changed files with 270 additions and 77 deletions
+91 -40
View File
@@ -30,25 +30,9 @@ interface DataFormProps {
selectedModel: any;
isGGUF: boolean;
onOk: (values: FormData) => void;
onBackendChange?: (value: string) => void;
}
const sourceOptions = [
{
label: 'Hugging Face',
value: modelSourceMap.huggingface_value,
key: 'huggingface'
},
{
label: 'Ollama Library',
value: modelSourceMap.ollama_library_value,
key: 'ollama_library'
},
{
label: 'ModelScope',
value: modelSourceMap.modelscope_value,
key: 'model_scope'
}
];
const SEARCH_SOURCE = [
modelSourceMap.huggingface_value,
modelSourceMap.modelscope_value
@@ -62,6 +46,29 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
Array<GPUListItem & { label: string; value: string }>
>([]);
const sourceOptions = [
{
label: 'Hugging Face',
value: modelSourceMap.huggingface_value,
key: 'huggingface'
},
{
label: 'Ollama Library',
value: modelSourceMap.ollama_library_value,
key: 'ollama_library'
},
{
label: 'ModelScope',
value: modelSourceMap.modelscope_value,
key: 'model_scope'
},
{
label: intl.formatMessage({ id: 'models.form.localPath' }),
value: modelSourceMap.local_path_value,
key: 'local_path'
}
];
const getGPUList = async () => {
const data = await queryGPUList();
const list = _.map(data.items, (item: GPUListItem) => {
@@ -119,6 +126,16 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
}
};
const handleLocalPathBlur = (e: any) => {
const value = e.target.value;
const isEndwithGGUF = _.endsWith(value, '.gguf');
if (isEndwithGGUF) {
props.onBackendChange?.(backendOptionsMap.llamaBox);
} else {
props.onBackendChange?.(backendOptionsMap.vllm);
}
};
const renderHuggingfaceFields = () => {
return (
<>
@@ -246,6 +263,34 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
);
};
const renderLocalPathFields = () => {
return (
<>
<Form.Item<FormData>
name="local_path"
key="local_path"
rules={[
{
required: true,
message: intl.formatMessage(
{
id: 'common.form.rule.input'
},
{ name: intl.formatMessage({ id: 'models.form.filePath' }) }
)
}
]}
>
<SealInput.Input
onBlur={handleLocalPathBlur}
label={intl.formatMessage({ id: 'models.form.filePath' })}
required
></SealInput.Input>
</Form.Item>
</>
);
};
const renderFieldsBySource = useMemo(() => {
if (SEARCH_SOURCE.includes(props.source)) {
return renderHuggingfaceFields();
@@ -258,6 +303,9 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
if (props.source === modelSourceMap.s3_value) {
return renderS3Fields();
}
if (props.source === modelSourceMap.local_path_value) {
return renderLocalPathFields();
}
return null;
}, [props.source, isGGUF, intl]);
@@ -332,31 +380,34 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
required
></SealInput.Input>
</Form.Item>
<Form.Item<FormData>
name="source"
rules={[
{
<Form.Item<FormData>
name="source"
rules={[
{
required: true,
message: intl.formatMessage(
{
id: 'common.form.rule.select'
},
{ name: intl.formatMessage({ id: 'models.form.source' }) }
)
}
]}
>
{
required: true,
message: intl.formatMessage(
{
id: 'common.form.rule.select'
},
{ name: intl.formatMessage({ id: 'models.form.source' }) }
)
<SealSelect
disabled={true}
label={intl.formatMessage({
id: 'models.form.source'
})}
options={sourceOptions}
required
></SealSelect>
}
]}
>
{
<SealSelect
disabled={true}
label={intl.formatMessage({
id: 'models.form.source'
})}
options={sourceOptions}
required
></SealSelect>
}
</Form.Item>
</Form.Item>
}
{renderFieldsBySource}
<Form.Item<FormData>
name="replicas"