-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: xyinshen <[email protected]>
- Loading branch information
Showing
10 changed files
with
317 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useMemo, useCallback } from 'react'; | ||
import { | ||
EuiSpacer, | ||
EuiText, | ||
EuiComboBoxOptionOption, | ||
EuiLink, | ||
EuiFormRow, | ||
EuiComboBox, | ||
} from '@elastic/eui'; | ||
|
||
import { useController, useFormContext } from 'react-hook-form'; | ||
import { useMonitoring } from '../monitoring/use_monitoring'; | ||
|
||
export const ModelSource = () => { | ||
const { allExternalConnectors } = useMonitoring(); | ||
const CONNECTOR_OPTIONS = allExternalConnectors?.map((item) => { | ||
return Object.assign({}, { label: item.name, value: item.description }); | ||
}); | ||
const { control } = useFormContext<{ modelConnector: string }>(); | ||
|
||
const modelConnectorController = useController({ | ||
name: 'modelConnector', | ||
control, | ||
rules: { | ||
required: { | ||
value: true, | ||
message: '', | ||
}, | ||
}, | ||
}); | ||
const { ref: fileFormatInputRef, ...fileFormatField } = modelConnectorController.field; | ||
const selectedConnectorOption = useMemo(() => { | ||
if (fileFormatField.value) { | ||
return CONNECTOR_OPTIONS?.find((connector) => connector.value === fileFormatField.value); | ||
} | ||
}, [fileFormatField, CONNECTOR_OPTIONS]); | ||
|
||
const onConnectorChange = useCallback( | ||
(options: Array<EuiComboBoxOptionOption<string>>) => { | ||
const value = options[0]?.value; | ||
fileFormatField.onChange(value); | ||
}, | ||
[fileFormatField] | ||
); | ||
return ( | ||
<div> | ||
<EuiText size="s"> | ||
<h3>Model source</h3> | ||
</EuiText> | ||
<EuiText style={{ maxWidth: 725 }}> | ||
<small> | ||
External model source explained, connector provisioning, etc.{' '} | ||
<EuiLink external href="#"> | ||
Learn more | ||
</EuiLink> | ||
. | ||
</small> | ||
</EuiText> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow label="Model connector"> | ||
<EuiComboBox | ||
inputRef={fileFormatInputRef} | ||
options={CONNECTOR_OPTIONS} | ||
singleSelection={{ asPlainText: true }} | ||
selectedOptions={selectedConnectorOption ? [selectedConnectorOption] : []} | ||
placeholder="Select a connector" | ||
onChange={onConnectorChange} | ||
/> | ||
</EuiFormRow> | ||
</div> | ||
); | ||
}; |
128 changes: 128 additions & 0 deletions
128
public/components/register_model/pretrainedmodel_select.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useCallback, useState, Fragment, useEffect } from 'react'; | ||
import { | ||
EuiSpacer, | ||
EuiTextColor, | ||
EuiSelectable, | ||
EuiLink, | ||
EuiSelectableOption, | ||
EuiHighlight, | ||
} from '@elastic/eui'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { generatePath } from 'react-router-dom'; | ||
import { modelRepositoryManager } from '../../utils/model_repository_manager'; | ||
import { routerPaths } from '../../../common/router_paths'; | ||
interface IItem { | ||
label: string; | ||
checked?: 'on' | undefined; | ||
description: string; | ||
} | ||
interface Props { | ||
getPreSelected: (val: boolean) => void; | ||
} | ||
const renderModelOption = (option: IItem, searchValue: string) => { | ||
return ( | ||
<> | ||
<EuiHighlight search={searchValue}>{option.label}</EuiHighlight> | ||
<br /> | ||
<EuiTextColor color="subdued"> | ||
<small> | ||
<EuiHighlight search={searchValue}>{option.description}</EuiHighlight> | ||
</small> | ||
</EuiTextColor> | ||
</> | ||
); | ||
}; | ||
export const PreTrainedModelSelect = ({ getPreSelected }: Props) => { | ||
useEffect(() => { | ||
const subscribe = modelRepositoryManager.getPreTrainedModels$().subscribe((models) => { | ||
setModelRepoSelection( | ||
Object.keys(models).map((name) => ({ | ||
label: name, | ||
description: models[name].description, | ||
checked: undefined, | ||
})) | ||
); | ||
}); | ||
return () => { | ||
subscribe.unsubscribe(); | ||
}; | ||
}, []); | ||
const ShowRest = useCallback( | ||
(selected: boolean) => { | ||
getPreSelected(selected); | ||
}, | ||
[getPreSelected] | ||
); | ||
const [modelRepoSelection, setModelRepoSelection] = useState<Array<EuiSelectableOption<IItem>>>( | ||
[] | ||
); | ||
const history = useHistory(); | ||
const onChange = useCallback( | ||
(modelSelection: Array<EuiSelectableOption<IItem>>) => { | ||
setModelRepoSelection(modelSelection); | ||
ShowRest(true); | ||
}, | ||
[ShowRest] | ||
); | ||
useEffect(() => { | ||
const selectedOption = modelRepoSelection.find((option) => option.checked === 'on'); | ||
if (selectedOption?.label) { | ||
history.push( | ||
`${generatePath(routerPaths.registerModel, { id: undefined })}/?type=import&name=${ | ||
selectedOption?.label | ||
}&version=${selectedOption?.label}` | ||
); | ||
} | ||
}, [modelRepoSelection, history]); | ||
return ( | ||
<div> | ||
<small> | ||
<strong>Model</strong> | ||
</small> | ||
<EuiSpacer size="s" /> | ||
<div> | ||
<EuiTextColor color="subdued"> | ||
<small>For more information on each model, see </small> | ||
</EuiTextColor> | ||
<small> | ||
<EuiLink href="#" external> | ||
OpenSearch model repository documentation | ||
</EuiLink> | ||
</small> | ||
</div> | ||
<EuiSpacer size="m" /> | ||
<EuiSelectable | ||
aria-label="OpenSearch model repository models" | ||
searchable | ||
searchProps={{ | ||
'data-test-subj': 'findModel', | ||
placeholder: 'Find model', | ||
}} | ||
options={modelRepoSelection} | ||
onChange={onChange} | ||
singleSelection={true} | ||
noMatchesMessage="No model found" | ||
height={240} | ||
renderOption={renderModelOption} | ||
listProps={{ | ||
rowHeight: 50, | ||
'data-test-subj': 'opensearchModelList', | ||
showIcons: true, | ||
}} | ||
isLoading={modelRepoSelection.length === 0} | ||
> | ||
{(list, search) => ( | ||
<Fragment> | ||
{search} | ||
{list} | ||
</Fragment> | ||
)} | ||
</EuiSelectable> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.