### What problem does this PR solve? fix: Merge models of the same category #2479 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)tags/v0.12.0
| import { LlmModelType } from '@/constants/knowledge'; | import { LlmModelType } from '@/constants/knowledge'; | ||||
| import { useSelectLlmOptionsByModelType } from '@/hooks/llm-hooks'; | |||||
| import { useComposeLlmOptionsByModelTypes } from '@/hooks/llm-hooks'; | |||||
| import { Popover, Select } from 'antd'; | import { Popover, Select } from 'antd'; | ||||
| import LlmSettingItems from '../llm-setting-items'; | import LlmSettingItems from '../llm-setting-items'; | ||||
| } | } | ||||
| const LLMSelect = ({ id, value, onChange }: IProps) => { | const LLMSelect = ({ id, value, onChange }: IProps) => { | ||||
| const modelOptions = useSelectLlmOptionsByModelType(); | |||||
| const modelOptions = useComposeLlmOptionsByModelTypes([ | |||||
| LlmModelType.Chat, | |||||
| LlmModelType.Image2text, | |||||
| ]); | |||||
| const content = ( | const content = ( | ||||
| <div style={{ width: 400 }}> | <div style={{ width: 400 }}> | ||||
| destroyTooltipOnHide | destroyTooltipOnHide | ||||
| > | > | ||||
| <Select | <Select | ||||
| options={[ | |||||
| ...modelOptions[LlmModelType.Chat], | |||||
| ...modelOptions[LlmModelType.Image2text], | |||||
| ]} | |||||
| options={modelOptions} | |||||
| style={{ width: '100%' }} | style={{ width: '100%' }} | ||||
| dropdownStyle={{ display: 'none' }} | dropdownStyle={{ display: 'none' }} | ||||
| id={id} | id={id} |
| import camelCase from 'lodash/camelCase'; | import camelCase from 'lodash/camelCase'; | ||||
| import { useTranslate } from '@/hooks/common-hooks'; | import { useTranslate } from '@/hooks/common-hooks'; | ||||
| import { useSelectLlmOptionsByModelType } from '@/hooks/llm-hooks'; | |||||
| import { useComposeLlmOptionsByModelTypes } from '@/hooks/llm-hooks'; | |||||
| import { useCallback, useMemo } from 'react'; | import { useCallback, useMemo } from 'react'; | ||||
| import styles from './index.less'; | import styles from './index.less'; | ||||
| const memorizedPrefix = useMemo(() => (prefix ? [prefix] : []), [prefix]); | const memorizedPrefix = useMemo(() => (prefix ? [prefix] : []), [prefix]); | ||||
| const modelOptions = useSelectLlmOptionsByModelType(); | |||||
| const modelOptions = useComposeLlmOptionsByModelTypes([ | |||||
| LlmModelType.Chat, | |||||
| LlmModelType.Image2text, | |||||
| ]); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| {...formItemLayout} | {...formItemLayout} | ||||
| rules={[{ required: true, message: t('modelMessage') }]} | rules={[{ required: true, message: t('modelMessage') }]} | ||||
| > | > | ||||
| <Select | |||||
| options={[ | |||||
| ...modelOptions[LlmModelType.Chat], | |||||
| ...modelOptions[LlmModelType.Image2text], | |||||
| ]} | |||||
| showSearch | |||||
| /> | |||||
| <Select options={modelOptions} showSearch /> | |||||
| </Form.Item> | </Form.Item> | ||||
| <Divider></Divider> | <Divider></Divider> | ||||
| <Form.Item | <Form.Item |
| import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/common-util'; | import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/common-util'; | ||||
| import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||||
| import { message } from 'antd'; | import { message } from 'antd'; | ||||
| import { DefaultOptionType } from 'antd/es/select'; | |||||
| import { useMemo } from 'react'; | import { useMemo } from 'react'; | ||||
| import { useTranslation } from 'react-i18next'; | import { useTranslation } from 'react-i18next'; | ||||
| label: key, | label: key, | ||||
| options: value.map((x) => ({ | options: value.map((x) => ({ | ||||
| label: x.llm_name, | label: x.llm_name, | ||||
| value: x.llm_name, | |||||
| value: `${x.llm_name}@${x.fid}`, | |||||
| disabled: !x.available, | disabled: !x.available, | ||||
| })), | })), | ||||
| }; | }; | ||||
| }; | }; | ||||
| }; | }; | ||||
| export const useComposeLlmOptionsByModelTypes = ( | |||||
| modelTypes: LlmModelType[], | |||||
| ) => { | |||||
| const allOptions = useSelectLlmOptionsByModelType(); | |||||
| return modelTypes.reduce<DefaultOptionType[]>((pre, cur) => { | |||||
| const options = allOptions[cur]; | |||||
| options.forEach((x) => { | |||||
| const item = pre.find((y) => y.label === x.label); | |||||
| if (item) { | |||||
| item.options.push(...x.options); | |||||
| } else { | |||||
| pre.push(x); | |||||
| } | |||||
| }); | |||||
| return pre; | |||||
| }, []); | |||||
| }; | |||||
| export const useFetchLlmFactoryList = (): ResponseGetType<IFactory[]> => { | export const useFetchLlmFactoryList = (): ResponseGetType<IFactory[]> => { | ||||
| const { data, isFetching: loading } = useQuery({ | const { data, isFetching: loading } = useQuery({ | ||||
| queryKey: ['factoryList'], | queryKey: ['factoryList'], |