index.tsx 3.8 KB

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