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.
✨ feat: support topic agent (lobehub#2683)
* ✨ feat: support topic agent * ✅ test: fix test * ✅ test: fix test * ✅ test: add tests * 🌐 chore: add i18n
- Loading branch information
Showing
36 changed files
with
383 additions
and
127 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use client'; | ||
|
||
import { Form, type ItemGroup } from '@lobehub/ui'; | ||
import { Form as AntForm } from 'antd'; | ||
import isEqual from 'fast-deep-equal'; | ||
import { memo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { FORM_STYLE } from '@/const/layoutTokens'; | ||
import ModelSelect from '@/features/ModelSelect'; | ||
import { useUserStore } from '@/store/user'; | ||
import { settingsSelectors } from '@/store/user/selectors'; | ||
|
||
import { useSyncSystemAgent } from './useSync'; | ||
|
||
type SettingItemGroup = ItemGroup; | ||
|
||
const Topic = memo(() => { | ||
const { t } = useTranslation('setting'); | ||
const [form] = AntForm.useForm(); | ||
|
||
const settings = useUserStore(settingsSelectors.currentSystemAgent, isEqual); | ||
const [updateSystemAgent] = useUserStore((s) => [s.updateSystemAgent]); | ||
|
||
const systemAgentSettings: SettingItemGroup = { | ||
children: [ | ||
{ | ||
children: ( | ||
<ModelSelect | ||
onChange={(props) => { | ||
updateSystemAgent('topic', props); | ||
}} | ||
/> | ||
), | ||
desc: t('systemAgent.topic.modelDesc'), | ||
label: t('systemAgent.topic.label'), | ||
name: ['topic', 'model'], | ||
}, | ||
], | ||
title: t('systemAgent.topic.title'), | ||
}; | ||
|
||
useSyncSystemAgent(form); | ||
|
||
return ( | ||
<Form | ||
form={form} | ||
initialValues={settings} | ||
items={[systemAgentSettings]} | ||
variant={'pure'} | ||
{...FORM_STYLE} | ||
/> | ||
); | ||
}); | ||
|
||
export default Topic; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { FormInstance } from 'antd'; | ||
import { useLayoutEffect } from 'react'; | ||
|
||
import { useUserStore } from '@/store/user'; | ||
|
||
export const useSyncSystemAgent = (form: FormInstance) => { | ||
useLayoutEffect(() => { | ||
// set the first time | ||
form.setFieldsValue(useUserStore.getState().settings.systemAgent); | ||
|
||
// sync with later updated settings | ||
const unsubscribe = useUserStore.subscribe( | ||
(s) => s.settings.systemAgent, | ||
(settings) => { | ||
form.setFieldsValue(settings); | ||
}, | ||
); | ||
|
||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, []); | ||
}; |
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.