Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

panel.tsx 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import type { FC } from 'react'
  2. import {
  3. memo,
  4. useCallback,
  5. } from 'react'
  6. import { useTranslation } from 'react-i18next'
  7. import type { KnowledgeBaseNodeType } from './types'
  8. import {
  9. ChunkStructureEnum,
  10. IndexMethodEnum,
  11. } from './types'
  12. import ChunkStructure from './components/chunk-structure'
  13. import IndexMethod from './components/index-method'
  14. import RetrievalSetting from './components/retrieval-setting'
  15. import EmbeddingModel from './components/embedding-model'
  16. import { useConfig } from './hooks/use-config'
  17. import type { NodePanelProps } from '@/app/components/workflow/types'
  18. import {
  19. BoxGroup,
  20. BoxGroupField,
  21. Group,
  22. } from '@/app/components/workflow/nodes/_base/components/layout'
  23. import Split from '../_base/components/split'
  24. import { useNodesReadOnly } from '@/app/components/workflow/hooks'
  25. import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
  26. import type { Var } from '@/app/components/workflow/types'
  27. const Panel: FC<NodePanelProps<KnowledgeBaseNodeType>> = ({
  28. id,
  29. data,
  30. }) => {
  31. const { t } = useTranslation()
  32. const { nodesReadOnly } = useNodesReadOnly()
  33. const {
  34. handleChunkStructureChange,
  35. handleIndexMethodChange,
  36. handleKeywordNumberChange,
  37. handleEmbeddingModelChange,
  38. handleRetrievalSearchMethodChange,
  39. handleHybridSearchModeChange,
  40. handleWeighedScoreChange,
  41. handleRerankingModelChange,
  42. handleTopKChange,
  43. handleScoreThresholdChange,
  44. handleScoreThresholdEnabledChange,
  45. handleInputVariableChange,
  46. } = useConfig(id)
  47. const filterVar = useCallback((variable: Var) => {
  48. if (!data.chunk_structure) return false
  49. switch (data.chunk_structure) {
  50. case ChunkStructureEnum.general:
  51. return variable.schemaType === 'general_structure'
  52. case ChunkStructureEnum.parent_child:
  53. return variable.schemaType === 'parent_child_structure'
  54. case ChunkStructureEnum.question_answer:
  55. return variable.schemaType === 'qa_structure'
  56. default:
  57. return false
  58. }
  59. }, [data.chunk_structure])
  60. return (
  61. <div>
  62. <Group
  63. className='py-3'
  64. withBorderBottom={!!data.chunk_structure}
  65. >
  66. <ChunkStructure
  67. chunkStructure={data.chunk_structure}
  68. onChunkStructureChange={handleChunkStructureChange}
  69. readonly={nodesReadOnly}
  70. />
  71. </Group>
  72. {
  73. data.chunk_structure && (
  74. <>
  75. <BoxGroupField
  76. boxGroupProps={{
  77. boxProps: { withBorderBottom: true },
  78. }}
  79. fieldProps={{
  80. fieldTitleProps: {
  81. title: t('workflow.nodes.common.inputVars'),
  82. },
  83. }}
  84. >
  85. <VarReferencePicker
  86. nodeId={id}
  87. isShowNodeName
  88. value={data.index_chunk_variable_selector}
  89. onChange={handleInputVariableChange}
  90. readonly={nodesReadOnly}
  91. filterVar={filterVar}
  92. isFilterFileVar
  93. isSupportFileVar={false}
  94. preferSchemaType
  95. />
  96. </BoxGroupField>
  97. <BoxGroup>
  98. <div className='space-y-3'>
  99. <IndexMethod
  100. chunkStructure={data.chunk_structure}
  101. indexMethod={data.indexing_technique}
  102. onIndexMethodChange={handleIndexMethodChange}
  103. keywordNumber={data.keyword_number}
  104. onKeywordNumberChange={handleKeywordNumberChange}
  105. readonly={nodesReadOnly}
  106. />
  107. {
  108. data.indexing_technique === IndexMethodEnum.QUALIFIED && (
  109. <EmbeddingModel
  110. embeddingModel={data.embedding_model}
  111. embeddingModelProvider={data.embedding_model_provider}
  112. onEmbeddingModelChange={handleEmbeddingModelChange}
  113. readonly={nodesReadOnly}
  114. />
  115. )
  116. }
  117. <div className='pt-1'>
  118. <Split className='h-[1px]' />
  119. </div>
  120. <RetrievalSetting
  121. indexMethod={data.indexing_technique}
  122. searchMethod={data.retrieval_model.search_method}
  123. onRetrievalSearchMethodChange={handleRetrievalSearchMethodChange}
  124. hybridSearchMode={data.retrieval_model.hybridSearchMode}
  125. onHybridSearchModeChange={handleHybridSearchModeChange}
  126. weightedScore={data.retrieval_model.weights}
  127. onWeightedScoreChange={handleWeighedScoreChange}
  128. rerankingModel={data.retrieval_model.reranking_model}
  129. onRerankingModelChange={handleRerankingModelChange}
  130. topK={data.retrieval_model.top_k}
  131. onTopKChange={handleTopKChange}
  132. scoreThreshold={data.retrieval_model.score_threshold}
  133. onScoreThresholdChange={handleScoreThresholdChange}
  134. isScoreThresholdEnabled={data.retrieval_model.score_threshold_enabled}
  135. onScoreThresholdEnabledChange={handleScoreThresholdEnabledChange}
  136. readonly={nodesReadOnly}
  137. />
  138. </div>
  139. </BoxGroup>
  140. </>
  141. )
  142. }
  143. </div>
  144. )
  145. }
  146. export default memo(Panel)