modify-external-retrieval-modal.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { useState } from 'react'
  2. import {
  3. RiCloseLine,
  4. } from '@remixicon/react'
  5. import { useTranslation } from 'react-i18next'
  6. import RetrievalSettings from '../external-knowledge-base/create/RetrievalSettings'
  7. import Button from '@/app/components/base/button'
  8. import ActionButton from '@/app/components/base/action-button'
  9. type ModifyExternalRetrievalModalProps = {
  10. onClose: () => void
  11. onSave: (data: { top_k: number; score_threshold: number; score_threshold_enabled: boolean }) => void
  12. initialTopK: number
  13. initialScoreThreshold: number
  14. initialScoreThresholdEnabled: boolean
  15. }
  16. const ModifyExternalRetrievalModal: React.FC<ModifyExternalRetrievalModalProps> = ({
  17. onClose,
  18. onSave,
  19. initialTopK,
  20. initialScoreThreshold,
  21. initialScoreThresholdEnabled,
  22. }) => {
  23. const { t } = useTranslation()
  24. const [topK, setTopK] = useState(initialTopK)
  25. const [scoreThreshold, setScoreThreshold] = useState(initialScoreThreshold)
  26. const [scoreThresholdEnabled, setScoreThresholdEnabled] = useState(initialScoreThresholdEnabled)
  27. const handleSettingsChange = (data: { top_k?: number; score_threshold?: number; score_threshold_enabled?: boolean }) => {
  28. if (data.top_k !== undefined)
  29. setTopK(data.top_k)
  30. if (data.score_threshold !== undefined)
  31. setScoreThreshold(data.score_threshold)
  32. if (data.score_threshold_enabled !== undefined)
  33. setScoreThresholdEnabled(data.score_threshold_enabled)
  34. }
  35. const handleSave = () => {
  36. onSave({ top_k: topK, score_threshold: scoreThreshold, score_threshold_enabled: scoreThresholdEnabled })
  37. onClose()
  38. }
  39. return (
  40. <div className='absolute z-10 top-[36px] right-[14px] flex w-[320px] flex-col items-start rounded-2xl border-[0.5px]
  41. border-components-panel-border bg-components-panel-bg shadows-shadow-2xl'
  42. >
  43. <div className='flex p-4 pb-2 items-center justify-between self-stretch'>
  44. <div className='text-text-primary system-xl-semibold flex-grow'>{t('datasetHitTesting.settingTitle')}</div>
  45. <ActionButton className='ml-auto' onClick={onClose}>
  46. <RiCloseLine className='w-4 h-4 flex-shrink-0' />
  47. </ActionButton>
  48. </div>
  49. <div className='flex p-4 pt-2 flex-col justify-center items-start gap-4 self-stretch'>
  50. <RetrievalSettings
  51. topK={topK}
  52. scoreThreshold={scoreThreshold}
  53. scoreThresholdEnabled={scoreThresholdEnabled}
  54. onChange={handleSettingsChange}
  55. isInHitTesting={true}
  56. />
  57. </div>
  58. <div className='flex p-4 pt-2 justify-end items-end gap-1 w-full'>
  59. <Button className='flex-shrink-0 min-w-[72px]' onClick={onClose}>{t('common.operation.cancel')}</Button>
  60. <Button variant='primary' className='flex-shrink-0 min-w-[72px]' onClick={handleSave}>{t('common.operation.save')}</Button>
  61. </div>
  62. </div>
  63. )
  64. }
  65. export default ModifyExternalRetrievalModal