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
d58a1b13
Commit
d58a1b13
authored
Feb 20, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: code support vars
parent
bb87a350
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
149 additions
and
20 deletions
+149
-20
page.tsx
web/app/(commonLayout)/workflow/nodes/page.tsx
+2
-1
use-var-list.ts
...app/components/workflow/nodes/_base/hooks/use-var-list.ts
+37
-0
mock.ts
web/app/components/workflow/nodes/code/mock.ts
+26
-0
node.tsx
web/app/components/workflow/nodes/code/node.tsx
+2
-1
panel.tsx
web/app/components/workflow/nodes/code/panel.tsx
+30
-1
types.ts
web/app/components/workflow/nodes/code/types.ts
+16
-0
use-config.ts
web/app/components/workflow/nodes/code/use-config.ts
+19
-0
use-config.ts
web/app/components/workflow/nodes/llm/use-config.ts
+5
-17
types.ts
...app/components/workflow/nodes/template-transform/types.ts
+6
-0
workflow.en.ts
web/i18n/lang/workflow.en.ts
+3
-0
workflow.zh.ts
web/i18n/lang/workflow.zh.ts
+3
-0
No files found.
web/app/(commonLayout)/workflow/nodes/page.tsx
View file @
d58a1b13
...
...
@@ -46,8 +46,9 @@ const Page: FC = () => {
/*
* TODO: for debug.
* 2 directAnswer 3: llm 5: questionClassifier
* 7 Code
*/
selectedNodeId=
'
5
'
selectedNodeId=
'
7
'
/>
</
div
>
)
...
...
web/app/components/workflow/nodes/_base/hooks/use-var-list.ts
0 → 100644
View file @
d58a1b13
import
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
type
{
Variable
}
from
'@/app/components/workflow/types'
type
Params
<
T
>
=
{
inputs
:
T
setInputs
:
(
newInputs
:
T
)
=>
void
varKey
?:
string
}
function
useVarList
<
T
>
({
inputs
,
setInputs
,
varKey
=
'variables'
,
}:
Params
<
T
>
)
{
const
handleVarListChange
=
useCallback
((
newList
:
Variable
[])
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
:
any
)
=>
{
draft
[
varKey
]
=
newList
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
,
varKey
])
const
handleAddVariable
=
useCallback
(()
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
:
any
)
=>
{
draft
[
varKey
].
push
({
variable
:
''
,
value_selector
:
[],
})
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
,
varKey
])
return
{
handleVarListChange
,
handleAddVariable
,
}
}
export
default
useVarList
web/app/components/workflow/nodes/code/mock.ts
0 → 100644
View file @
d58a1b13
import
{
CodeLanguage
}
from
'./types'
import
type
{
CodeNodeType
}
from
'./types'
export
const
mockData
:
CodeNodeType
=
{
title
:
'Test'
,
desc
:
'Test'
,
type
:
'Test'
,
variables
:
[
{
variable
:
'name'
,
value_selector
:
[
'aaa'
,
'name'
],
},
{
variable
:
'age'
,
value_selector
:
[
'bbb'
,
'b'
,
'c'
],
},
],
code_language
:
CodeLanguage
.
python3
,
code
:
'print("hello world")'
,
outputs
:
[
{
variable
:
'output'
,
variable_type
:
'string'
,
},
],
}
web/app/components/workflow/nodes/code/node.tsx
View file @
d58a1b13
...
...
@@ -2,7 +2,8 @@ import type { FC } from 'react'
const
Node
:
FC
=
()
=>
{
return
(
<
div
>
code
</
div
>
// No summary content
<
div
></
div
>
)
}
...
...
web/app/components/workflow/nodes/code/panel.tsx
View file @
d58a1b13
import
type
{
FC
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
useConfig
from
'./use-config'
import
{
mockData
}
from
'./mock'
import
VarList
from
'@/app/components/workflow/nodes/_base/components/variable/var-list'
import
AddButton
from
'@/app/components/base/button/add-button'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
const
i18nPrefix
=
'workflow.nodes.code'
const
Panel
:
FC
=
()
=>
{
const
{
t
}
=
useTranslation
()
const
readOnly
=
false
const
{
inputs
,
handleVarListChange
,
handleAddVariable
,
}
=
useConfig
(
mockData
)
return
(
<
div
>
start panel inputs
</
div
>
<
div
className=
'mt-2 px-4 space-y-4'
>
<
Field
title=
{
t
(
`${i18nPrefix}.inputVars`
)
}
operations=
{
<
AddButton
onClick=
{
handleAddVariable
}
/>
}
>
<
VarList
readonly=
{
readOnly
}
list=
{
inputs
.
variables
}
onChange=
{
handleVarListChange
}
/>
</
Field
>
</
div
>
)
}
...
...
web/app/components/workflow/nodes/code/types.ts
0 → 100644
View file @
d58a1b13
import
type
{
CommonNodeType
,
Variable
}
from
'@/app/components/workflow/types'
export
enum
CodeLanguage
{
python3
=
'python3'
,
javascript
=
'javascript'
,
}
export
type
CodeNodeType
=
CommonNodeType
&
{
variables
:
Variable
[]
code_language
:
CodeLanguage
code
:
string
outputs
:
{
variable
:
string
variable_type
:
string
}[]
}
web/app/components/workflow/nodes/code/use-config.ts
0 → 100644
View file @
d58a1b13
import
{
useState
}
from
'react'
import
useVarList
from
'../_base/hooks/use-var-list'
import
type
{
CodeNodeType
}
from
'./types'
const
useConfig
=
(
initInputs
:
CodeNodeType
)
=>
{
const
[
inputs
,
setInputs
]
=
useState
<
CodeNodeType
>
(
initInputs
)
const
{
handleVarListChange
,
handleAddVariable
}
=
useVarList
<
CodeNodeType
>
({
inputs
,
setInputs
,
})
return
{
inputs
,
handleVarListChange
,
handleAddVariable
,
}
}
export
default
useConfig
web/app/components/workflow/nodes/llm/use-config.ts
View file @
d58a1b13
import
{
useCallback
,
useState
}
from
'react'
import
produce
from
'immer'
import
type
{
Variable
}
from
'../../types
'
import
useVarList
from
'../_base/hooks/use-var-list
'
import
type
{
LLMNodeType
}
from
'./types'
const
useConfig
=
(
initInputs
:
LLMNodeType
)
=>
{
...
...
@@ -24,22 +24,10 @@ const useConfig = (initInputs: LLMNodeType) => {
},
[
inputs
,
setInputs
])
// variables
const
handleVarListChange
=
useCallback
((
newList
:
Variable
[])
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
)
=>
{
draft
.
variables
=
newList
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
const
handleAddVariable
=
useCallback
(()
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
)
=>
{
draft
.
variables
.
push
({
variable
:
''
,
value_selector
:
[],
})
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
const
{
handleVarListChange
,
handleAddVariable
}
=
useVarList
<
LLMNodeType
>
({
inputs
,
setInputs
,
})
// context
const
toggleContextEnabled
=
useCallback
(()
=>
{
...
...
web/app/components/workflow/nodes/template-transform/types.ts
0 → 100644
View file @
d58a1b13
import
type
{
CommonNodeType
,
Variable
}
from
'@/app/components/workflow/types'
export
type
TemplateTransformNodeType
=
CommonNodeType
&
{
variables
:
Variable
[]
template
:
string
}
web/i18n/lang/workflow.en.ts
View file @
d58a1b13
...
...
@@ -19,6 +19,9 @@ const translation = {
usage
:
'Model Usage Information'
,
},
},
code
:
{
inputVars
:
'Input Variables'
,
},
},
}
...
...
web/i18n/lang/workflow.zh.ts
View file @
d58a1b13
...
...
@@ -18,6 +18,9 @@ const translation = {
output
:
'生成内容'
,
usage
:
'模型用量信息'
,
},
code
:
{
inputVars
:
'输入变量'
,
},
},
},
}
...
...
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