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 Moonshot AI Provider (lobehub#1232)
* ✨ feat: support moonshot * 📝 docs: update documents * 🎨 chore: clean code
- Loading branch information
Showing
29 changed files
with
367 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,7 @@ ENV GOOGLE_API_KEY "" | |
# Zhipu | ||
ENV ZHIPU_API_KEY "" | ||
|
||
# Moonshot | ||
ENV MOONSHOT_API_KEY "" | ||
|
||
CMD ["node", "server.js"] |
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,77 @@ | ||
import { Moonshot } from '@lobehub/icons'; | ||
import { Form, type ItemGroup } from '@lobehub/ui'; | ||
import { Form as AntForm, Input, Switch } from 'antd'; | ||
import { useTheme } from 'antd-style'; | ||
import { debounce } from 'lodash-es'; | ||
import { memo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import { FORM_STYLE } from '@/const/layoutTokens'; | ||
import { ModelProvider } from '@/libs/agent-runtime'; | ||
import { useGlobalStore } from '@/store/global'; | ||
import { modelProviderSelectors } from '@/store/global/selectors'; | ||
|
||
import Checker from '../Checker'; | ||
import { LLMProviderApiTokenKey, LLMProviderConfigKey } from '../const'; | ||
import { useSyncSettings } from '../useSyncSettings'; | ||
|
||
const providerKey = 'moonshot'; | ||
|
||
const MoonshotProvider = memo(() => { | ||
const { t } = useTranslation('setting'); | ||
const [form] = AntForm.useForm(); | ||
const theme = useTheme(); | ||
const [toggleProviderEnabled, setSettings] = useGlobalStore((s) => [ | ||
s.toggleProviderEnabled, | ||
s.setSettings, | ||
]); | ||
const enabled = useGlobalStore(modelProviderSelectors.enableMoonshot); | ||
|
||
useSyncSettings(form); | ||
|
||
const model: ItemGroup = { | ||
children: [ | ||
{ | ||
children: ( | ||
<Input.Password | ||
autoComplete={'new-password'} | ||
placeholder={t('llm.Moonshot.token.placeholder')} | ||
/> | ||
), | ||
desc: t('llm.Moonshot.token.desc'), | ||
label: t('llm.Moonshot.token.title'), | ||
name: [LLMProviderConfigKey, providerKey, LLMProviderApiTokenKey], | ||
}, | ||
{ | ||
children: <Checker model={'moonshot-v1-8k'} provider={ModelProvider.Moonshot} />, | ||
desc: t('llm.checker.desc'), | ||
label: t('llm.checker.title'), | ||
minWidth: undefined, | ||
}, | ||
], | ||
defaultActive: enabled, | ||
extra: ( | ||
<Switch | ||
onChange={(enabled) => { | ||
toggleProviderEnabled(providerKey, enabled); | ||
}} | ||
value={enabled} | ||
/> | ||
), | ||
title: ( | ||
<Flexbox align={'center'} gap={8} horizontal> | ||
<Moonshot.Combine | ||
color={theme.isDarkMode ? theme.colorText : Moonshot.colorPrimary} | ||
size={24} | ||
/> | ||
</Flexbox> | ||
), | ||
}; | ||
|
||
return ( | ||
<Form form={form} items={[model]} onValuesChange={debounce(setSettings, 100)} {...FORM_STYLE} /> | ||
); | ||
}); | ||
|
||
export default MoonshotProvider; |
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,24 @@ | ||
import { ModelProviderCard } from '@/types/llm'; | ||
|
||
const Moonshot: ModelProviderCard = { | ||
chatModels: [ | ||
{ | ||
displayName: 'Moonshot V1 8K', | ||
id: 'moonshot-v1-8k', | ||
tokens: 8192, | ||
}, | ||
{ | ||
displayName: 'Moonshot V1 32K', | ||
id: 'moonshot-v1-32k', | ||
tokens: 32_768, | ||
}, | ||
{ | ||
displayName: 'Moonshot V1 128K', | ||
id: 'moonshot-v1-128k', | ||
tokens: 128_000, | ||
}, | ||
], | ||
id: 'moonshot', | ||
}; | ||
|
||
export default Moonshot; |
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.