forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π fix: refactor user store and fix custom model list form (lobehub#2620)
* β»οΈ refactor: refactor user store * β»οΈ refactor: refactor the user trace * π fix: fix parser model * π fix: fix parser model * π fix: fix parser model * β»οΈ refactor: refactor modal * π fix: try to fix modal * π fix: fix model list select error * β test: add test for model list
- Loading branch information
Showing
60 changed files
with
1,238 additions
and
725 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
File renamed without changes.
78 changes: 78 additions & 0 deletions
78
src/app/(main)/settings/llm/components/ProviderModelList/ModelConfigModal/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,78 @@ | ||
import { Modal } from '@lobehub/ui'; | ||
import { Button, FormInstance } from 'antd'; | ||
import isEqual from 'fast-deep-equal'; | ||
import { memo, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { useUserStore } from '@/store/user'; | ||
import { modelConfigSelectors } from '@/store/user/slices/modelList/selectors'; | ||
|
||
import ModelConfigForm from './Form'; | ||
|
||
interface ModelConfigModalProps { | ||
provider?: string; | ||
showAzureDeployName?: boolean; | ||
} | ||
|
||
const ModelConfigModal = memo<ModelConfigModalProps>(({ showAzureDeployName, provider }) => { | ||
const { t } = useTranslation('setting'); | ||
const { t: tc } = useTranslation('common'); | ||
const [formInstance, setFormInstance] = useState<FormInstance>(); | ||
|
||
const [open, id, editingProvider, dispatchCustomModelCards, toggleEditingCustomModelCard] = | ||
useUserStore((s) => [ | ||
!!s.editingCustomCardModel && provider === s.editingCustomCardModel?.provider, | ||
s.editingCustomCardModel?.id, | ||
s.editingCustomCardModel?.provider, | ||
s.dispatchCustomModelCards, | ||
s.toggleEditingCustomModelCard, | ||
]); | ||
|
||
const modelCard = useUserStore( | ||
modelConfigSelectors.getCustomModelCard({ id, provider: editingProvider }), | ||
isEqual, | ||
); | ||
|
||
const closeModal = () => { | ||
toggleEditingCustomModelCard(undefined); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
destroyOnClose | ||
footer={[ | ||
<Button key="cancel" onClick={closeModal}> | ||
{tc('cancel')} | ||
</Button>, | ||
|
||
<Button | ||
key="ok" | ||
onClick={() => { | ||
if (!editingProvider || !id || !formInstance) return; | ||
const data = formInstance.getFieldsValue(); | ||
|
||
dispatchCustomModelCards(editingProvider as any, { id, type: 'update', value: data }); | ||
|
||
closeModal(); | ||
}} | ||
style={{ marginInlineStart: '16px' }} | ||
type="primary" | ||
> | ||
{tc('ok')} | ||
</Button>, | ||
]} | ||
maskClosable | ||
onCancel={closeModal} | ||
open={open} | ||
title={t('llm.customModelCards.modelConfig.modalTitle')} | ||
zIndex={1251} // Select is 1150 | ||
> | ||
<ModelConfigForm | ||
initialValues={modelCard} | ||
onFormInstanceReady={setFormInstance} | ||
showAzureDeployName={showAzureDeployName} | ||
/> | ||
</Modal> | ||
); | ||
}); | ||
export default ModelConfigModal; |
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
Oops, something went wrong.