Bladeren bron

Merge remote-tracking branch 'origin/feat/rag-2' into feat/rag-2

tags/2.0.0-beta.1
jyong 3 maanden geleden
bovenliggende
commit
ed77877db1

+ 5
- 3
web/app/components/app-sidebar/navLink.tsx Bestand weergeven

'use client' 'use client'
import React from 'react'
import { useSelectedLayoutSegment } from 'next/navigation' import { useSelectedLayoutSegment } from 'next/navigation'
import Link from 'next/link' import Link from 'next/link'
import classNames from '@/utils/classnames' import classNames from '@/utils/classnames'
disabled?: boolean disabled?: boolean
} }


export default function NavLink({
const NavLink = ({
name, name,
href, href,
iconMap, iconMap,
mode = 'expand', mode = 'expand',
disabled = false, disabled = false,
}: NavLinkProps) {
}: NavLinkProps) => {
const segment = useSelectedLayoutSegment() const segment = useSelectedLayoutSegment()
const formattedSegment = (() => { const formattedSegment = (() => {
let res = segment?.toLowerCase() let res = segment?.toLowerCase()
</Link> </Link>
) )
} }

export default React.memo(NavLink)

+ 21
- 13
web/app/components/datasets/documents/create-from-pipeline/data-source/online-documents/index.tsx Bestand weergeven

import type { DataSourceNodeCompletedResponse, DataSourceNodeErrorResponse } from '@/types/pipeline' import type { DataSourceNodeCompletedResponse, DataSourceNodeErrorResponse } from '@/types/pipeline'
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types' import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
import { useDataSourceStore, useDataSourceStoreWithSelector } from '../store' import { useDataSourceStore, useDataSourceStoreWithSelector } from '../store'
import { useShallow } from 'zustand/react/shallow'


type OnlineDocumentsProps = { type OnlineDocumentsProps = {
isInPipeline?: boolean isInPipeline?: boolean
nodeData, nodeData,
}: OnlineDocumentsProps) => { }: OnlineDocumentsProps) => {
const pipelineId = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id) const pipelineId = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id)
const documentsData = useDataSourceStoreWithSelector(state => state.documentsData)
const searchValue = useDataSourceStoreWithSelector(state => state.searchValue)
const selectedPagesId = useDataSourceStoreWithSelector(state => state.selectedPagesId)
const currentWorkspaceId = useDataSourceStoreWithSelector(state => state.currentWorkspaceId)
const currentNodeIdRef = useDataSourceStoreWithSelector(state => state.currentNodeIdRef)
const {
documentsData,
searchValue,
selectedPagesId,
currentWorkspaceId,
} = useDataSourceStoreWithSelector(useShallow(state => ({
documentsData: state.documentsData,
searchValue: state.searchValue,
selectedPagesId: state.selectedPagesId,
currentWorkspaceId: state.currentWorkspaceId,
})))
const dataSourceStore = useDataSourceStore() const dataSourceStore = useDataSourceStore()


const PagesMapAndSelectedPagesId: DataSourceNotionPageMap = useMemo(() => { const PagesMapAndSelectedPagesId: DataSourceNotionPageMap = useMemo(() => {
}, [dataSourceStore, datasourceNodeRunURL]) }, [dataSourceStore, datasourceNodeRunURL])


useEffect(() => { useEffect(() => {
const {
setDocumentsData,
setCurrentWorkspaceId,
setSearchValue,
setSelectedPagesId,
setOnlineDocuments,
setCurrentDocument,
currentNodeIdRef,
} = dataSourceStore.getState()
if (nodeId !== currentNodeIdRef.current) { if (nodeId !== currentNodeIdRef.current) {
const {
setDocumentsData,
setCurrentWorkspaceId,
setSearchValue,
setSelectedPagesId,
setOnlineDocuments,
setCurrentDocument,
} = dataSourceStore.getState()
setDocumentsData([]) setDocumentsData([])
setCurrentWorkspaceId('') setCurrentWorkspaceId('')
setSearchValue('') setSearchValue('')

+ 22
- 13
web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/index.tsx Bestand weergeven

import { useDataSourceStore, useDataSourceStoreWithSelector } from '../store' import { useDataSourceStore, useDataSourceStoreWithSelector } from '../store'
import { convertOnlineDriveData } from './utils' import { convertOnlineDriveData } from './utils'
import produce from 'immer' import produce from 'immer'
import { useShallow } from 'zustand/react/shallow'


type OnlineDriveProps = { type OnlineDriveProps = {
nodeId: string nodeId: string
isInPipeline = false, isInPipeline = false,
}: OnlineDriveProps) => { }: OnlineDriveProps) => {
const pipelineId = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id) const pipelineId = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id)
const prefix = useDataSourceStoreWithSelector(state => state.prefix)
const keywords = useDataSourceStoreWithSelector(state => state.keywords)
const bucket = useDataSourceStoreWithSelector(state => state.bucket)
const selectedFileKeys = useDataSourceStoreWithSelector(state => state.selectedFileKeys)
const fileList = useDataSourceStoreWithSelector(state => state.fileList)
const currentNodeIdRef = useDataSourceStoreWithSelector(state => state.currentNodeIdRef)
const {
prefix,
keywords,
bucket,
selectedFileKeys,
fileList,
} = useDataSourceStoreWithSelector(useShallow(state => ({
prefix: state.prefix,
keywords: state.keywords,
bucket: state.bucket,
selectedFileKeys: state.selectedFileKeys,
fileList: state.fileList,
})))
const dataSourceStore = useDataSourceStore() const dataSourceStore = useDataSourceStore()
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)


}, [datasourceNodeRunURL, dataSourceStore]) }, [datasourceNodeRunURL, dataSourceStore])


useEffect(() => { useEffect(() => {
const {
setFileList,
setBucket,
setPrefix,
setKeywords,
setSelectedFileKeys,
currentNodeIdRef,
} = dataSourceStore.getState()
if (nodeId !== currentNodeIdRef.current) { if (nodeId !== currentNodeIdRef.current) {
const {
setFileList,
setBucket,
setPrefix,
setKeywords,
setSelectedFileKeys,
} = dataSourceStore.getState()
setFileList([]) setFileList([])
setBucket('') setBucket('')
setPrefix([]) setPrefix([])

+ 14
- 6
web/app/components/datasets/documents/create-from-pipeline/data-source/website-crawl/index.tsx Bestand weergeven

} from '@/types/pipeline' } from '@/types/pipeline'
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types' import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
import { useDataSourceStore, useDataSourceStoreWithSelector } from '../store' import { useDataSourceStore, useDataSourceStoreWithSelector } from '../store'
import { useShallow } from 'zustand/react/shallow'


const I18N_PREFIX = 'datasetCreation.stepOne.website' const I18N_PREFIX = 'datasetCreation.stepOne.website'


const [crawledNum, setCrawledNum] = useState(0) const [crawledNum, setCrawledNum] = useState(0)
const [crawlErrorMessage, setCrawlErrorMessage] = useState('') const [crawlErrorMessage, setCrawlErrorMessage] = useState('')
const pipelineId = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id) const pipelineId = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id)
const crawlResult = useDataSourceStoreWithSelector(state => state.crawlResult)
const step = useDataSourceStoreWithSelector(state => state.step)
const checkedCrawlResult = useDataSourceStoreWithSelector(state => state.websitePages)
const previewIndex = useDataSourceStoreWithSelector(state => state.previewIndex)
const {
crawlResult,
step,
checkedCrawlResult,
previewIndex,
} = useDataSourceStoreWithSelector(useShallow(state => ({
crawlResult: state.crawlResult,
step: state.step,
checkedCrawlResult: state.websitePages,
previewIndex: state.previewIndex,
})))
const dataSourceStore = useDataSourceStore() const dataSourceStore = useDataSourceStore()


const usePreProcessingParams = useRef(!isInPipeline ? usePublishedPipelinePreProcessingParams : useDraftPipelinePreProcessingParams) const usePreProcessingParams = useRef(!isInPipeline ? usePublishedPipelinePreProcessingParams : useDraftPipelinePreProcessingParams)
time_consuming: time_consuming ?? 0, time_consuming: time_consuming ?? 0,
} }
setCrawlResult(crawlResultData) setCrawlResult(crawlResultData)
handleCheckedCrawlResultChange(crawlData || []) // default select the crawl result
handleCheckedCrawlResultChange(isInPipeline ? [crawlData[0]] : crawlData) // default select the crawl result
setCrawlErrorMessage('') setCrawlErrorMessage('')
setStep(CrawlStep.finished) setStep(CrawlStep.finished)
}, },
}, },
}, },
) )
}, [dataSourceStore, datasourceNodeRunURL, handleCheckedCrawlResultChange, t])
}, [dataSourceStore, datasourceNodeRunURL, handleCheckedCrawlResultChange, isInPipeline, t])


const handleSubmit = useCallback((value: Record<string, any>) => { const handleSubmit = useCallback((value: Record<string, any>) => {
handleRun(value) handleRun(value)

+ 33
- 10
web/app/components/datasets/documents/create-from-pipeline/hooks.ts Bestand weergeven

import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types' import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
import { useDataSourceStore, useDataSourceStoreWithSelector } from './data-source/store' import { useDataSourceStore, useDataSourceStoreWithSelector } from './data-source/store'
import type { DataSourceNotionPageMap, DataSourceNotionWorkspace } from '@/models/common' import type { DataSourceNotionPageMap, DataSourceNotionWorkspace } from '@/models/common'
import { useShallow } from 'zustand/react/shallow'


export const useAddDocumentsSteps = () => { export const useAddDocumentsSteps = () => {
const { t } = useTranslation() const { t } = useTranslation()
} }


export const useLocalFile = () => { export const useLocalFile = () => {
const fileList = useDataSourceStoreWithSelector(state => state.localFileList)
const currentLocalFile = useDataSourceStoreWithSelector(state => state.currentLocalFile)
const {
localFileList: fileList,
currentLocalFile,
} = useDataSourceStoreWithSelector(useShallow(state => ({
localFileList: state.localFileList,
currentLocalFile: state.currentLocalFile,
})))
const dataSourceStore = useDataSourceStore() const dataSourceStore = useDataSourceStore()


const allFileLoaded = useMemo(() => (fileList.length > 0 && fileList.every(file => file.file.id)), [fileList]) const allFileLoaded = useMemo(() => (fileList.length > 0 && fileList.every(file => file.file.id)), [fileList])
} }


export const useOnlineDocuments = () => { export const useOnlineDocuments = () => {
const documentsData = useDataSourceStoreWithSelector(state => state.documentsData)
const currentWorkspaceId = useDataSourceStoreWithSelector(state => state.currentWorkspaceId)
const onlineDocuments = useDataSourceStoreWithSelector(state => state.onlineDocuments)
const currentDocument = useDataSourceStoreWithSelector(state => state.currentDocument)
const {
documentsData,
currentWorkspaceId,
onlineDocuments,
currentDocument,
} = useDataSourceStoreWithSelector(useShallow(state => ({
documentsData: state.documentsData,
currentWorkspaceId: state.currentWorkspaceId,
onlineDocuments: state.onlineDocuments,
currentDocument: state.currentDocument,
})))
const dataSourceStore = useDataSourceStore() const dataSourceStore = useDataSourceStore()


const currentWorkspace = documentsData.find(workspace => workspace.workspace_id === currentWorkspaceId) const currentWorkspace = documentsData.find(workspace => workspace.workspace_id === currentWorkspaceId)
} }


export const useWebsiteCrawl = () => { export const useWebsiteCrawl = () => {
const websitePages = useDataSourceStoreWithSelector(state => state.websitePages)
const currentWebsite = useDataSourceStoreWithSelector(state => state.currentWebsite)
const {
websitePages,
currentWebsite,
} = useDataSourceStoreWithSelector(useShallow(state => ({
websitePages: state.websitePages,
currentWebsite: state.currentWebsite,
})))
const dataSourceStore = useDataSourceStore() const dataSourceStore = useDataSourceStore()


const hideWebsitePreview = useCallback(() => { const hideWebsitePreview = useCallback(() => {
} }


export const useOnlineDrive = () => { export const useOnlineDrive = () => {
const fileList = useDataSourceStoreWithSelector(state => state.fileList)
const selectedFileKeys = useDataSourceStoreWithSelector(state => state.selectedFileKeys)
const {
fileList,
selectedFileKeys,
} = useDataSourceStoreWithSelector(useShallow(state => ({
fileList: state.fileList,
selectedFileKeys: state.selectedFileKeys,
})))


const selectedOnlineDriveFileList = useMemo(() => { const selectedOnlineDriveFileList = useMemo(() => {
return selectedFileKeys.map(key => fileList.find(item => item.key === key)!) return selectedFileKeys.map(key => fileList.find(item => item.key === key)!)

+ 3
- 2
web/app/components/datasets/documents/create-from-pipeline/preview/chunk-preview.tsx Bestand weergeven

import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import type { OnlineDriveFile } from '@/models/pipeline' import type { OnlineDriveFile } from '@/models/pipeline'
import { DatasourceType } from '@/models/pipeline' import { DatasourceType } from '@/models/pipeline'
import { getFileExtension } from '../data-source/online-drive/file-list/list/utils'


type ChunkPreviewProps = { type ChunkPreviewProps = {
dataSourceType: DatasourceType dataSourceType: DatasourceType
onlineDriveFiles.map(file => ({ onlineDriveFiles.map(file => ({
id: file.key, id: file.key,
name: file.displayName, name: file.displayName,
extension: 'md',
extension: getFileExtension(previewOnlineDriveFile?.displayName),
})) }))
} }
onChange={(selected) => { onChange={(selected) => {
{ {
id: previewOnlineDriveFile?.key || '', id: previewOnlineDriveFile?.key || '',
name: previewOnlineDriveFile?.displayName || '', name: previewOnlineDriveFile?.displayName || '',
extension: 'md',
extension: getFileExtension(previewOnlineDriveFile?.displayName),
} }
} }
/> />

+ 12
- 4
web/app/components/rag-pipeline/components/panel/test-run/index.tsx Bestand weergeven

import FooterTips from './footer-tips' import FooterTips from './footer-tips'
import DataSourceProvider from '@/app/components/datasets/documents/create-from-pipeline/data-source/store/provider' import DataSourceProvider from '@/app/components/datasets/documents/create-from-pipeline/data-source/store/provider'
import { useDataSourceStore, useDataSourceStoreWithSelector } from '@/app/components/datasets/documents/create-from-pipeline/data-source/store' import { useDataSourceStore, useDataSourceStoreWithSelector } from '@/app/components/datasets/documents/create-from-pipeline/data-source/store'
import { useShallow } from 'zustand/react/shallow'


const TestRunPanel = () => { const TestRunPanel = () => {
const setShowDebugAndPreviewPanel = useWorkflowStoreWithSelector(state => state.setShowDebugAndPreviewPanel) const setShowDebugAndPreviewPanel = useWorkflowStoreWithSelector(state => state.setShowDebugAndPreviewPanel)
const fileList = useDataSourceStoreWithSelector(state => state.localFileList)
const onlineDocuments = useDataSourceStoreWithSelector(state => state.onlineDocuments)
const websitePages = useDataSourceStoreWithSelector(state => state.websitePages)
const selectedFileKeys = useDataSourceStoreWithSelector(state => state.selectedFileKeys)
const {
localFileList: fileList,
onlineDocuments,
websitePages,
selectedFileKeys,
} = useDataSourceStoreWithSelector(useShallow(state => ({
localFileList: state.localFileList,
onlineDocuments: state.onlineDocuments,
websitePages: state.websitePages,
selectedFileKeys: state.selectedFileKeys,
})))
const dataSourceStore = useDataSourceStore() const dataSourceStore = useDataSourceStore()
const [datasource, setDatasource] = useState<Datasource>() const [datasource, setDatasource] = useState<Datasource>()



+ 4
- 2
web/app/components/rag-pipeline/components/rag-pipeline-children.tsx Bestand weergeven

} from 'react' } from 'react'
import { useStore } from '../../workflow/store' import { useStore } from '../../workflow/store'
import InputField from './input-field' import InputField from './input-field'
import PluginDependency from '../../workflow/plugin-dependency'
import RagPipelinePanel from './panel' import RagPipelinePanel from './panel'
import RagPipelineHeader from './rag-pipeline-header' import RagPipelineHeader from './rag-pipeline-header'
import type { EnvironmentVariable } from '@/app/components/workflow/types' import type { EnvironmentVariable } from '@/app/components/workflow/types'
handlePaneContextmenuCancel, handlePaneContextmenuCancel,
} = usePanelInteractions() } = usePanelInteractions()
const { const {
exportCheck,
handleExportDSL,
exportCheck,
handleExportDSL,
} = useDSL() } = useDSL()


eventEmitter?.useSubscription((v: any) => { eventEmitter?.useSubscription((v: any) => {


return ( return (
<> <>
<PluginDependency />
{ {
showImportDSLModal && ( showImportDSLModal && (
<UpdateDSLModal <UpdateDSLModal

+ 2
- 0
web/app/components/workflow-app/components/workflow-children.tsx Bestand weergeven

import { DSL_EXPORT_CHECK } from '@/app/components/workflow/constants' import { DSL_EXPORT_CHECK } from '@/app/components/workflow/constants'
import { useStore } from '@/app/components/workflow/store' import { useStore } from '@/app/components/workflow/store'
import Features from '@/app/components/workflow/features' import Features from '@/app/components/workflow/features'
import PluginDependency from '../../workflow/plugin-dependency'
import UpdateDSLModal from '@/app/components/workflow/update-dsl-modal' import UpdateDSLModal from '@/app/components/workflow/update-dsl-modal'
import DSLExportConfirmModal from '@/app/components/workflow/dsl-export-confirm-modal' import DSLExportConfirmModal from '@/app/components/workflow/dsl-export-confirm-modal'
import { import {


return ( return (
<> <>
<PluginDependency />
{ {
showFeaturesPanel && <Features /> showFeaturesPanel && <Features />
} }

+ 17
- 11
web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx Bestand weergeven

return return
if (workflowCanvasWidth - 400 <= nodePanelWidth + otherPanelWidth) if (workflowCanvasWidth - 400 <= nodePanelWidth + otherPanelWidth)
debounceUpdate(workflowCanvasWidth - 400 - otherPanelWidth) debounceUpdate(workflowCanvasWidth - 400 - otherPanelWidth)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [nodePanelWidth, otherPanelWidth, workflowCanvasWidth, updateNodePanelWidth]) }, [nodePanelWidth, otherPanelWidth, workflowCanvasWidth, updateNodePanelWidth])


const { handleNodeSelect } = useNodesInteractions() const { handleNodeSelect } = useNodesInteractions()
const [isPaused, setIsPaused] = useState(false) const [isPaused, setIsPaused] = useState(false)


useEffect(() => { useEffect(() => {
if(data._singleRunningStatus === NodeRunningStatus.Running) {
if (data._singleRunningStatus === NodeRunningStatus.Running) {
hasClickRunning.current = true hasClickRunning.current = true
setIsPaused(false) setIsPaused(false)
} }
else if(data._isSingleRun && data._singleRunningStatus === undefined && hasClickRunning) {
else if (data._isSingleRun && data._singleRunningStatus === undefined && hasClickRunning) {
setIsPaused(true) setIsPaused(true)
hasClickRunning.current = false hasClickRunning.current = false
} }
return {} return {}
})() })()


if(logParams.showSpecialResultPanel) {
if (logParams.showSpecialResultPanel) {
return ( return (
<div className={cn(
<div className={cn(
'relative mr-1 h-full', 'relative mr-1 h-full',
)}> )}>
<div <div
} }


return ( return (
<div className={cn(
'relative mr-1 h-full',
showMessageLogModal && '!absolute -top-[5px] right-[416px] z-0 !mr-0 w-[384px] overflow-hidden rounded-2xl border-[0.5px] border-components-panel-border shadow-lg transition-all',
)}>
<div
className={cn(
'relative mr-1 h-full',
showMessageLogModal && 'absolute z-0 mr-2 w-[400px] overflow-hidden rounded-2xl border-[0.5px] border-components-panel-border shadow-lg transition-all',
)}
style={{
right: !showMessageLogModal ? '0' : `${otherPanelWidth}px`,
}}
>
<div <div
ref={triggerRef} ref={triggerRef}
className='absolute -left-1 top-0 flex h-full w-1 cursor-col-resize resize-x items-center justify-center'> className='absolute -left-1 top-0 flex h-full w-1 cursor-col-resize resize-x items-center justify-center'>
</div> </div>
<div <div
ref={containerRef} ref={containerRef}
className={cn('flex h-full flex-col rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadow-lg', showSingleRunPanel ? 'overflow-hidden' : 'overflow-y-auto')}
className={cn('flex h-full flex-col rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadow-lg transition-[width] ease-linear', showSingleRunPanel ? 'overflow-hidden' : 'overflow-y-auto')}
style={{ style={{
width: `${nodePanelWidth}px`, width: `${nodePanelWidth}px`,
}} }}
<div <div
className='mr-1 flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-state-base-hover' className='mr-1 flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-state-base-hover'
onClick={() => { onClick={() => {
if(isSingleRunning) {
if (isSingleRunning) {
handleNodeDataUpdate({ handleNodeDataUpdate({
id, id,
data: { data: {
> >
{ {
isSingleRunning ? <Stop className='h-4 w-4 text-text-tertiary' /> isSingleRunning ? <Stop className='h-4 w-4 text-text-tertiary' />
: <RiPlayLargeLine className='h-4 w-4 text-text-tertiary' />
: <RiPlayLargeLine className='h-4 w-4 text-text-tertiary' />
} }
</div> </div>
</Tooltip> </Tooltip>

Laden…
Annuleren
Opslaan