Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
cbb298cc
Commit
cbb298cc
authored
Feb 29, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: config conversation role name
parent
9e6940ed
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
9 deletions
+78
-9
memory-config.tsx
...ponents/workflow/nodes/_base/components/memory-config.tsx
+64
-5
mock.ts
...app/components/workflow/nodes/question-classifier/mock.ts
+2
-3
types.ts
web/app/components/workflow/types.ts
+6
-1
workflow.ts
web/i18n/en-US/workflow.ts
+3
-0
workflow.ts
web/i18n/zh-Hans/workflow.ts
+3
-0
No files found.
web/app/components/workflow/nodes/_base/components/memory-config.tsx
View file @
cbb298cc
...
...
@@ -5,11 +5,42 @@ import { useTranslation } from 'react-i18next'
import
produce
from
'immer'
import
cn
from
'classnames'
import
type
{
Memory
}
from
'../../../types'
import
{
MemoryRole
}
from
'../../../types'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
import
Switch
from
'@/app/components/base/switch'
import
Slider
from
'@/app/components/base/slider'
const
i18nPrefix
=
'workflow.nodes.common.memory'
const
WINDOW_SIZE_MIN
=
1
const
WINDOW_SIZE_MAX
=
100
const
WINDOW_SIZE_DEFAULT
=
50
type
RoleItemProps
=
{
readonly
:
boolean
title
:
string
value
:
string
onChange
:
(
value
:
string
)
=>
void
}
const
RoleItem
:
FC
<
RoleItemProps
>
=
({
readonly
,
title
,
value
,
onChange
,
})
=>
{
const
handleChange
=
useCallback
((
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
onChange
(
e
.
target
.
value
)
},
[
onChange
])
return
(
<
div
className=
'flex items-center justify-between'
>
<
div
className=
'text-[13px] font-normal text-gray-700'
>
{
title
}
</
div
>
<
input
readOnly=
{
readonly
}
value=
{
value
}
onChange=
{
handleChange
}
className=
'w-[200px] h-8 leading-8 px-2.5 rounded-lg border-0 bg-gray-100 text-gray-900 text-[13px] placeholder:text-gray-400 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200'
type=
'text'
/>
</
div
>
)
}
type
Props
=
{
className
?:
string
...
...
@@ -19,10 +50,6 @@ type Props = {
canSetRoleName
?:
boolean
}
const
WINDOW_SIZE_MIN
=
1
const
WINDOW_SIZE_MAX
=
100
const
WINDOW_SIZE_DEFAULT
=
50
const
MemoryConfig
:
FC
<
Props
>
=
({
className
,
readonly
,
...
...
@@ -70,6 +97,21 @@ const MemoryConfig: FC<Props> = ({
if
(
payload
.
window
.
size
===
''
||
payload
.
window
.
size
===
null
)
handleWindowSizeChange
(
WINDOW_SIZE_DEFAULT
)
},
[
handleWindowSizeChange
,
payload
.
window
?.
size
])
const
handleRolePrefixChange
=
useCallback
((
role
:
MemoryRole
)
=>
{
return
(
value
:
string
)
=>
{
const
newPayload
=
produce
(
payload
,
(
draft
)
=>
{
if
(
!
draft
.
role_prefix
)
{
draft
.
role_prefix
=
{
user
:
''
,
assistant
:
''
,
}
}
draft
.
role_prefix
[
role
]
=
value
})
onChange
(
newPayload
)
}
},
[
payload
,
onChange
])
return
(
<
div
className=
{
cn
(
className
)
}
>
<
Field
...
...
@@ -112,7 +154,24 @@ const MemoryConfig: FC<Props> = ({
</
div
>
</
div
>
{
canSetRoleName
&&
(
<
div
>
Role name
</
div
>
<
div
className=
'mt-4'
>
<
div
className=
'leading-6 text-xs font-medium text-gray-500 uppercase'
>
{
t
(
`${i18nPrefix}.conversationRoleName`
)
}
</
div
>
<
div
className=
'mt-1 space-y-2'
>
<
RoleItem
readonly=
{
readonly
}
title=
{
t
(
`${i18nPrefix}.user`
)
}
value=
{
payload
.
role_prefix
?.
user
||
''
}
onChange=
{
handleRolePrefixChange
(
MemoryRole
.
user
)
}
/>
<
RoleItem
readonly=
{
readonly
}
title=
{
t
(
`${i18nPrefix}.assistant`
)
}
value=
{
payload
.
role_prefix
?.
assistant
||
''
}
onChange=
{
handleRolePrefixChange
(
MemoryRole
.
assistant
)
}
/>
</
div
>
</
div
>
)
}
</>
</
Field
>
...
...
web/app/components/workflow/nodes/question-classifier/mock.ts
View file @
cbb298cc
import
{
MemoryRole
}
from
'../../types'
import
{
BlockEnum
}
from
'../../types'
import
type
{
QuestionClassifierNodeType
}
from
'./types'
export
const
mockData
:
QuestionClassifierNodeType
=
{
title
:
'Test'
,
desc
:
'Test'
,
type
:
'Test'
,
type
:
BlockEnum
.
QuestionClassifier
,
query_variable_selector
:
[
'aaa'
,
'name'
],
model
:
{
provider
:
'openai'
,
...
...
@@ -28,7 +28,6 @@ export const mockData: QuestionClassifierNodeType = {
],
instruction
:
'You are an entity extraction model that accepts an input'
,
memory
:
{
role_prefix
:
MemoryRole
.
assistant
,
window
:
{
enabled
:
false
,
size
:
0
,
...
...
web/app/components/workflow/types.ts
View file @
cbb298cc
...
...
@@ -90,8 +90,13 @@ export enum MemoryRole {
assistant
=
'assistant'
,
}
export
type
RolePrefix
=
{
user
:
string
assistant
:
string
}
export
type
Memory
=
{
role_prefix
?:
MemoryRole
role_prefix
?:
RolePrefix
window
:
{
enabled
:
boolean
size
:
number
|
string
|
null
...
...
web/i18n/en-US/workflow.ts
View file @
cbb298cc
...
...
@@ -7,6 +7,9 @@ const translation = {
memory
:
'Memory'
,
memoryTip
:
'Chat memory settings'
,
windowSize
:
'Window Size'
,
conversationRoleName
:
'Conversation Role Name'
,
user
:
'User prefix'
,
assistant
:
'Assistant prefix'
,
},
},
start
:
{
...
...
web/i18n/zh-Hans/workflow.ts
View file @
cbb298cc
...
...
@@ -7,6 +7,9 @@ const translation = {
memory
:
'记忆'
,
memoryTip
:
'聊天记忆设置'
,
windowSize
:
'记忆窗口'
,
conversationRoleName
:
'对话角色名'
,
user
:
'用户前缀'
,
assistant
:
'助手前缀'
,
},
},
start
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment