|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { Markdown } from '@lobehub/ui'; |
| 4 | +import { createStyles } from 'antd-style'; |
| 5 | +import { useTranslation } from 'react-i18next'; |
| 6 | + |
| 7 | +import { FormPassword } from '@/components/FormInput'; |
| 8 | +import { VertexAIProviderCard } from '@/config/modelProviders'; |
| 9 | +import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra'; |
| 10 | +import { GlobalLLMProviderKey } from '@/types/user/settings'; |
| 11 | + |
| 12 | +import { KeyVaultsConfigKey, LLMProviderApiTokenKey } from '../../const'; |
| 13 | +import { SkeletonInput } from '../../features/ProviderConfig'; |
| 14 | +import { ProviderItem } from '../../type'; |
| 15 | +import ProviderDetail from '../[id]'; |
| 16 | + |
| 17 | +const useStyles = createStyles(({ css, token }) => ({ |
| 18 | + markdown: css` |
| 19 | + p { |
| 20 | + color: ${token.colorTextDescription} !important; |
| 21 | + } |
| 22 | + `, |
| 23 | + tip: css` |
| 24 | + font-size: 12px; |
| 25 | + color: ${token.colorTextDescription}; |
| 26 | + `, |
| 27 | +})); |
| 28 | + |
| 29 | +const providerKey: GlobalLLMProviderKey = 'vertexai'; |
| 30 | + |
| 31 | +// Same as OpenAIProvider, but replace API Key with HuggingFace Access Token |
| 32 | +const useProviderCard = (): ProviderItem => { |
| 33 | + const { t } = useTranslation('modelProvider'); |
| 34 | + const { styles } = useStyles(); |
| 35 | + const isLoading = useAiInfraStore(aiProviderSelectors.isAiProviderConfigLoading(providerKey)); |
| 36 | + |
| 37 | + return { |
| 38 | + ...VertexAIProviderCard, |
| 39 | + apiKeyItems: [ |
| 40 | + { |
| 41 | + children: isLoading ? ( |
| 42 | + <SkeletonInput /> |
| 43 | + ) : ( |
| 44 | + <FormPassword |
| 45 | + autoComplete={'new-password'} |
| 46 | + placeholder={t('vertexai.apiKey.placeholder')} |
| 47 | + /> |
| 48 | + ), |
| 49 | + desc: ( |
| 50 | + <Markdown className={styles.markdown} fontSize={12} variant={'chat'}> |
| 51 | + {t('vertexai.apiKey.desc')} |
| 52 | + </Markdown> |
| 53 | + ), |
| 54 | + label: t('vertexai.apiKey.title'), |
| 55 | + name: [KeyVaultsConfigKey, LLMProviderApiTokenKey], |
| 56 | + }, |
| 57 | + ], |
| 58 | + }; |
| 59 | +}; |
| 60 | + |
| 61 | +const Page = () => { |
| 62 | + const card = useProviderCard(); |
| 63 | + |
| 64 | + return <ProviderDetail {...card} />; |
| 65 | +}; |
| 66 | + |
| 67 | +export default Page; |
0 commit comments