RetrievalSettings.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import TopKItem from '@/app/components/base/param-item/top-k-item'
  5. import ScoreThresholdItem from '@/app/components/base/param-item/score-threshold-item'
  6. import cn from '@/utils/classnames'
  7. type RetrievalSettingsProps = {
  8. topK: number
  9. scoreThreshold: number
  10. scoreThresholdEnabled: boolean
  11. isInHitTesting?: boolean
  12. isInRetrievalSetting?: boolean
  13. onChange: (data: { top_k?: number; score_threshold?: number; score_threshold_enabled?: boolean }) => void
  14. }
  15. const RetrievalSettings: FC<RetrievalSettingsProps> = ({
  16. topK,
  17. scoreThreshold,
  18. scoreThresholdEnabled,
  19. onChange,
  20. isInHitTesting = false,
  21. isInRetrievalSetting = false,
  22. }) => {
  23. const { t } = useTranslation()
  24. const handleScoreThresholdChange = (enabled: boolean) => {
  25. onChange({ score_threshold_enabled: enabled })
  26. }
  27. return (
  28. <div className={cn('flex flex-col gap-2 self-stretch', isInRetrievalSetting && 'w-full max-w-[480px]')}>
  29. {!isInHitTesting && !isInRetrievalSetting && <div className='flex h-7 pt-1 flex-col gap-2 self-stretch'>
  30. <label className='text-text-secondary system-sm-semibold'>{t('dataset.retrievalSettings')}</label>
  31. </div>}
  32. <div className={cn(
  33. 'flex gap-4 self-stretch',
  34. {
  35. 'flex-col': isInHitTesting,
  36. 'flex-row': isInRetrievalSetting,
  37. 'flex-col sm:flex-row': !isInHitTesting && !isInRetrievalSetting,
  38. },
  39. )}>
  40. <div className='flex flex-col gap-1 flex-grow'>
  41. <TopKItem
  42. className='grow'
  43. value={topK}
  44. onChange={(_key, v) => onChange({ top_k: v })}
  45. enable={true}
  46. />
  47. </div>
  48. <div className='flex flex-col gap-1 flex-grow'>
  49. <ScoreThresholdItem
  50. className='grow'
  51. value={scoreThreshold}
  52. onChange={(_key, v) => onChange({ score_threshold: v })}
  53. enable={scoreThresholdEnabled}
  54. hasSwitch={true}
  55. onSwitchChange={(_key, v) => handleScoreThresholdChange(v)}
  56. />
  57. </div>
  58. </div>
  59. </div>
  60. )
  61. }
  62. export default RetrievalSettings