-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: rename the key to enabledModels
- Loading branch information
Showing
11 changed files
with
135 additions
and
84 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 was deleted.
Oops, something went wrong.
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
30 changes: 30 additions & 0 deletions
30
src/app/settings/llm/components/ProviderModelList/CustomModelOption.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,30 @@ | ||
import { Typography } from 'antd'; | ||
import isEqual from 'fast-deep-equal'; | ||
import { memo } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import ModelIcon from '@/components/ModelIcon'; | ||
import { ModelInfoTags } from '@/components/ModelSelect'; | ||
import { useGlobalStore } from '@/store/global'; | ||
import { modelProviderSelectors } from '@/store/global/selectors'; | ||
|
||
const CustomModelOption = memo<{ displayName: string; id: string }>(({ displayName, id: id }) => { | ||
const model = useGlobalStore((s) => modelProviderSelectors.modelCardById(id)(s), isEqual); | ||
|
||
return ( | ||
<Flexbox align={'center'} gap={8} horizontal> | ||
<ModelIcon model={id} size={32} /> | ||
<Flexbox> | ||
<Flexbox align={'center'} gap={8} horizontal> | ||
{displayName} | ||
<ModelInfoTags directionReverse placement={'top'} {...model!} /> | ||
</Flexbox> | ||
<Typography.Text style={{ fontSize: 12 }} type={'secondary'}> | ||
{id} | ||
</Typography.Text> | ||
</Flexbox> | ||
</Flexbox> | ||
); | ||
}); | ||
|
||
export default CustomModelOption; |
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
73 changes: 73 additions & 0 deletions
73
src/app/settings/llm/components/ProviderModelList/index.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,73 @@ | ||
import { Select } from 'antd'; | ||
import { css, cx } from 'antd-style'; | ||
import isEqual from 'fast-deep-equal'; | ||
import { memo } from 'react'; | ||
|
||
import { filterEnabledModels } from '@/config/modelProviders'; | ||
import { useGlobalStore } from '@/store/global'; | ||
import { modelConfigSelectors, modelProviderSelectors } from '@/store/global/selectors'; | ||
import { GlobalLLMProviderKey } from '@/types/settings'; | ||
|
||
import CustomModelOption from './CustomModelOption'; | ||
import OptionRender from './Option'; | ||
|
||
const popup = css` | ||
&.ant-select-dropdown { | ||
.ant-select-item-option-selected { | ||
font-weight: normal; | ||
} | ||
} | ||
`; | ||
|
||
interface CustomModelSelectProps { | ||
onChange?: (value: string[]) => void; | ||
placeholder?: string; | ||
provider: string; | ||
value?: string[]; | ||
} | ||
|
||
const ProviderModelListSelect = memo<CustomModelSelectProps>( | ||
({ provider, placeholder, onChange }) => { | ||
const providerCard = useGlobalStore( | ||
(s) => modelProviderSelectors.providerModelList(s).find((s) => s.id === provider), | ||
isEqual, | ||
); | ||
const providerConfig = useGlobalStore((s) => | ||
modelConfigSelectors.providerConfig(provider as GlobalLLMProviderKey)(s), | ||
); | ||
|
||
const defaultEnableModel = providerCard ? filterEnabledModels(providerCard) : []; | ||
|
||
const chatModels = providerCard?.chatModels || []; | ||
|
||
return ( | ||
<Select<string[]> | ||
allowClear | ||
defaultValue={defaultEnableModel} | ||
mode="tags" | ||
onChange={(value) => { | ||
onChange?.(value.filter(Boolean)); | ||
}} | ||
optionFilterProp="label" | ||
optionRender={({ label, value }) => { | ||
console.log(value); | ||
// model is in the chatModels | ||
if (chatModels.some((c) => c.id === value)) | ||
return <OptionRender displayName={label as string} id={value as string} />; | ||
|
||
// model is user defined in client | ||
return <CustomModelOption displayName={label as string} id={value as string} />; | ||
}} | ||
options={chatModels.map((model) => ({ | ||
label: model.displayName || model.id, | ||
value: model.id, | ||
}))} | ||
placeholder={placeholder} | ||
popupClassName={cx(popup)} | ||
value={providerConfig?.enabledModels.filter(Boolean)} | ||
/> | ||
); | ||
}, | ||
); | ||
|
||
export default ProviderModelListSelect; |
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