mirror of https://github.com/langgenius/dify.git
fix
This commit is contained in:
parent
0b1445aed5
commit
7e9375ce7e
|
|
@ -9,6 +9,7 @@ import {
|
|||
MEMORY_DEFAULT,
|
||||
} from './linear-memory'
|
||||
import type { Memory } from '@/app/components/workflow/types'
|
||||
import { MemoryMode } from '@/app/components/workflow/types'
|
||||
|
||||
export const useMemory = (
|
||||
id: string,
|
||||
|
|
@ -31,7 +32,7 @@ export const useMemory = (
|
|||
const nodeData = getNodeData()
|
||||
const { memory: memoryData = {} } = nodeData as any
|
||||
|
||||
if (value === 'disabled') {
|
||||
if (value === MemoryMode.disabled) {
|
||||
setCollapsed(true)
|
||||
handleNodeDataUpdate({
|
||||
memory: {
|
||||
|
|
@ -41,25 +42,25 @@ export const useMemory = (
|
|||
},
|
||||
})
|
||||
}
|
||||
if (value === 'linear') {
|
||||
if (value === MemoryMode.linear) {
|
||||
setCollapsed(false)
|
||||
handleNodeDataUpdate({
|
||||
memory: {
|
||||
...memoryData,
|
||||
enabled: true,
|
||||
mode: 'linear',
|
||||
mode: MemoryMode.linear,
|
||||
window: memoryData?.window || MEMORY_DEFAULT.window,
|
||||
query_prompt_template: memoryData?.query_prompt_template || MEMORY_DEFAULT.query_prompt_template,
|
||||
},
|
||||
})
|
||||
}
|
||||
if (value === 'block') {
|
||||
if (value === MemoryMode.block) {
|
||||
setCollapsed(false)
|
||||
handleNodeDataUpdate({
|
||||
memory: {
|
||||
...memoryData,
|
||||
enabled: true,
|
||||
mode: 'block',
|
||||
mode: MemoryMode.block,
|
||||
block_id: memoryData?.block_id || [],
|
||||
query_prompt_template: memoryData?.query_prompt_template || MEMORY_DEFAULT.query_prompt_template,
|
||||
},
|
||||
|
|
@ -75,19 +76,19 @@ export const useMemory = (
|
|||
|
||||
const memoryType = useMemo(() => {
|
||||
if (!memory)
|
||||
return 'disabled'
|
||||
return MemoryMode.disabled
|
||||
|
||||
if (!('enabled' in memory))
|
||||
return 'linear'
|
||||
return MemoryMode.linear
|
||||
|
||||
if (memory.enabled) {
|
||||
if (memory.mode === 'linear')
|
||||
return 'linear'
|
||||
if (memory.mode === 'block')
|
||||
return 'block'
|
||||
if (memory.mode === MemoryMode.linear)
|
||||
return MemoryMode.linear
|
||||
if (memory.mode === MemoryMode.block)
|
||||
return MemoryMode.block
|
||||
}
|
||||
else {
|
||||
return 'disabled'
|
||||
return MemoryMode.disabled
|
||||
}
|
||||
}, [memory])
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import type { Memory } from '@/app/components/workflow/types'
|
|||
import type { LLMNodeType } from '../../types'
|
||||
import { useMemory } from './hooks'
|
||||
import Split from '@/app/components/workflow/nodes/_base/components/split'
|
||||
import { MemoryMode } from '@/app/components/workflow/types'
|
||||
|
||||
type MemoryProps = Pick<Node, 'id' | 'data'> & {
|
||||
readonly?: boolean
|
||||
|
|
@ -58,7 +59,7 @@ const MemorySystem = ({
|
|||
/>
|
||||
{collapseIcon}
|
||||
{
|
||||
memoryType === 'block' && (
|
||||
memoryType === MemoryMode.block && (
|
||||
<>
|
||||
<Divider type='vertical' className='!ml-1.5 !mr-1 h-3 !w-px bg-divider-regular' />
|
||||
<div onClick={e => e.stopPropagation()}>
|
||||
|
|
@ -78,7 +79,7 @@ const MemorySystem = ({
|
|||
>
|
||||
<>
|
||||
{
|
||||
memoryType === 'linear' && !collapsed && (
|
||||
memoryType === MemoryMode.linear && !collapsed && (
|
||||
<LinearMemory
|
||||
className='mt-2'
|
||||
payload={memory as Memory}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import {
|
|||
PortalToFollowElemTrigger,
|
||||
} from '@/app/components/base/portal-to-follow-elem'
|
||||
import Button from '@/app/components/base/button'
|
||||
import { MemoryMode } from '@/app/components/workflow/types'
|
||||
|
||||
type MemorySelectorProps = {
|
||||
value?: string
|
||||
|
|
@ -28,17 +29,17 @@ const MemorySelector = ({
|
|||
const [open, setOpen] = useState(false)
|
||||
const options = [
|
||||
{
|
||||
value: 'disabled',
|
||||
value: MemoryMode.disabled,
|
||||
label: t('workflow.nodes.common.memory.disabled.title'),
|
||||
description: t('workflow.nodes.common.memory.disabled.desc'),
|
||||
},
|
||||
{
|
||||
value: 'linear',
|
||||
value: MemoryMode.linear,
|
||||
label: t('workflow.nodes.common.memory.linear.title'),
|
||||
description: t('workflow.nodes.common.memory.linear.desc'),
|
||||
},
|
||||
{
|
||||
value: 'block',
|
||||
value: MemoryMode.block,
|
||||
label: t('workflow.nodes.common.memory.block.title'),
|
||||
description: t('workflow.nodes.common.memory.block.desc'),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import { RiAlertFill, RiQuestionLine } from '@remixicon/react'
|
|||
import { fetchAndMergeValidCompletionParams } from '@/utils/completion-params'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import MemorySystem from './components/memory-system'
|
||||
import { useMemory } from './components/memory-system/hooks'
|
||||
import { MemoryMode } from '@/app/components/workflow/types'
|
||||
|
||||
const i18nPrefix = 'workflow.nodes.llm'
|
||||
|
||||
|
|
@ -64,6 +66,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||
handleReasoningFormatChange,
|
||||
memoryVarSortFn,
|
||||
} = useConfig(id, data)
|
||||
const { memoryType } = useMemory(id, data)
|
||||
|
||||
const model = inputs.model
|
||||
|
||||
|
|
@ -177,7 +180,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||
)}
|
||||
|
||||
{/* Memory put place examples. */}
|
||||
{isChatMode && isChatModel && !!inputs.memory?.enabled && (
|
||||
{isChatMode && isChatModel && (memoryType === MemoryMode.linear || memoryType === MemoryMode.block) && (
|
||||
<div className='mt-4'>
|
||||
<div className='flex h-8 items-center justify-between rounded-lg bg-components-input-bg-normal pl-3 pr-2'>
|
||||
<div className='flex items-center space-x-1'>
|
||||
|
|
@ -201,7 +204,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||
triggerClassName='w-4 h-4'
|
||||
/>
|
||||
</div>}
|
||||
value={inputs.memory.query_prompt_template || '{{#sys.query#}}'}
|
||||
value={inputs.memory?.query_prompt_template || '{{#sys.query#}}'}
|
||||
onChange={handleSyeQueryChange}
|
||||
readOnly={readOnly}
|
||||
isShowContext={false}
|
||||
|
|
@ -214,7 +217,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||
instanceId={`${id}-chat-workflow-llm-prompt-editor-user`}
|
||||
/>
|
||||
|
||||
{inputs.memory.query_prompt_template && !inputs.memory.query_prompt_template.includes('{{#sys.query#}}') && (
|
||||
{inputs.memory?.query_prompt_template && !inputs.memory.query_prompt_template.includes('{{#sys.query#}}') && (
|
||||
<div className='text-xs font-normal leading-[18px] text-[#DC6803]'>{t(`${i18nPrefix}.sysQueryInUser`)}</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -273,6 +273,12 @@ export type RolePrefix = {
|
|||
assistant: string
|
||||
}
|
||||
|
||||
export enum MemoryMode {
|
||||
linear = 'linear',
|
||||
block = 'block',
|
||||
disabled = 'disabled',
|
||||
}
|
||||
|
||||
export type Memory = {
|
||||
enabled?: boolean
|
||||
role_prefix?: RolePrefix
|
||||
|
|
@ -282,7 +288,7 @@ export type Memory = {
|
|||
}
|
||||
query_prompt_template: string
|
||||
block_id?: string[]
|
||||
mode?: 'linear' | 'block'
|
||||
mode?: MemoryMode
|
||||
}
|
||||
|
||||
export enum VarType {
|
||||
|
|
|
|||
Loading…
Reference in New Issue