modify-retrieval-modal.tsx 4.3 KB

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