Parcourir la source

add option Embed into webpage (#5065)

add option Embed into webpage

---------

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
tags/v0.17.0
so95 il y a 8 mois
Parent
révision
d6ba4bd255
Aucun compte lié à l'adresse e-mail de l'auteur

+ 3
- 0
web/src/components/api-service/embed-modal/index.less Voir le fichier

color: white; color: white;
.darkBg(); .darkBg();
} }
.optionContainer {
padding: 10px;
}

+ 47
- 2
web/src/components/api-service/embed-modal/index.tsx Voir le fichier

import { SharedFrom } from '@/constants/chat'; import { SharedFrom } from '@/constants/chat';
import { useTranslate } from '@/hooks/common-hooks'; import { useTranslate } from '@/hooks/common-hooks';
import { IModalProps } from '@/interfaces/common'; import { IModalProps } from '@/interfaces/common';
import { Card, Modal, Tabs, TabsProps, Typography } from 'antd';
import {
Card,
Checkbox,
Flex,
Form,
Modal,
Select,
Tabs,
TabsProps,
Typography,
} from 'antd';
import { useState } from 'react';


import { useIsDarkTheme } from '@/components/theme-provider'; import { useIsDarkTheme } from '@/components/theme-provider';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { languageOptions } from '@/locales/config';
import styles from './index.less'; import styles from './index.less';


const { Paragraph, Link } = Typography; const { Paragraph, Link } = Typography;
const { t } = useTranslate('chat'); const { t } = useTranslate('chat');
const isDarkTheme = useIsDarkTheme(); const isDarkTheme = useIsDarkTheme();


const [visibleAvatar, setVisibleAvatar] = useState(false);
const [locale, setLocale] = useState('');

const generateIframeSrc = () => {
let src = `${location.origin}/chat/share?shared_id=${token}&from=${form}&auth=${beta}`;
if (visibleAvatar) {
src += '&visible_avatar=1';
}
if (locale) {
src += `&locale=${locale}`;
}
return src;
};

const iframeSrc = generateIframeSrc();

const text = ` const text = `
~~~ html ~~~ html
<iframe <iframe
src="${location.origin}/chat/share?shared_id=${token}&from=${form}&auth=${beta}"
src="${iframeSrc}"
style="width: 100%; height: 100%; min-height: 600px" style="width: 100%; height: 100%; min-height: 600px"
frameborder="0" frameborder="0"
> >
extra={<CopyToClipboard text={text}></CopyToClipboard>} extra={<CopyToClipboard text={text}></CopyToClipboard>}
className={styles.codeCard} className={styles.codeCard}
> >
<Flex vertical className={styles.optionContainer}>
<h2>Option</h2>
<Form.Item label={t('avatarHidden')}>
<Checkbox
checked={visibleAvatar}
onChange={(e) => setVisibleAvatar(e.target.checked)}
></Checkbox>
</Form.Item>
<Form.Item label={t('locale')}>
<Select
placeholder="Select a locale"
onChange={(value) => setLocale(value)}
options={languageOptions}
style={{ width: '100%' }}
/>
</Form.Item>
</Flex>
<HightLightMarkdown>{text}</HightLightMarkdown> <HightLightMarkdown>{text}</HightLightMarkdown>
</Card> </Card>
), ),

+ 11
- 0
web/src/locales/config.ts Voir le fichier

}, },
}); });


export const languageOptions = [
{ value: 'en', label: 'English' },
{ value: 'zh', label: 'Chinese' },
{ value: 'zh-TRADITIONAL', label: 'Traditional Chinese' },
{ value: 'id', label: 'Indonesian' },
{ value: 'es', label: 'Spanish' },
{ value: 'vi', label: 'Vietnamese' },
{ value: 'ja', label: 'Japanese' },
{ value: 'pt-BR', label: 'Brazilian Portuguese' },
];

export default i18n; export default i18n;

+ 2
- 0
web/src/locales/en.ts Voir le fichier

keywordTip: `Apply LLM to analyze user's questions, extract keywords which will be emphesize during the relevance omputation.`, keywordTip: `Apply LLM to analyze user's questions, extract keywords which will be emphesize during the relevance omputation.`,
languageTip: languageTip:
'Allows sentence rewriting with the specified language or defaults to the latest question if not selected.', 'Allows sentence rewriting with the specified language or defaults to the latest question if not selected.',
avatarHidden: 'Hide avatar',
locale: 'Locale',
}, },
setting: { setting: {
profile: 'Profile', profile: 'Profile',

Chargement…
Annuler
Enregistrer