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
4837ae49
Commit
4837ae49
authored
Feb 28, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: question add class
parent
6da9950b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
119 additions
and
5 deletions
+119
-5
page.tsx
web/app/(commonLayout)/workflow/nodes/page.tsx
+3
-1
class-list.tsx
...kflow/nodes/question-classifier/components/class-list.tsx
+58
-0
panel.tsx
...p/components/workflow/nodes/question-classifier/panel.tsx
+28
-3
types.ts
...pp/components/workflow/nodes/question-classifier/types.ts
+1
-1
use-config.ts
...mponents/workflow/nodes/question-classifier/use-config.ts
+17
-0
workflow.ts
web/i18n/en-US/workflow.ts
+6
-0
workflow.ts
web/i18n/zh-Hans/workflow.ts
+6
-0
No files found.
web/app/(commonLayout)/workflow/nodes/page.tsx
View file @
4837ae49
...
...
@@ -4,8 +4,9 @@ import type { FC } from 'react'
import
{
memo
}
from
'react'
import
Workflow
from
'@/app/components/workflow'
import
{
BlockEnum
}
from
'@/app/components/workflow/types'
const
nodes
=
[
BlockEnum
.
Tool
/* 10 */
,
BlockEnum
.
VariableAssigner
/* 11 */
,
BlockEnum
.
Start
/* 1 */
,
BlockEnum
.
DirectAnswer
/* 2 */
,
BlockEnum
.
LLM
/* 3 */
,
BlockEnum
.
KnowledgeRetrieval
/* 4 */
,
BlockEnum
.
QuestionClassifier
/* 5
*/
,
BlockEnum
.
QuestionClassifier
/* 5 */
,
BlockEnum
.
Tool
/* 10 */
,
BlockEnum
.
VariableAssigner
/* 11 */
,
BlockEnum
.
Start
/* 1 */
,
BlockEnum
.
DirectAnswer
/* 2 */
,
BlockEnum
.
LLM
/* 3 */
,
BlockEnum
.
KnowledgeRetrieval
/* 4
*/
,
BlockEnum
.
IfElse
/* 6 */
,
BlockEnum
.
Code
/* 7 */
,
BlockEnum
.
TemplateTransform
/* 8 */
,
BlockEnum
.
HttpRequest
/* 9 */
,
BlockEnum
.
End
/* 12 */
,
].
map
((
item
,
i
)
=>
({
...
...
@@ -13,6 +14,7 @@ const nodes = [
type
:
'custom'
,
position
:
{
x
:
330
,
y
:
30
+
i
*
300
},
data
:
{
type
:
item
,
name
:
item
},
selected
:
i
===
0
,
// for test: always select the first node
}))
const
initialNodes
=
nodes
...
...
web/app/components/workflow/nodes/question-classifier/components/class-list.tsx
0 → 100644
View file @
4837ae49
'use client'
import
type
{
FC
}
from
'react'
import
React
,
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
TextEditor
from
'../../_base/components/editor/text-editor'
import
AddButton
from
'../../_base/components/add-button'
import
type
{
Topic
}
from
'@/app/components/workflow/nodes/question-classifier/types'
type
Props
=
{
list
:
Topic
[]
onChange
:
(
list
:
Topic
[])
=>
void
}
const
ClassList
:
FC
<
Props
>
=
({
list
,
onChange
,
})
=>
{
const
handleTopicChange
=
useCallback
((
index
:
number
)
=>
{
return
(
value
:
string
)
=>
{
const
newList
=
produce
(
list
,
(
draft
)
=>
{
draft
[
index
].
topic
=
value
})
onChange
(
newList
)
}
},
[
list
,
onChange
])
const
handleAddTopic
=
useCallback
(()
=>
{
const
newList
=
produce
(
list
,
(
draft
)
=>
{
draft
.
push
({
id
:
''
,
name
:
'topic aaa'
,
topic
:
'aaa'
})
})
onChange
(
newList
)
},
[
list
,
onChange
])
// Todo Remove; edit topic name
return
(
<
div
className=
'space-y-2'
>
{
list
.
map
((
item
,
index
)
=>
{
return
(
<
TextEditor
title=
{
<
div
>
{
/* can edit */
}
<
div
>
{
item
.
name
}
</
div
>
</
div
>
}
key=
{
index
}
value=
{
item
.
topic
}
onChange=
{
handleTopicChange
(
index
)
}
/>
)
})
}
<
AddButton
onClick=
{
handleAddTopic
}
text=
'Add Class'
/>
</
div
>
)
}
export
default
React
.
memo
(
ClassList
)
web/app/components/workflow/nodes/question-classifier/panel.tsx
View file @
4837ae49
import
type
{
FC
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
VarReferencePicker
from
'../_base/components/variable/var-reference-picker'
import
useConfig
from
'./use-config'
import
{
mockData
}
from
'./mock'
import
ClassList
from
'./components/class-list'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
import
ModelParameterModal
from
'@/app/components/header/account-setting/model-provider-page/model-parameter-modal'
const
i18nPrefix
=
'workflow.nodes.
llm
'
const
i18nPrefix
=
'workflow.nodes.
questionClassifiers
'
const
Panel
:
FC
=
()
=>
{
const
{
t
}
=
useTranslation
()
//
const readOnly = false
const
readOnly
=
false
const
{
inputs
,
handleModelChanged
,
handleCompletionParamsChange
,
handleQueryVarChange
,
handleTopicsChange
,
}
=
useConfig
(
mockData
)
const
model
=
inputs
.
model
return
(
<
div
className=
'mt-2 px-4 space-y-4'
>
<
Field
title=
{
t
(
`${i18nPrefix}.inputVars`
)
}
>
<
VarReferencePicker
readonly=
{
readOnly
}
isShowNodeName
value=
{
inputs
.
query_variable_selector
}
onChange=
{
handleQueryVarChange
}
/>
</
Field
>
<
Field
title=
{
t
(
`${i18nPrefix}.model`
)
}
>
...
...
@@ -37,6 +50,18 @@ const Panel: FC = () => {
debugWithMultipleModel=
{
false
}
/>
</
Field
>
<
Field
title=
{
t
(
`${i18nPrefix}.class`
)
}
>
<
ClassList
list=
{
inputs
.
topics
}
onChange=
{
handleTopicsChange
}
/>
</
Field
>
<
Field
title=
{
t
(
`${i18nPrefix}.advancedSetting`
)
}
>
advancedSetting
</
Field
>
</
div
>
)
}
...
...
web/app/components/workflow/nodes/question-classifier/types.ts
View file @
4837ae49
import
type
{
CommonNodeType
,
Memory
,
ModelConfig
,
ValueSelector
}
from
'@/app/components/workflow/types'
type
Topic
=
{
export
type
Topic
=
{
id
:
string
name
:
string
topic
:
string
...
...
web/app/components/workflow/nodes/question-classifier/use-config.ts
View file @
4837ae49
import
{
useCallback
,
useState
}
from
'react'
import
produce
from
'immer'
import
type
{
ValueSelector
}
from
'../../types'
import
type
{
QuestionClassifierNodeType
}
from
'./types'
const
useConfig
=
(
initInputs
:
QuestionClassifierNodeType
)
=>
{
...
...
@@ -22,10 +23,26 @@ const useConfig = (initInputs: QuestionClassifierNodeType) => {
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
const
handleQueryVarChange
=
useCallback
((
newVar
:
ValueSelector
)
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
)
=>
{
draft
.
query_variable_selector
=
newVar
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
const
handleTopicsChange
=
useCallback
((
newTopics
:
any
)
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
)
=>
{
draft
.
topics
=
newTopics
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
return
{
inputs
,
handleModelChanged
,
handleCompletionParamsChange
,
handleQueryVarChange
,
handleTopicsChange
,
}
}
...
...
web/i18n/en-US/workflow.ts
View file @
4837ae49
...
...
@@ -125,6 +125,12 @@ const translation = {
toAuthorize
:
'To authorize'
,
inputVars
:
'Input Variables'
,
},
questionClassifiers
:
{
model
:
'model'
,
inputVars
:
'Input Variables'
,
class
:
'Class'
,
advancedSetting
:
'Advanced Setting'
,
},
},
}
...
...
web/i18n/zh-Hans/workflow.ts
View file @
4837ae49
...
...
@@ -124,6 +124,12 @@ const translation = {
toAuthorize
:
'授权'
,
inputVars
:
'输入变量'
,
},
questionClassifiers
:
{
model
:
'模型'
,
inputVars
:
'输入变量'
,
class
:
'类别'
,
advancedSetting
:
'高级设置'
,
},
},
}
...
...
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