balibabu
commited on
Commit
·
aaf24a6
1
Parent(s):
ac847bc
fix: Merge models of the same category #2479 (#2536)
Browse files### 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)
web/src/components/llm-select/index.tsx
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import { LlmModelType } from '@/constants/knowledge';
|
2 |
-
import {
|
3 |
import { Popover, Select } from 'antd';
|
4 |
import LlmSettingItems from '../llm-setting-items';
|
5 |
|
@@ -10,7 +10,10 @@ interface IProps {
|
|
10 |
}
|
11 |
|
12 |
const LLMSelect = ({ id, value, onChange }: IProps) => {
|
13 |
-
const modelOptions =
|
|
|
|
|
|
|
14 |
|
15 |
const content = (
|
16 |
<div style={{ width: 400 }}>
|
@@ -29,10 +32,7 @@ const LLMSelect = ({ id, value, onChange }: IProps) => {
|
|
29 |
destroyTooltipOnHide
|
30 |
>
|
31 |
<Select
|
32 |
-
options={
|
33 |
-
...modelOptions[LlmModelType.Chat],
|
34 |
-
...modelOptions[LlmModelType.Image2text],
|
35 |
-
]}
|
36 |
style={{ width: '100%' }}
|
37 |
dropdownStyle={{ display: 'none' }}
|
38 |
id={id}
|
|
|
1 |
import { LlmModelType } from '@/constants/knowledge';
|
2 |
+
import { useComposeLlmOptionsByModelTypes } from '@/hooks/llm-hooks';
|
3 |
import { Popover, Select } from 'antd';
|
4 |
import LlmSettingItems from '../llm-setting-items';
|
5 |
|
|
|
10 |
}
|
11 |
|
12 |
const LLMSelect = ({ id, value, onChange }: IProps) => {
|
13 |
+
const modelOptions = useComposeLlmOptionsByModelTypes([
|
14 |
+
LlmModelType.Chat,
|
15 |
+
LlmModelType.Image2text,
|
16 |
+
]);
|
17 |
|
18 |
const content = (
|
19 |
<div style={{ width: 400 }}>
|
|
|
32 |
destroyTooltipOnHide
|
33 |
>
|
34 |
<Select
|
35 |
+
options={modelOptions}
|
|
|
|
|
|
|
36 |
style={{ width: '100%' }}
|
37 |
dropdownStyle={{ display: 'none' }}
|
38 |
id={id}
|
web/src/components/llm-setting-items/index.tsx
CHANGED
@@ -7,7 +7,7 @@ import { Divider, Flex, Form, InputNumber, Select, Slider, Switch } from 'antd';
|
|
7 |
import camelCase from 'lodash/camelCase';
|
8 |
|
9 |
import { useTranslate } from '@/hooks/common-hooks';
|
10 |
-
import {
|
11 |
import { useCallback, useMemo } from 'react';
|
12 |
import styles from './index.less';
|
13 |
|
@@ -39,7 +39,10 @@ const LlmSettingItems = ({ prefix, formItemLayout = {} }: IProps) => {
|
|
39 |
|
40 |
const memorizedPrefix = useMemo(() => (prefix ? [prefix] : []), [prefix]);
|
41 |
|
42 |
-
const modelOptions =
|
|
|
|
|
|
|
43 |
|
44 |
return (
|
45 |
<>
|
@@ -50,13 +53,7 @@ const LlmSettingItems = ({ prefix, formItemLayout = {} }: IProps) => {
|
|
50 |
{...formItemLayout}
|
51 |
rules={[{ required: true, message: t('modelMessage') }]}
|
52 |
>
|
53 |
-
<Select
|
54 |
-
options={[
|
55 |
-
...modelOptions[LlmModelType.Chat],
|
56 |
-
...modelOptions[LlmModelType.Image2text],
|
57 |
-
]}
|
58 |
-
showSearch
|
59 |
-
/>
|
60 |
</Form.Item>
|
61 |
<Divider></Divider>
|
62 |
<Form.Item
|
|
|
7 |
import camelCase from 'lodash/camelCase';
|
8 |
|
9 |
import { useTranslate } from '@/hooks/common-hooks';
|
10 |
+
import { useComposeLlmOptionsByModelTypes } from '@/hooks/llm-hooks';
|
11 |
import { useCallback, useMemo } from 'react';
|
12 |
import styles from './index.less';
|
13 |
|
|
|
39 |
|
40 |
const memorizedPrefix = useMemo(() => (prefix ? [prefix] : []), [prefix]);
|
41 |
|
42 |
+
const modelOptions = useComposeLlmOptionsByModelTypes([
|
43 |
+
LlmModelType.Chat,
|
44 |
+
LlmModelType.Image2text,
|
45 |
+
]);
|
46 |
|
47 |
return (
|
48 |
<>
|
|
|
53 |
{...formItemLayout}
|
54 |
rules={[{ required: true, message: t('modelMessage') }]}
|
55 |
>
|
56 |
+
<Select options={modelOptions} showSearch />
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
</Form.Item>
|
58 |
<Divider></Divider>
|
59 |
<Form.Item
|
web/src/hooks/llm-hooks.ts
CHANGED
@@ -14,6 +14,7 @@ import userService from '@/services/user-service';
|
|
14 |
import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/common-util';
|
15 |
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
16 |
import { message } from 'antd';
|
|
|
17 |
import { useMemo } from 'react';
|
18 |
import { useTranslation } from 'react-i18next';
|
19 |
|
@@ -42,7 +43,7 @@ export const useSelectLlmOptions = () => {
|
|
42 |
label: key,
|
43 |
options: value.map((x) => ({
|
44 |
label: x.llm_name,
|
45 |
-
value: x.llm_name
|
46 |
disabled: !x.available,
|
47 |
})),
|
48 |
};
|
@@ -91,6 +92,26 @@ export const useSelectLlmOptionsByModelType = () => {
|
|
91 |
};
|
92 |
};
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
export const useFetchLlmFactoryList = (): ResponseGetType<IFactory[]> => {
|
95 |
const { data, isFetching: loading } = useQuery({
|
96 |
queryKey: ['factoryList'],
|
|
|
14 |
import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/common-util';
|
15 |
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
16 |
import { message } from 'antd';
|
17 |
+
import { DefaultOptionType } from 'antd/es/select';
|
18 |
import { useMemo } from 'react';
|
19 |
import { useTranslation } from 'react-i18next';
|
20 |
|
|
|
43 |
label: key,
|
44 |
options: value.map((x) => ({
|
45 |
label: x.llm_name,
|
46 |
+
value: `${x.llm_name}@${x.fid}`,
|
47 |
disabled: !x.available,
|
48 |
})),
|
49 |
};
|
|
|
92 |
};
|
93 |
};
|
94 |
|
95 |
+
export const useComposeLlmOptionsByModelTypes = (
|
96 |
+
modelTypes: LlmModelType[],
|
97 |
+
) => {
|
98 |
+
const allOptions = useSelectLlmOptionsByModelType();
|
99 |
+
|
100 |
+
return modelTypes.reduce<DefaultOptionType[]>((pre, cur) => {
|
101 |
+
const options = allOptions[cur];
|
102 |
+
options.forEach((x) => {
|
103 |
+
const item = pre.find((y) => y.label === x.label);
|
104 |
+
if (item) {
|
105 |
+
item.options.push(...x.options);
|
106 |
+
} else {
|
107 |
+
pre.push(x);
|
108 |
+
}
|
109 |
+
});
|
110 |
+
|
111 |
+
return pre;
|
112 |
+
}, []);
|
113 |
+
};
|
114 |
+
|
115 |
export const useFetchLlmFactoryList = (): ResponseGetType<IFactory[]> => {
|
116 |
const { data, isFetching: loading } = useQuery({
|
117 |
queryKey: ['factoryList'],
|