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
7a07d8c2
Commit
7a07d8c2
authored
Mar 08, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: tool params
parent
17a67e79
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
9 deletions
+84
-9
Form.tsx
.../account-setting/model-provider-page/model-modal/Form.tsx
+14
-8
panel.tsx
web/app/components/workflow/nodes/tool/panel.tsx
+23
-1
use-config.ts
web/app/components/workflow/nodes/tool/use-config.ts
+47
-0
No files found.
web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx
View file @
7a07d8c2
...
...
@@ -19,6 +19,9 @@ import Tooltip from '@/app/components/base/tooltip-plus'
import
{
HelpCircle
}
from
'@/app/components/base/icons/src/vender/line/general'
import
Radio
from
'@/app/components/base/radio'
type
FormProps
=
{
className
?:
string
itemClassName
?:
string
fieldLabelClassName
?:
string
value
:
FormValue
onChange
:
(
val
:
FormValue
)
=>
void
formSchemas
:
CredentialFormSchema
[]
...
...
@@ -33,6 +36,9 @@ type FormProps = {
}
const
Form
:
FC
<
FormProps
>
=
({
className
,
itemClassName
,
fieldLabelClassName
,
value
,
onChange
,
formSchemas
,
...
...
@@ -89,8 +95,8 @@ const Form: FC<FormProps> = ({
const
disabed
=
readonly
||
(
isEditMode
&&
(
variable
===
'__model_type'
||
variable
===
'__model_name'
))
return
(
<
div
key=
{
variable
}
className=
'py-3'
>
<
div
className=
'py-2 text-sm text-gray-900'
>
<
div
key=
{
variable
}
className=
{
cn
(
itemClassName
,
'py-3'
)
}
>
<
div
className=
{
cn
(
fieldLabelClassName
,
'py-2 text-sm text-gray-900'
)
}
>
{
label
[
language
]
||
label
.
en_US
}
{
required
&&
(
...
...
@@ -130,8 +136,8 @@ const Form: FC<FormProps> = ({
const
disabed
=
isEditMode
&&
(
variable
===
'__model_type'
||
variable
===
'__model_name'
)
return
(
<
div
key=
{
variable
}
className=
'py-3'
>
<
div
className=
'py-2 text-sm text-gray-900'
>
<
div
key=
{
variable
}
className=
{
cn
(
itemClassName
,
'py-3'
)
}
>
<
div
className=
{
cn
(
fieldLabelClassName
,
'py-2 text-sm text-gray-900'
)
}
>
{
label
[
language
]
||
label
.
en_US
}
{
required
&&
(
...
...
@@ -186,8 +192,8 @@ const Form: FC<FormProps> = ({
return
null
return
(
<
div
key=
{
variable
}
className=
'py-3'
>
<
div
className=
'py-2 text-sm text-gray-900'
>
<
div
key=
{
variable
}
className=
{
cn
(
itemClassName
,
'py-3'
)
}
>
<
div
className=
{
cn
(
fieldLabelClassName
,
'py-2 text-sm text-gray-900'
)
}
>
{
label
[
language
]
||
label
.
en_US
}
{
...
...
@@ -227,7 +233,7 @@ const Form: FC<FormProps> = ({
return
null
return
(
<
div
key=
{
variable
}
className=
'py-3'
>
<
div
key=
{
variable
}
className=
{
cn
(
itemClassName
,
'py-3'
)
}
>
<
div
className=
'flex items-center justify-between py-2 text-sm text-gray-900'
>
<
div
className=
'flex items-center space-x-2'
>
<
span
>
{
label
[
language
]
||
label
.
en_US
}
</
span
>
...
...
@@ -249,7 +255,7 @@ const Form: FC<FormProps> = ({
}
return
(
<
div
>
<
div
className=
{
className
}
>
{
formSchemas
.
map
(
formSchema
=>
renderField
(
formSchema
))
}
...
...
web/app/components/workflow/nodes/tool/panel.tsx
View file @
7a07d8c2
...
...
@@ -3,9 +3,11 @@ import React from 'react'
import
{
useTranslation
}
from
'react-i18next'
import
Split
from
'../_base/components/split'
import
type
{
ToolNodeType
}
from
'./types'
import
useConfig
from
'./use-config'
import
Button
from
'@/app/components/base/button'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
import
type
{
NodePanelProps
}
from
'@/app/components/workflow/types'
import
Form
from
'@/app/components/header/account-setting/model-provider-page/model-modal/Form'
const
i18nPrefix
=
'workflow.nodes.tool'
...
...
@@ -16,6 +18,13 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
const
{
t
}
=
useTranslation
()
const
readOnly
=
false
const
{
inputs
,
toolSettingSchema
,
toolSettingValue
,
setToolSettingValue
,
}
=
useConfig
(
id
,
data
)
return
(
<
div
className=
'mt-2'
>
{
!
readOnly
&&
(
...
...
@@ -37,8 +46,21 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
>
inputVars
</
Field
>
<
Split
/>
<
Form
className=
'space-y-4'
itemClassName=
'!py-0'
fieldLabelClassName=
'!text-[13px] !font-semibold !text-gray-700 uppercase'
value=
{
toolSettingValue
}
onChange=
{
setToolSettingValue
}
formSchemas=
{
toolSettingSchema
as
any
}
isEditMode=
{
false
}
showOnVariableMap=
{
{}
}
validating=
{
false
}
inputClassName=
'!bg-gray-50'
readonly=
{
readOnly
}
/>
</
div
>
<
Split
/>
</
div
>
)
}
...
...
web/app/components/workflow/nodes/tool/use-config.ts
0 → 100644
View file @
7a07d8c2
import
{
useCallback
,
useEffect
,
useState
}
from
'react'
import
type
{
ToolNodeType
}
from
'./types'
import
useNodeCrud
from
'@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import
{
fetchBuiltInToolList
,
fetchCustomToolList
}
from
'@/service/tools'
import
type
{
Tool
}
from
'@/app/components/tools/types'
import
{
addDefaultValue
,
toolParametersToFormSchemas
}
from
'@/app/components/tools/utils/to-form-schema'
import
{
CollectionType
}
from
'@/app/components/tools/types'
const
useConfig
=
(
id
:
string
,
payload
:
ToolNodeType
)
=>
{
const
{
inputs
,
setInputs
}
=
useNodeCrud
<
ToolNodeType
>
(
id
,
payload
)
const
{
provider_id
,
provider_type
,
tool_name
,
tool_parameters
}
=
inputs
const
isBuiltIn
=
provider_type
===
CollectionType
.
builtIn
const
[
currTool
,
setCurrTool
]
=
useState
<
Tool
|
null
>
(
null
)
const
formSchemas
=
currTool
?
toolParametersToFormSchemas
(
currTool
.
parameters
)
:
[]
// use setting
const
toolSettingSchema
=
formSchemas
.
filter
((
item
:
any
)
=>
item
.
form
!==
'llm'
)
const
toolSettingValue
=
(()
=>
{
return
addDefaultValue
(
tool_parameters
,
toolSettingSchema
)
})()
const
setToolSettingValue
=
useCallback
((
value
:
Record
<
string
,
any
>
)
=>
{
setInputs
({
...
inputs
,
tool_parameters
:
value
,
})
},
[
inputs
,
setInputs
])
// setting when call
const
toolInputSchema
=
formSchemas
.
filter
((
item
:
any
)
=>
item
.
form
===
'llm'
)
useEffect
(()
=>
{
(
async
()
=>
{
const
list
=
isBuiltIn
?
await
fetchBuiltInToolList
(
provider_id
)
:
await
fetchCustomToolList
(
provider_id
)
const
currTool
=
list
.
find
(
tool
=>
tool
.
name
===
tool_name
)
if
(
currTool
)
setCurrTool
(
currTool
)
})()
},
[
provider_id
])
return
{
inputs
,
currTool
,
toolSettingSchema
,
toolSettingValue
,
setToolSettingValue
,
}
}
export
default
useConfig
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