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
25a11c5b
Commit
25a11c5b
authored
Mar 13, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: question classify output
parent
1f41521c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
64 deletions
+115
-64
constants.ts
web/app/components/workflow/constants.ts
+92
-58
utils.ts
...ponents/workflow/nodes/_base/components/variable/utils.ts
+16
-4
var-reference-picker.tsx
.../nodes/_base/components/variable/var-reference-picker.tsx
+7
-2
No files found.
web/app/components/workflow/constants.ts
View file @
25a11c5b
...
...
@@ -185,12 +185,7 @@ export const SUPPORT_OUTPUT_VARS_NODE = [
BlockEnum
.
QuestionClassifier
,
BlockEnum
.
HttpRequest
,
BlockEnum
.
Tool
,
BlockEnum
.
VariableAssigner
,
]
export
const
LLM_OUTPUT_STRUCT
:
Var
[]
=
[
{
variable
:
'text'
,
type
:
VarType
.
string
,
},
{
const
USAGE
=
{
variable
:
'usage'
,
type
:
VarType
.
object
,
children
:
[
...
...
@@ -247,7 +242,13 @@ export const LLM_OUTPUT_STRUCT: Var[] = [
type
:
VarType
.
number
,
},
],
}
export
const
LLM_OUTPUT_STRUCT
:
Var
[]
=
[
{
variable
:
'text'
,
type
:
VarType
.
string
,
},
]
export
const
KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT
:
Var
[]
=
[
...
...
@@ -255,6 +256,7 @@ export const KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT: Var[] = [
variable
:
'result'
,
type
:
VarType
.
arrayObject
,
},
USAGE
,
]
export
const
TEMPLATE_TRANSFORM_OUTPUT_STRUCT
:
Var
[]
=
[
...
...
@@ -263,3 +265,35 @@ export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [
type
:
VarType
.
string
,
},
]
const
QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON
:
Var
[]
=
[
USAGE
,
{
variable
:
'topic'
,
type
:
VarType
.
string
,
},
]
export
const
CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT
=
[
{
variable
:
'model_mode'
,
type
:
VarType
.
string
,
},
{
variable
:
'messages'
,
type
:
VarType
.
arrayObject
,
},
...
QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON
,
]
export
const
COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT
=
[
{
variable
:
'model_mode'
,
type
:
VarType
.
string
,
},
{
variable
:
'text'
,
type
:
VarType
.
string
,
},
...
QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON
,
]
web/app/components/workflow/nodes/_base/components/variable/utils.ts
View file @
25a11c5b
...
...
@@ -2,7 +2,14 @@ import type { CodeNodeType } from '../../../code/types'
import
{
BlockEnum
,
InputVarType
,
VarType
}
from
'@/app/components/workflow/types'
import
type
{
StartNodeType
}
from
'@/app/components/workflow/nodes/start/types'
import
type
{
NodeOutPutVar
}
from
'@/app/components/workflow/types'
import
{
KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT
,
LLM_OUTPUT_STRUCT
,
SUPPORT_OUTPUT_VARS_NODE
,
TEMPLATE_TRANSFORM_OUTPUT_STRUCT
}
from
'@/app/components/workflow/constants'
import
{
CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT
,
COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT
,
KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT
,
LLM_OUTPUT_STRUCT
,
SUPPORT_OUTPUT_VARS_NODE
,
TEMPLATE_TRANSFORM_OUTPUT_STRUCT
,
}
from
'@/app/components/workflow/constants'
const
inputVarTypeToVarType
=
(
type
:
InputVarType
):
VarType
=>
{
if
(
type
===
InputVarType
.
number
)
...
...
@@ -11,7 +18,7 @@ const inputVarTypeToVarType = (type: InputVarType): VarType => {
return
VarType
.
string
}
const
formatItem
=
(
item
:
any
):
NodeOutPutVar
=>
{
const
formatItem
=
(
item
:
any
,
isChatMode
:
boolean
):
NodeOutPutVar
=>
{
const
{
id
,
data
}
=
item
const
res
:
NodeOutPutVar
=
{
nodeId
:
id
,
...
...
@@ -59,10 +66,15 @@ const formatItem = (item: any): NodeOutPutVar => {
res
.
vars
=
TEMPLATE_TRANSFORM_OUTPUT_STRUCT
break
}
case
BlockEnum
.
QuestionClassifier
:
{
res
.
vars
=
isChatMode
?
CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT
:
COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT
break
}
}
return
res
}
export
const
toNodeOutputVars
=
(
nodes
:
any
[]):
NodeOutPutVar
[]
=>
{
return
nodes
.
filter
(
node
=>
SUPPORT_OUTPUT_VARS_NODE
.
includes
(
node
.
data
.
type
)).
map
(
formatItem
)
export
const
toNodeOutputVars
=
(
nodes
:
any
[]
,
isChatMode
:
boolean
):
NodeOutPutVar
[]
=>
{
return
nodes
.
filter
(
node
=>
SUPPORT_OUTPUT_VARS_NODE
.
includes
(
node
.
data
.
type
)).
map
(
node
=>
formatItem
(
node
,
isChatMode
)
)
}
web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx
View file @
25a11c5b
...
...
@@ -14,7 +14,10 @@ import {
PortalToFollowElemContent
,
PortalToFollowElemTrigger
,
}
from
'@/app/components/base/portal-to-follow-elem'
import
{
useWorkflow
}
from
'@/app/components/workflow/hooks'
import
{
useIsChatMode
,
useWorkflow
,
}
from
'@/app/components/workflow/hooks'
type
Props
=
{
className
?:
string
...
...
@@ -37,9 +40,11 @@ const VarReferencePicker: FC<Props> = ({
value
,
onChange
,
})
=>
{
const
isChatMode
=
useIsChatMode
()
const
{
getTreeLeafNodes
,
getBeforeNodesInSameBranch
}
=
useWorkflow
()
const
availableNodes
=
getBeforeNodesInSameBranch
(
nodeId
)
const
outputVars
=
toNodeOutputVars
(
availableNodes
)
const
outputVars
=
toNodeOutputVars
(
availableNodes
,
isChatMode
)
const
[
open
,
setOpen
]
=
useState
(
false
)
const
hasValue
=
value
.
length
>
0
const
outputVarNodeId
=
hasValue
?
value
[
0
]
:
''
...
...
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