mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 19:27:23 +08:00
knowledge base node init
This commit is contained in:
parent
d6640f2adf
commit
4bc0a1bd37
@ -1,13 +1,12 @@
|
|||||||
import {
|
import {
|
||||||
memo,
|
memo,
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
|
||||||
useMemo,
|
useMemo,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { Field } from '@/app/components/workflow/nodes/_base/components/layout'
|
import { Field } from '@/app/components/workflow/nodes/_base/components/layout'
|
||||||
import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector'
|
import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector'
|
||||||
import { useModelListAndDefaultModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
import { useModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
import type { DefaultModel } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
import type { DefaultModel } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||||
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||||
|
|
||||||
@ -28,9 +27,8 @@ const EmbeddingModel = ({
|
|||||||
}: EmbeddingModelProps) => {
|
}: EmbeddingModelProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const {
|
const {
|
||||||
defaultModel,
|
data: embeddingModelList,
|
||||||
modelList: embeddingModelList,
|
} = useModelList(ModelTypeEnum.textEmbedding)
|
||||||
} = useModelListAndDefaultModel(ModelTypeEnum.textEmbedding)
|
|
||||||
const embeddingModelConfig = useMemo(() => {
|
const embeddingModelConfig = useMemo(() => {
|
||||||
if (!embeddingModel || !embeddingModelProvider)
|
if (!embeddingModel || !embeddingModelProvider)
|
||||||
return undefined
|
return undefined
|
||||||
@ -48,15 +46,6 @@ const EmbeddingModel = ({
|
|||||||
})
|
})
|
||||||
}, [onEmbeddingModelChange])
|
}, [onEmbeddingModelChange])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!embeddingModelConfig && defaultModel) {
|
|
||||||
handleEmbeddingModelChange({
|
|
||||||
provider: defaultModel.provider.provider,
|
|
||||||
model: defaultModel.model,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, [embeddingModelConfig, defaultModel, handleEmbeddingModelChange])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Field
|
<Field
|
||||||
fieldTitleProps={{
|
fieldTitleProps={{
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useEffect,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { produce } from 'immer'
|
import { produce } from 'immer'
|
||||||
import { useStoreApi } from 'reactflow'
|
import { useStoreApi } from 'reactflow'
|
||||||
import { useNodeDataUpdate } from '@/app/components/workflow/hooks'
|
import { useNodeDataUpdate } from '@/app/components/workflow/hooks'
|
||||||
import type { ValueSelector } from '@/app/components/workflow/types'
|
import type { ValueSelector } from '@/app/components/workflow/types'
|
||||||
|
import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
|
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||||
import {
|
import {
|
||||||
ChunkStructureEnum,
|
ChunkStructureEnum,
|
||||||
IndexMethodEnum,
|
IndexMethodEnum,
|
||||||
@ -171,6 +174,31 @@ export const useConfig = (id: string) => {
|
|||||||
})
|
})
|
||||||
}, [handleNodeDataUpdate])
|
}, [handleNodeDataUpdate])
|
||||||
|
|
||||||
|
const {
|
||||||
|
currentModel,
|
||||||
|
currentProvider,
|
||||||
|
} = useModelListAndDefaultModelAndCurrentProviderAndModel(ModelTypeEnum.textEmbedding)
|
||||||
|
|
||||||
|
const handleInitConfig = useCallback(() => {
|
||||||
|
const nodeData = getNodeData()
|
||||||
|
|
||||||
|
if (!nodeData?.data.embedding_model && !nodeData?.data.embedding_model_provider && currentModel && currentProvider) {
|
||||||
|
handleEmbeddingModelChange({
|
||||||
|
embeddingModel: currentModel.model,
|
||||||
|
embeddingModelProvider: currentProvider.provider,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
getNodeData,
|
||||||
|
handleEmbeddingModelChange,
|
||||||
|
currentModel,
|
||||||
|
currentProvider,
|
||||||
|
])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleInitConfig()
|
||||||
|
}, [handleInitConfig])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handleChunkStructureChange,
|
handleChunkStructureChange,
|
||||||
handleIndexMethodChange,
|
handleIndexMethodChange,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user