index.tsx 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import RetrievalParamConfig from '../retrieval-param-config'
  6. import type { RetrievalConfig } from '@/types/app'
  7. import { RETRIEVE_METHOD } from '@/types/app'
  8. import RadioCard from '@/app/components/base/radio-card'
  9. import { PatternRecognition, Semantic } from '@/app/components/base/icons/src/vender/solid/development'
  10. import { FileSearch02 } from '@/app/components/base/icons/src/vender/solid/files'
  11. import { useProviderContext } from '@/context/provider-context'
  12. type Props = {
  13. value: RetrievalConfig
  14. onChange: (value: RetrievalConfig) => void
  15. }
  16. const RetrievalMethodConfig: FC<Props> = ({
  17. value,
  18. onChange,
  19. }) => {
  20. const { t } = useTranslation()
  21. const { supportRetrievalMethods } = useProviderContext()
  22. return (
  23. <div className='space-y-2'>
  24. {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (
  25. <RadioCard
  26. icon={<Semantic className='w-4 h-4 text-[#7839EE]' />}
  27. title={t('dataset.retrieval.semantic_search.title')}
  28. description={t('dataset.retrieval.semantic_search.description')}
  29. isChosen={value.search_method === RETRIEVE_METHOD.semantic}
  30. onChosen={() => onChange({
  31. ...value,
  32. search_method: RETRIEVE_METHOD.semantic,
  33. })}
  34. chosenConfig={
  35. <RetrievalParamConfig
  36. type={RETRIEVE_METHOD.semantic}
  37. value={value}
  38. onChange={onChange}
  39. />
  40. }
  41. />
  42. )}
  43. {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (
  44. <RadioCard
  45. icon={<FileSearch02 className='w-4 h-4 text-[#7839EE]' />}
  46. title={t('dataset.retrieval.full_text_search.title')}
  47. description={t('dataset.retrieval.full_text_search.description')}
  48. isChosen={value.search_method === RETRIEVE_METHOD.fullText}
  49. onChosen={() => onChange({
  50. ...value,
  51. search_method: RETRIEVE_METHOD.fullText,
  52. })}
  53. chosenConfig={
  54. <RetrievalParamConfig
  55. type={RETRIEVE_METHOD.fullText}
  56. value={value}
  57. onChange={onChange}
  58. />
  59. }
  60. />
  61. )}
  62. {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (
  63. <RadioCard
  64. icon={<PatternRecognition className='w-4 h-4 text-[#7839EE]' />}
  65. title={
  66. <div className='flex items-center space-x-1'>
  67. <div>{t('dataset.retrieval.hybrid_search.title')}</div>
  68. <div className='flex h-full items-center px-1.5 rounded-md border border-[#E0EAFF] text-xs font-medium text-[#444CE7]'>{t('dataset.retrieval.hybrid_search.recommend')}</div>
  69. </div>
  70. }
  71. description={t('dataset.retrieval.hybrid_search.description')}
  72. isChosen={value.search_method === RETRIEVE_METHOD.hybrid}
  73. onChosen={() => onChange({
  74. ...value,
  75. search_method: RETRIEVE_METHOD.hybrid,
  76. })}
  77. chosenConfig={
  78. <RetrievalParamConfig
  79. type={RETRIEVE_METHOD.hybrid}
  80. value={value}
  81. onChange={onChange}
  82. />
  83. }
  84. />
  85. )}
  86. </div>
  87. )
  88. }
  89. export default React.memo(RetrievalMethodConfig)