選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

modify-retrieval-modal.tsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useRef, useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { RiCloseLine } from '@remixicon/react'
  6. import Toast from '../../base/toast'
  7. import { ModelTypeEnum } from '../../header/account-setting/model-provider-page/declarations'
  8. import type { RetrievalConfig } from '@/types/app'
  9. import RetrievalMethodConfig from '@/app/components/datasets/common/retrieval-method-config'
  10. import EconomicalRetrievalMethodConfig from '@/app/components/datasets/common/economical-retrieval-method-config'
  11. import Button from '@/app/components/base/button'
  12. import { isReRankModelSelected } from '@/app/components/datasets/common/check-rerank-model'
  13. import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
  14. import { useDocLink } from '@/context/i18n'
  15. type Props = {
  16. indexMethod: string
  17. value: RetrievalConfig
  18. isShow: boolean
  19. onHide: () => void
  20. onSave: (value: RetrievalConfig) => void
  21. }
  22. const ModifyRetrievalModal: FC<Props> = ({
  23. indexMethod,
  24. value,
  25. isShow,
  26. onHide,
  27. onSave,
  28. }) => {
  29. const ref = useRef(null)
  30. const { t } = useTranslation()
  31. const docLink = useDocLink()
  32. const [retrievalConfig, setRetrievalConfig] = useState(value)
  33. // useClickAway(() => {
  34. // if (ref)
  35. // onHide()
  36. // }, ref)
  37. const {
  38. modelList: rerankModelList,
  39. } = useModelListAndDefaultModelAndCurrentProviderAndModel(ModelTypeEnum.rerank)
  40. const handleSave = () => {
  41. if (
  42. !isReRankModelSelected({
  43. rerankModelList,
  44. retrievalConfig,
  45. indexMethod,
  46. })
  47. ) {
  48. Toast.notify({ type: 'error', message: t('appDebug.datasetConfig.rerankModelRequired') })
  49. return
  50. }
  51. onSave(retrievalConfig)
  52. }
  53. if (!isShow)
  54. return null
  55. return (
  56. <div
  57. className='flex w-full flex-col rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadow-2xl shadow-shadow-shadow-9'
  58. style={{
  59. height: 'calc(100vh - 72px)',
  60. }}
  61. ref={ref}
  62. >
  63. <div className='h-15 flex shrink-0 justify-between px-3 pb-1 pt-3.5'>
  64. <div className='text-base font-semibold text-text-primary'>
  65. <div>{t('datasetSettings.form.retrievalSetting.title')}</div>
  66. <div className='text-xs font-normal leading-[18px] text-text-tertiary'>
  67. <a
  68. target='_blank'
  69. rel='noopener noreferrer'
  70. href={docLink('/guides/knowledge-base/retrieval-test-and-citation#modify-text-retrieval-setting', {
  71. 'zh-Hans': '/guides/knowledge-base/retrieval-test-and-citation#修改文本检索方式',
  72. 'ja-JP': '/guides/knowledge-base/retrieval-test-and-citation',
  73. })}
  74. className='text-text-accent'
  75. >
  76. {t('datasetSettings.form.retrievalSetting.learnMore')}
  77. </a>
  78. {t('datasetSettings.form.retrievalSetting.description')}
  79. </div>
  80. </div>
  81. <div className='flex'>
  82. <div
  83. onClick={onHide}
  84. className='flex h-8 w-8 cursor-pointer items-center justify-center'
  85. >
  86. <RiCloseLine className='h-4 w-4 text-text-tertiary' />
  87. </div>
  88. </div>
  89. </div>
  90. <div className='px-4 py-2'>
  91. <div className='mb-1 text-[13px] font-semibold leading-6 text-text-secondary'>
  92. {t('datasetSettings.form.retrievalSetting.method')}
  93. </div>
  94. {indexMethod === 'high_quality'
  95. ? (
  96. <RetrievalMethodConfig
  97. value={retrievalConfig}
  98. onChange={setRetrievalConfig}
  99. />
  100. )
  101. : (
  102. <EconomicalRetrievalMethodConfig
  103. value={retrievalConfig}
  104. onChange={setRetrievalConfig}
  105. />
  106. )}
  107. </div>
  108. <div className='flex justify-end p-4 pt-2'>
  109. <Button className='mr-2 shrink-0' onClick={onHide}>{t('common.operation.cancel')}</Button>
  110. <Button variant='primary' className='shrink-0' onClick={handleSave} >{t('common.operation.save')}</Button>
  111. </div>
  112. </div>
  113. )
  114. }
  115. export default React.memo(ModifyRetrievalModal)