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
f15dce9e
Commit
f15dce9e
authored
Mar 13, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: llm output and var type
parent
b718e66b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
12 deletions
+120
-12
constants.ts
web/app/components/workflow/constants.ts
+72
-1
utils.ts
...ponents/workflow/nodes/_base/components/variable/utils.ts
+15
-6
var-reference-picker.tsx
.../nodes/_base/components/variable/var-reference-picker.tsx
+20
-2
var-reference-popup.tsx
...w/nodes/_base/components/variable/var-reference-popup.tsx
+2
-2
types.ts
web/app/components/workflow/types.ts
+11
-1
No files found.
web/app/components/workflow/constants.ts
View file @
f15dce9e
import
{
BlockEnum
}
from
'./types'
import
type
{
Var
}
from
'./types'
import
{
BlockEnum
,
VarType
}
from
'./types'
import
StartNodeDefault
from
'./nodes/start/default'
import
DirectAnswerDefault
from
'./nodes/direct-answer/default'
import
LLMDefault
from
'./nodes/llm/default'
...
...
@@ -178,3 +179,73 @@ export const RETRIEVAL_OUTPUT_STRUCT = `{
"score": ""
}
}`
export
const
SUPPORT_OUTPUT_VARS_NODE
=
[
BlockEnum
.
Start
,
BlockEnum
.
LLM
,
BlockEnum
.
KnowledgeRetrieval
,
BlockEnum
.
Code
,
BlockEnum
.
TemplateTransform
,
BlockEnum
.
QuestionClassifier
,
BlockEnum
.
HttpRequest
,
BlockEnum
.
Tool
,
BlockEnum
.
VariableAssigner
,
]
export
const
LLM_OUTPUT_STRUCT
:
Var
[]
=
[
{
variable
:
'text'
,
type
:
VarType
.
string
,
},
{
variable
:
'usage'
,
type
:
VarType
.
object
,
children
:
[
{
variable
:
'prompt_tokens'
,
type
:
VarType
.
number
,
},
{
variable
:
'prompt_unit_price'
,
type
:
VarType
.
number
,
},
{
variable
:
'prompt_price_unit'
,
type
:
VarType
.
number
,
},
{
variable
:
'prompt_price'
,
type
:
VarType
.
number
,
},
{
variable
:
'completion_tokens'
,
type
:
VarType
.
number
,
},
{
variable
:
'completion_unit_price'
,
type
:
VarType
.
number
,
},
{
variable
:
'completion_price_unit'
,
type
:
VarType
.
number
,
},
{
variable
:
'completion_unit_price'
,
type
:
VarType
.
number
,
},
{
variable
:
'completion_price'
,
type
:
VarType
.
number
,
},
{
variable
:
'total_tokens'
,
type
:
VarType
.
number
,
},
{
variable
:
'total_price'
,
type
:
VarType
.
number
,
},
{
variable
:
'currency'
,
type
:
VarType
.
string
,
},
{
variable
:
'latency'
,
type
:
VarType
.
number
,
},
],
},
]
web/app/components/workflow/nodes/_base/components/variable/utils.ts
View file @
f15dce9e
import
{
BlockEnum
}
from
'@/app/components/workflow/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
{
LLM_OUTPUT_STRUCT
,
SUPPORT_OUTPUT_VARS_NODE
}
from
'@/app/components/workflow/constants'
const
inputVarTypeToVarType
=
(
type
:
InputVarType
):
VarType
=>
{
if
(
type
===
InputVarType
.
number
)
return
VarType
.
number
return
VarType
.
string
}
const
formatItem
=
(
item
:
any
):
NodeOutPutVar
=>
{
const
{
id
,
data
}
=
item
...
...
@@ -17,19 +25,20 @@ const formatItem = (item: any): NodeOutPutVar => {
res
.
vars
=
variables
.
map
((
v
)
=>
{
return
{
variable
:
v
.
variable
,
type
:
v
.
type
,
type
:
inputVarTypeToVarType
(
v
.
type
)
,
}
})
break
}
// default:
// // throw new Error('unknown type')
// break
case
BlockEnum
.
LLM
:
{
res
.
vars
=
LLM_OUTPUT_STRUCT
break
}
}
return
res
}
export
const
toNodeOutputVars
=
(
nodes
:
any
[]):
NodeOutPutVar
[]
=>
{
return
nodes
.
map
(
formatItem
)
return
nodes
.
filter
(
node
=>
SUPPORT_OUTPUT_VARS_NODE
.
includes
(
node
.
data
.
type
)).
map
(
formatItem
)
}
web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx
View file @
f15dce9e
...
...
@@ -5,6 +5,7 @@ import cn from 'classnames'
import
VarReferencePopup
from
'./var-reference-popup'
import
{
toNodeOutputVars
}
from
'./utils'
import
type
{
ValueSelector
}
from
'@/app/components/workflow/types'
import
{
VarType
}
from
'@/app/components/workflow/types'
import
{
VarBlockIcon
}
from
'@/app/components/workflow/block-icon'
import
{
Line3
}
from
'@/app/components/base/icons/src/public/common'
import
{
Variable02
}
from
'@/app/components/base/icons/src/vender/solid/development'
...
...
@@ -54,9 +55,26 @@ const VarReferencePicker: FC<Props> = ({
const
outputVarNode
=
hasValue
?
getNodeInfoById
(
availableNodes
,
outputVarNodeId
)?.
data
:
null
// console.log(hasValue, value, outputVarNode)
const
varName
=
hasValue
?
value
[
value
.
length
-
1
]
:
''
// TODO: get var type through node and value
const
getVarType
=
()
=>
{
return
'string'
const
targetVar
=
outputVars
.
find
(
v
=>
v
.
nodeId
===
outputVarNodeId
)
if
(
!
targetVar
)
return
'undefined'
let
type
:
VarType
=
VarType
.
string
let
curr
:
any
=
targetVar
.
vars
value
.
slice
(
1
).
forEach
((
key
,
i
)
=>
{
const
isLast
=
i
===
value
.
length
-
2
curr
=
curr
.
find
((
v
:
any
)
=>
v
.
variable
===
key
)
if
(
isLast
)
{
type
=
curr
.
type
}
else
{
if
(
curr
.
type
===
VarType
.
object
)
curr
=
curr
.
children
}
})
return
type
}
return
(
...
...
web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx
View file @
f15dce9e
...
...
@@ -3,7 +3,7 @@ import type { FC } from 'react'
import
React
,
{
useRef
}
from
'react'
import
{
useHover
}
from
'ahooks'
import
cn
from
'classnames'
import
type
{
NodeOutPutVar
,
ValueSelector
,
Var
}
from
'@/app/components/workflow/types'
import
{
type
NodeOutPutVar
,
type
ValueSelector
,
type
Var
,
VarType
}
from
'@/app/components/workflow/types'
import
{
Variable02
}
from
'@/app/components/base/icons/src/vender/solid/development'
import
{
ChevronRight
}
from
'@/app/components/base/icons/src/vender/line/arrows'
...
...
@@ -30,7 +30,7 @@ const Item: FC<ItemProps> = ({
itemData
,
onChange
,
})
=>
{
const
isObj
=
itemData
.
type
===
'object'
const
isObj
=
itemData
.
type
===
VarType
.
object
const
itemRef
=
useRef
(
null
)
const
isItemHovering
=
useHover
(
itemRef
)
const
handleChosen
=
(
e
:
React
.
MouseEvent
)
=>
{
...
...
web/app/components/workflow/types.ts
View file @
f15dce9e
...
...
@@ -118,9 +118,19 @@ export type Memory = {
}
}
export
enum
VarType
{
string
=
'String'
,
number
=
'Number'
,
boolean
=
'Boolean'
,
object
=
'Object'
,
array
=
'Array'
,
arrayString
=
'Array[string]'
,
arrayNumber
=
'Array[number]'
,
}
export
type
Var
=
{
variable
:
string
type
:
string
type
:
VarType
children
?:
Var
[]
// if type is obj, has the children struct
}
...
...
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