Skip to content

Commit

Permalink
feat: add SystemModelSettingModal (#127)
Browse files Browse the repository at this point in the history
* feat: add the model

* feat: add SystemModelSettingModal
  • Loading branch information
cike8899 committed Mar 15, 2024
1 parent 2447f95 commit a0f1e1f
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 66 deletions.
14 changes: 14 additions & 0 deletions web/src/assets/svg/more-model.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion web/src/hooks/commonHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export const useSetModalState = () => {
setVisible(false);
};

return { visible, showModal, hideModal };
const switchVisible = () => {
setVisible(!visible);
};

return { visible, showModal, hideModal, switchVisible };
};

export const useDeepCompareEffect = (
Expand Down
44 changes: 35 additions & 9 deletions web/src/hooks/llmHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { useCallback, useEffect, useMemo } from 'react';
import { useDispatch, useSelector } from 'umi';

export const useFetchLlmList = (modelType: LlmModelType) => {
export const useFetchLlmList = (modelType?: LlmModelType) => {
const dispatch = useDispatch();

const fetchLlmList = useCallback(() => {
Expand Down Expand Up @@ -85,19 +85,20 @@ export const useFetchLlmFactoryListOnMount = () => {
return list;
};

export type LlmItem = { name: string; logo: string } & IMyLlmValue;

export const useFetchMyLlmListOnMount = () => {
const dispatch = useDispatch();
const llmList = useSelectMyLlmList();
const factoryList = useSelectLlmFactoryList();

const list: Array<{ name: string; logo: string } & IMyLlmValue> =
useMemo(() => {
return Object.entries(llmList).map(([key, value]) => ({
name: key,
logo: factoryList.find((x) => x.name === key)?.logo ?? '',
...value,
}));
}, [llmList, factoryList]);
const list: Array<LlmItem> = useMemo(() => {
return Object.entries(llmList).map(([key, value]) => ({
name: key,
logo: factoryList.find((x) => x.name === key)?.logo ?? '',
...value,
}));
}, [llmList, factoryList]);

const fetchMyLlmList = useCallback(() => {
dispatch({
Expand Down Expand Up @@ -135,3 +136,28 @@ export const useSaveApiKey = () => {

return saveApiKey;
};

export interface ISystemModelSettingSavingParams {
tenant_id: string;
name?: string;
asr_id: string;
embd_id: string;
img2txt_id: string;
llm_id: string;
}

export const useSaveTenantInfo = () => {
const dispatch = useDispatch();

const saveTenantInfo = useCallback(
(savingParams: ISystemModelSettingSavingParams) => {
return dispatch<any>({
type: 'settingModel/set_tenant_info',
payload: savingParams,
});
},
[dispatch],
);

return saveTenantInfo;
};
4 changes: 3 additions & 1 deletion web/src/pages/setting/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const model: DvaModel<SettingModelState> = {
}
},
*my_llm({ payload = {} }, { call, put }) {
const { data } = yield call(userService.my_llm, payload);
const { data } = yield call(userService.my_llm);
const { retcode, data: res } = data;
if (retcode === 0) {
yield put({
Expand All @@ -158,6 +158,8 @@ const model: DvaModel<SettingModelState> = {
const { retcode } = data;
if (retcode === 0) {
message.success('Modified!');
yield put({ type: 'my_llm' });
yield put({ type: 'factories_list' });
yield put({
type: 'updateState',
});
Expand Down
27 changes: 21 additions & 6 deletions web/src/pages/user-setting/components/setting-title/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { Typography } from 'antd';
import { SettingOutlined } from '@ant-design/icons';
import { Button, Flex, Typography } from 'antd';

const { Title, Paragraph } = Typography;

interface IProps {
title: string;
description: string;
showRightButton?: boolean;
clickButton?: () => void;
}

const SettingTitle = ({ title, description }: IProps) => {
const SettingTitle = ({
title,
description,
clickButton,
showRightButton = false,
}: IProps) => {
return (
<div>
<Title level={5}>{title}</Title>
<Paragraph>{description}</Paragraph>
</div>
<Flex align="center" justify={'space-between'}>
<div>
<Title level={5}>{title}</Title>
<Paragraph>{description}</Paragraph>
</div>
{showRightButton && (
<Button type={'primary'} onClick={clickButton}>
<SettingOutlined></SettingOutlined> System Model Settings
</Button>
)}
</Flex>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ApiKeyModal = ({
form={form}
>
<Form.Item<FieldType>
label="Api key"
label="Api-Key"
name="api_key"
rules={[{ required: true, message: 'Please input api key!' }]}
>
Expand Down
60 changes: 58 additions & 2 deletions web/src/pages/user-setting/setting-model/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { useSetModalState } from '@/hooks/commonHooks';
import { IApiKeySavingParams, useSaveApiKey } from '@/hooks/llmHooks';
import {
IApiKeySavingParams,
ISystemModelSettingSavingParams,
useFetchLlmList,
useSaveApiKey,
useSaveTenantInfo,
} from '@/hooks/llmHooks';
import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
import {
useFetchTenantInfo,
useSelectTenantInfo,
} from '@/hooks/userSettingHook';
import { useCallback, useState } from 'react';

type SavingParamsState = Omit<IApiKeySavingParams, 'api_key'>;
Expand All @@ -20,7 +30,7 @@ export const useSubmitApiKey = () => {
async (apiKey: string) => {
const ret = await saveApiKey({ ...savingParams, api_key: apiKey });

if (ret.retcode === 0) {
if (ret === 0) {
hideApiKeyModal();
}
},
Expand Down Expand Up @@ -48,3 +58,49 @@ export const useSubmitApiKey = () => {
showApiKeyModal: onShowApiKeyModal,
};
};

export const useSubmitSystemModelSetting = () => {
const systemSetting = useSelectTenantInfo();
const loading = useOneNamespaceEffectsLoading('settingModel', [
'set_tenant_info',
]);
const saveSystemModelSetting = useSaveTenantInfo();
const {
visible: systemSettingVisible,
hideModal: hideSystemSettingModal,
showModal: showSystemSettingModal,
} = useSetModalState();

const onSystemSettingSavingOk = useCallback(
async (
payload: Omit<ISystemModelSettingSavingParams, 'tenant_id' | 'name'>,
) => {
const ret = await saveSystemModelSetting({
tenant_id: systemSetting.tenant_id,
name: systemSetting.name,
...payload,
});

if (ret === 0) {
hideSystemSettingModal();
}
},
[hideSystemSettingModal, saveSystemModelSetting, systemSetting],
);

return {
saveSystemModelSettingLoading: loading,
onSystemSettingSavingOk,
systemSettingVisible,
hideSystemSettingModal,
showSystemSettingModal,
};
};

export const useFetchSystemModelSettingOnMount = () => {
const systemSetting = useSelectTenantInfo();
useFetchLlmList();
useFetchTenantInfo();

return systemSetting;
};
17 changes: 17 additions & 0 deletions web/src/pages/user-setting/setting-model/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,21 @@
.factoryOperationWrapper {
text-align: right;
}
.modelItem {
}
.llmList {
padding-top: 10px;
}
.toBeAddedCard {
border-radius: 24px;
border: 1px solid #eaecf0;
background: #e3f0ff;
box-shadow: 0px 1px 2px 0px rgba(16, 24, 40, 0.05);
}
.addedCard {
border-radius: 18px;
border: 1px solid #eaecf0;
background: #e6e7eb;
box-shadow: 0px 1px 2px 0px rgba(16, 24, 40, 0.05);
}
}
Loading

0 comments on commit a0f1e1f

Please sign in to comment.