index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: passValue,
  18. onChange,
  19. }) => {
  20. const { t } = useTranslation()
  21. const { supportRetrievalMethods, rerankDefaultModel } = useProviderContext()
  22. const value = (() => {
  23. if (!passValue.reranking_model.reranking_model_name) {
  24. return {
  25. ...passValue,
  26. reranking_model: {
  27. reranking_provider_name: rerankDefaultModel?.model_provider.provider_name || '',
  28. reranking_model_name: rerankDefaultModel?.model_name || '',
  29. },
  30. }
  31. }
  32. return passValue
  33. })()
  34. return (
  35. <div className='space-y-2'>
  36. {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (
  37. <RadioCard
  38. icon={<Semantic className='w-4 h-4 text-[#7839EE]' />}
  39. title={t('dataset.retrieval.semantic_search.title')}
  40. description={t('dataset.retrieval.semantic_search.description')}
  41. isChosen={value.search_method === RETRIEVE_METHOD.semantic}
  42. onChosen={() => onChange({
  43. ...value,
  44. search_method: RETRIEVE_METHOD.semantic,
  45. })}
  46. chosenConfig={
  47. <RetrievalParamConfig
  48. type={RETRIEVE_METHOD.semantic}
  49. value={value}
  50. onChange={onChange}
  51. />
  52. }
  53. />
  54. )}
  55. {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (
  56. <RadioCard
  57. icon={<FileSearch02 className='w-4 h-4 text-[#7839EE]' />}
  58. title={t('dataset.retrieval.full_text_search.title')}
  59. description={t('dataset.retrieval.full_text_search.description')}
  60. isChosen={value.search_method === RETRIEVE_METHOD.fullText}
  61. onChosen={() => onChange({
  62. ...value,
  63. search_method: RETRIEVE_METHOD.fullText,
  64. })}
  65. chosenConfig={
  66. <RetrievalParamConfig
  67. type={RETRIEVE_METHOD.fullText}
  68. value={value}
  69. onChange={onChange}
  70. />
  71. }
  72. />
  73. )}
  74. {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (
  75. <RadioCard
  76. icon={<PatternRecognition className='w-4 h-4 text-[#7839EE]' />}
  77. title={
  78. <div className='flex items-center space-x-1'>
  79. <div>{t('dataset.retrieval.hybrid_search.title')}</div>
  80. <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>
  81. </div>
  82. }
  83. description={t('dataset.retrieval.hybrid_search.description')}
  84. isChosen={value.search_method === RETRIEVE_METHOD.hybrid}
  85. onChosen={() => onChange({
  86. ...value,
  87. search_method: RETRIEVE_METHOD.hybrid,
  88. })}
  89. chosenConfig={
  90. <RetrievalParamConfig
  91. type={RETRIEVE_METHOD.hybrid}
  92. value={value}
  93. onChange={onChange}
  94. />
  95. }
  96. />
  97. )}
  98. </div>
  99. )
  100. }
  101. export default React.memo(RetrievalMethodConfig)