index.tsx 3.9 KB

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