'use client' import type { FC } from 'react' import React from 'react' import { useCSVDownloader, } from 'react-papaparse' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' import { Download02 as DownloadIcon } from '@/app/components/base/icons/src/vender/solid/general' import { DocForm } from '@/models/datasets' import I18n from '@/context/i18n' import { LanguagesSupported } from '@/i18n/language' const CSV_TEMPLATE_QA_EN = [ ['question', 'answer'], ['question1', 'answer1'], ['question2', 'answer2'], ] const CSV_TEMPLATE_QA_CN = [ ['问题', '答案'], ['问题 1', '答案 1'], ['问题 2', '答案 2'], ] const CSV_TEMPLATE_EN = [ ['segment content'], ['content1'], ['content2'], ] const CSV_TEMPLATE_CN = [ ['分段内容'], ['内容 1'], ['内容 2'], ] const CSVDownload: FC<{ docForm: DocForm }> = ({ docForm }) => { const { t } = useTranslation() const { locale } = useContext(I18n) const { CSVDownloader, Type } = useCSVDownloader() const getTemplate = () => { if (locale === LanguagesSupported[1]) { if (docForm === DocForm.QA) return CSV_TEMPLATE_QA_CN return CSV_TEMPLATE_CN } if (docForm === DocForm.QA) return CSV_TEMPLATE_QA_EN return CSV_TEMPLATE_EN } return (
{t('share.generation.csvStructureTitle')}
{docForm === DocForm.QA && (
{t('datasetDocuments.list.batchModal.question')} {t('datasetDocuments.list.batchModal.answer')}
{t('datasetDocuments.list.batchModal.question')} 1 {t('datasetDocuments.list.batchModal.answer')} 1
{t('datasetDocuments.list.batchModal.question')} 2 {t('datasetDocuments.list.batchModal.answer')} 2
)} {docForm === DocForm.TEXT && (
{t('datasetDocuments.list.batchModal.contentTitle')}
{t('datasetDocuments.list.batchModal.content')} 1
{t('datasetDocuments.list.batchModal.content')} 2
)}
{t('datasetDocuments.list.batchModal.template')}
) } export default React.memo(CSVDownload)