Spaces:
Build error
Build error
File size: 5,881 Bytes
a8b3f00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
import type { FC } from 'react'
import {
memo,
useCallback,
} from 'react'
import { useTranslation } from 'react-i18next'
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
import useConfig from './use-config'
import RetrievalConfig from './components/retrieval-config'
import AddKnowledge from './components/add-dataset'
import DatasetList from './components/dataset-list'
import type { KnowledgeRetrievalNodeType } from './types'
import Field from '@/app/components/workflow/nodes/_base/components/field'
import Split from '@/app/components/workflow/nodes/_base/components/split'
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
import { InputVarType, type NodePanelProps } from '@/app/components/workflow/types'
import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
import ResultPanel from '@/app/components/workflow/run/result-panel'
const i18nPrefix = 'workflow.nodes.knowledgeRetrieval'
const Panel: FC<NodePanelProps<KnowledgeRetrievalNodeType>> = ({
id,
data,
}) => {
const { t } = useTranslation()
const {
readOnly,
inputs,
handleQueryVarChange,
filterVar,
handleModelChanged,
handleCompletionParamsChange,
handleRetrievalModeChange,
handleMultipleRetrievalConfigChange,
selectedDatasets,
handleOnDatasetsChange,
isShowSingleRun,
hideSingleRun,
runningStatus,
handleRun,
handleStop,
query,
setQuery,
runResult,
rerankModelOpen,
setRerankModelOpen,
} = useConfig(id, data)
const handleOpenFromPropsChange = useCallback((openFromProps: boolean) => {
setRerankModelOpen(openFromProps)
}, [setRerankModelOpen])
return (
<div className='mt-2'>
<div className='px-4 pb-4 space-y-4'>
{/* {JSON.stringify(inputs, null, 2)} */}
<Field
title={t(`${i18nPrefix}.queryVariable`)}
>
<VarReferencePicker
nodeId={id}
readonly={readOnly}
isShowNodeName
value={inputs.query_variable_selector}
onChange={handleQueryVarChange}
filterVar={filterVar}
/>
</Field>
<Field
title={t(`${i18nPrefix}.knowledge`)}
operations={
<div className='flex items-center space-x-1'>
<RetrievalConfig
payload={{
retrieval_mode: inputs.retrieval_mode,
multiple_retrieval_config: inputs.multiple_retrieval_config,
single_retrieval_config: inputs.single_retrieval_config,
}}
onRetrievalModeChange={handleRetrievalModeChange}
onMultipleRetrievalConfigChange={handleMultipleRetrievalConfigChange}
singleRetrievalModelConfig={inputs.single_retrieval_config?.model}
onSingleRetrievalModelChange={handleModelChanged as any}
onSingleRetrievalModelParamsChange={handleCompletionParamsChange}
readonly={readOnly || !selectedDatasets.length}
openFromProps={rerankModelOpen}
onOpenFromPropsChange={handleOpenFromPropsChange}
selectedDatasets={selectedDatasets}
/>
{!readOnly && (<div className='w-px h-3 bg-gray-200'></div>)}
{!readOnly && (
<AddKnowledge
selectedIds={inputs.dataset_ids}
onChange={handleOnDatasetsChange}
/>
)}
</div>
}
>
<DatasetList
list={selectedDatasets}
onChange={handleOnDatasetsChange}
readonly={readOnly}
/>
</Field>
</div>
<Split />
<div className='px-4 pt-4 pb-2'>
<OutputVars>
<>
<VarItem
name='result'
type='Array[Object]'
description={t(`${i18nPrefix}.outputVars.output`)}
subItems={[
{
name: 'content',
type: 'string',
description: t(`${i18nPrefix}.outputVars.content`),
},
// url, title, link like bing search reference result: link, link page title, link page icon
{
name: 'title',
type: 'string',
description: t(`${i18nPrefix}.outputVars.title`),
},
{
name: 'url',
type: 'string',
description: t(`${i18nPrefix}.outputVars.url`),
},
{
name: 'icon',
type: 'string',
description: t(`${i18nPrefix}.outputVars.icon`),
},
{
name: 'metadata',
type: 'object',
description: t(`${i18nPrefix}.outputVars.metadata`),
},
]}
/>
</>
</OutputVars>
{isShowSingleRun && (
<BeforeRunForm
nodeName={inputs.title}
onHide={hideSingleRun}
forms={[
{
inputs: [{
label: t(`${i18nPrefix}.queryVariable`)!,
variable: 'query',
type: InputVarType.paragraph,
required: true,
}],
values: { query },
onChange: keyValue => setQuery((keyValue as any).query),
},
]}
runningStatus={runningStatus}
onRun={handleRun}
onStop={handleStop}
result={<ResultPanel {...runResult} showSteps={false} />}
/>
)}
</div>
</div>
)
}
export default memo(Panel)
|